Arduino Traffic Light LEDs Circuit

by GrayCode in Circuits > Arduino

206 Views, 0 Favorites, 0 Comments

Arduino Traffic Light LEDs Circuit

Diagram.png

Here we have an example of how using 3 different coloured LEDs and the delay function, we can mimic the operation of a traffic light system.

This project can be easily edited using more LEDs, different coloured LEDs and differentdelays to create more unique sequences. A more advanced project which we will post in the future will be motion sensor traffic lights.

View this project and more at my website Gray Code!

Supplies

  • 1x Breadboard
  • 1x Arduino Uno
  • 3x 330 Ohm Resistor
  • 3x LED (Green, Amber, Red)
  • 4x Jumper Wires
  • 1x USB-A Cable

Let's Construct the Circuit!

20200222_202854.jpg

How do I start?

The first thing to do is to take a look at our photos above to see how the circuit is constructed, and then have a go building it yourself! Hint: Use the circuit diagram when building it, it’s there for a reason.

The positive led of the Green LED is connected to Pin 13 via a current limiting resistor and the negative led of the Green LED is connected to the Ground Pin via a jumper wire. This is the same for the Amber and Red LEDs. You can see how they share the same ground connection, this is perfectly fine to do and is encouraged to reduce wiring. A quick summary of the circuit can be seen below:

Pin 11 > Resistor > Red LED > Ground Rail

Pin 11 > Resistor > Amber LED > Ground Rail

Pin 11 > Resistor > Green LED > Ground Rail

Ground Rail on Breadboard > Jumper Wire > Ground Pin

Now the Code:

20200222_202903.jpg

Let’s run through what the code is doing

We initialise the Pins that the LEDs are connected to. Eg. ‘int led1 = 13;’

Inside the Setup function we use the pinMode function to set our Pins to which the LEDs are connected to be Outputs. Then inside the main loop function we are using the digitalWrite function to write each LED either HIGH or LOW. Essentially turning them ON or OFF.

Also utilising the delay function to pause the program and keep the current state of the program/circuit static for a specific amount of time.

Check out the information given on Arduino documentation to learn more.

<div><div>// This simple program uses the void loop() to run a sequence of LEDs using delays and the HIGH/LOW variables</div></div><div><div>int led1 = 13;               // Red</div></div><div><div>int led2 = 12;               // Yellow</div></div><div><div>int led3 = 11;               // Green </div></div><div><div>void setup() {</div></div><div><div>  // Setting all LEDs as OUTPUTs</div></div><div><div>  pinMode(led1,OUTPUT);</div></div><div><div>  pinMode(led2,OUTPUT);</div></div><div><div>  pinMode(led3,OUTPUT);</div></div><div><div>  </div></div><div><div>}</div></div><div><div>void loop() {</div></div><div><div>  // Turning pins HIGH for a specified time and then LOW until the loop restarts</div></div><div><div>  digitalWrite(led1,HIGH);</div></div><div><div>  delay(3000);</div></div><div><div>  </div></div><div><div>  digitalWrite(led1,LOW);</div></div><div><div>  delay(1000);</div></div><div><div>  </div></div><div><div>  digitalWrite(led2,HIGH);</div></div><div><div>  delay(3000);</div></div><div><div>  digitalWrite(led2,LOW);</div></div><div><div>  delay(1000);</div></div><div><div>  </div></div><div><div>  digitalWrite(led3,HIGH);</div></div><div><div>  delay(3000);</div></div><div><div>  digitalWrite(led3,LOW);</div></div><div><div>  delay(1000);</div></div><div><div>  </div></div><div><div>}</div></div><div><div>/*</div></div><div><div>This code can be edited to include more LEDs running in different sequences. </div></div><div><div>This is a simple 'traffic light' sequence.</div></div><div><div>*/</div></div>

Upload the Code and Watch the Magic!

Upload the code from the Arduino IDE and enjoy your traffic light simulation!

Take some time and play around, add extra LEDs or change the timing and have fun!

View this project and more at my website Gray Code!