Traffic thumb

Arduino based Traffic Light Simulator

3D printed Arduino Traffic Lights

A little bit off topic for the 3D printer community , but then again maybe not , for those of you who design and create 3D models then this little blog will enable you to create Traffic lights simulator on a breadboard – insert some light emitting diodes , do some cabling and program the arduino.

arduino - traffic lightsElectronic-Components - traffic lights

If you are into modelling then you could design and print the traffic lights once you understand how it all goes together.

Traffic Light design and stl files


Print out all the pieces and super glue them together. Place a battery in the base with one wire going from ground and three wires going from power. Connect each of the three powers to a different color 10″ LED, and connect the ground to a snap. Solder a ground wire to each of the LEDs and connect each of these ground wires to a snap. Bring all the LEDs and wires through the traffic pole and then super glue each of the lights into one of the three holes in the head. Have all the snaps coming out the of hole in the back of the head so they can be connected together and the LEDs will light up.


Click here to download the .STL Traffic lights <–

Brief history of Traffic Lights

Traffic lights, also known as traffic signals, traffic lamps, traffic semaphore, signal lights, stop lights, and (in technical parlance)traffic control signals, are signalling devices positioned at road intersections, pedestrian crossings, and other locations to control conflicting flows of traffic.

The world’s first, manually operated gas-lit traffic signal was short lived. Installed in London in December 1868, it exploded less than a month later, injuring or killing its policeman operator. The first safe, automatic electric traffic lights were installed in the United States in the late 1890s.

Traffic lights alternate the right of way accorded to road users by displaying lights of a standard colour (red, yellow, and green) following a universal colour code. In the typical sequence of colour phases:

  • The green light allows traffic to proceed in the direction denoted, if it is safe to do so and there is room on the other side of the intersection.
  • The yellow (or amber) light warns that the signal is about to change to red. In a number of countries – among them the United Kingdom – a phase during which red and amber are displayed together indicates that the signal is about to change to green. Actions required by drivers on an amber light vary, with some jurisdictions requiring drivers to stop if it is safe to do so, and others allowing drivers to go through the intersection if safe to do so.
  • A flashing yellow indication is a warning signal. In the United Kingdom, a flashing amber light is used only at pelican crossings, in place of the combined red–amber signal, and indicates that drivers may pass if no pedestrians are on the crossing.
  • The red signal prohibits any traffic from proceeding.
  • A flashing red indication is treated as a stop sign.
  • In some countries traffic signals will go into a flashing mode if the controller detects a problem, such as a program that tries to display green lights to conflicting traffic. The signal may display flashing yellow to the main road and flashing red to the side road, or flashing red in all directions. Flashing operation can also be used during times of day when traffic is light, such as late at night.ProcessWhat I will be going through is the coding first using the arduino ide , followed by breadboarding the circuit ,followed by connecting the arduino and the breadboard together and running the compiled a parts list.Parts List1 x Arduino1 x Small breadboard7 x Jumper cables3 x Led’s in Red , Yellow , and Green3 x 220 ohm resistors1 x cable to connect your arduino to your computerAnd the arduino ide from www.arduino.ccThe Arduino

    I would guess that most of you use an arduino to control your 3D printer with a firmware sketch for Marlin or Repetier – There are others out there plus if you a programmer you could create your own.using C or C++ which the ide supports.

    The arduino ide automatically checks for programming errors , if you have a problem it will give a brief error message and which line is effected.

    Once you have a working program the sketch is compiled and uploaded to your arduino – overwriting whatever is on your arduino.

    Please note  – do not use the arduino that runs your printer because you cannot extract the contents .!!

    A little bit about the arduino – basically it has loads of pins available for use which basically can be used as inputs and outputs.

    As a default the arduino makes all pins “inputs” as a standard so when programming if you forget to state what you want the program will still compile but not work.

    The Program

    Create a new sketch and name it TrafficLightSimulator

    This is what the sketch looks like with no code.

    void setup() {
    // put your setup code here, to run once:


    void loop() {
    // put your main code here, to run repeatedly:


    You need to add all the variables next

    int red = 13; // pin being used for output to red led
    int amber = 12; // pin being used for output to amber led
    int green = 11; // pin being used for output to green led

    A quick note about pins – their state is either HIGH meaning a signal goes to them or LOW meaning no signal.

    Setup pins


    Loop that makes it all work with timings for the light changes , in the delay setting 1000 = one minute.


    The Full sketch

    int red = 13;
    int amber = 12;
    int green = 11;

    void setup() {
    // put your setup code here, to run once:
    }oid loop() {
    // put your main code here, to run repeatedly:


    void changeLights(){
    // green off, amber on for 3 seconds

    //turn off amber ,then turn red on for 5 seconds

    //red and amber on for 2 seconds (red is already on)

    //Turn off red and amber , then turn on green

    I have put in as many comments as to what is going on.

    So save the file and press the tick to verify all is well it will say DONE COMPILING and you will see in the terminal window.

    Sketch uses 1,204 bytes (3%) of program storage space. Maximum is 30,720 bytes.
    Global variables use 15 bytes (0%) of dynamic memory, leaving 2,033 bytes for local variables. Maximum is 2,048 bytes.

    Click upload and it gets sent to the arduino.

    Building the circuit

    If you are new to electronics just following the diagram below


    Download the files by clicking the picture below! 

  • downloadOnce my new video camera arrived I will update the post with a videoThanks for dropping by , If there is another arduino related project that you would like me to cover , let me know.   

Leave a Reply

One thought on “Arduino based Traffic Light Simulator”

buy cialis online

Discover more from 3D Printer Chat

Subscribe now to keep reading and get access to the full archive.

Continue Reading

%d bloggers like this: