FLASHING TRAFFIC LIGHT

Super easy Arduino project.  You end up with a flashing LED "traffic light," with just a bread board, Uno board, a few other bits and pieces and some easy code.

Supplies Needed:

A computer for coding
An Arduino Uno board (we are using an Elegoo clone)
USB cable (A to B)
A bread board
3 LEDs (1 red, 1 yellow and 1 green)
3 220 Ohm resistors
7 male to male wires

Blinking%252520Traffic%252520Light_bb_edited_edited_edited.jpg

Breadboard Circuit Diagram

The circuit to the left shows the wiring schematic for connecting the power to the LEDs on the breadboard.  To make things clear, we used colored wiring.  Let's follow the path of the circuit.

  • Power comes into the board from the USB connection to the computer.

  • Each LED gets power from its port.

  • Port 8/10/12 have wires from them to the bread board.

  • Along the same strip for each of those wires is a 220 Ohm resistor.  These should be labeled in your kit.  I put tape on mine indicating the resistance, as the lines are hard to see once removed from their packaging.

  • The first leg of the resistor must be placed in line with the wires from the board.

  • The second leg of the resistor is then placed perpendicular to this line.

  • Then the long leg (anode/+) of the LED goes into the board in line with this.

  • The short leg (cathode/-) is placed perpendicular to this.

  • And then in line with this leg a wire from each LED leg goes to the blue strip on the breadboard.

  • And lastly, one wire connects back to the board via the ground port (GND) from there.

And now we are ready for the code!  :)

PS.  You can make diagrams like this for yourself on www.fritzing.org

Moving to the Arduino IDE

You can either work in the Arduino Online IDE or use the downloaded environment.  This is the code.  You will then verify it and load it onto the board.

Screen Shot 2020-03-22 at 3.26.24 PM.png

Arduino Sketch Code

/* Make a blinking traffic light.

*/

void setup() {

//Set ports for each LED to output.  

pinMode(8, OUTPUT);

pinMode(10, OUTPUT);

pinMode(12, OUTPUT);


}


void loop() {


//Set port 8, red LED, to HIGH, meaning light on.

digitalWrite(8, HIGH);


//Keep red LED lit for 3 seconds.   delay(3000);


//Set port 10, yellow LED to HIGH, meaning light on.

digitalWrite(10, HIGH);


//Keep yellow LED lit for 2 second.  

delay(2000);


//Turn off 8, red LED and 10, yellow LED. Turn on 12, green LED.

digitalWrite(8, LOW);

digitalWrite(10, LOW);

digitalWrite(12, HIGH);

delay(3000);

digitalWrite(12, LOW);


//Turn 12, green LED, on and off 3 times.   delay(500);

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(500);

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(500);

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(500);


//Flash 10, yellow LED.

digitalWrite(10, HIGH);

delay(1000);

digitalWrite(10, LOW);


}

Share Your Results!

This sketch was very satisfying for me when I finished it.  It was basically my first real sketch, after looking online for some time to find something easy that used very few parts.  Please note that if you copy and paste the text it will add some punctuation from the website.  So, you will need to remove random periods that you might find that are added.  It is good practice to write the code out for yourself, anyway.  :)

I hope you enjoyed this exercise, and hope that you share and give back to your community.