Arduino Based 3-Way Traffic Light Controller (2024)

  1. Home
  2. Microcontroller Based Projects
  3. Arduino Based 3-Way Traffic Light Controller

PublishedAugust 8, 2017 16

A Antony Jackson
Author

Arduino Based 3-Way Traffic Light Controller (1)

We all know about Arduino. It is one of the most popular open source micro controller board which is highly useful for doing DIY projects. This Arduino based 3-Way Traffic Light Controller is a simpleArduino DIY project which is useful to understand the working of traffic lights which we see around us. We have covered a more simpler version of traffic lights in this traffic light circuit. Here have demonstrated it for 3 sides or ways. Now let’s get into the project…

Components Required:

  1. 3*Red LED Lights
  2. 3*Green LED Lights
  3. 3*Yellow LED Lights
  4. 3*220ohm Resistors
  5. Breadboard
  6. Male To Male Connectors
  7. Arduino Uno With Ide Cable

Circuit Explanation:

The circuit Diagram for Arduino Traffic Light Controllerproject is given below:

It’s pretty simple and can be easily built on bread board as explained in below steps:

  1. Connect the LEDs in the order as Red, Green, and Yellow in the breadboard.
  2. Place the negative terminal of the LEDs in common and connect the 220ohm resistor in series.
  3. Connect the connector wires accordingly.
  4. Connect the other end of the wire to the Arduino Uno in the consecutive pins(2,3,4…10)
  5. Power up the breadboard using the Arduino 5v and GND pin.

Program and Working Explanation:

The code for this Arduino Traffic Light Controller Project is simple and can be easily understood. Here we have demonstrated Traffic lights for the 3 ways road and the code glows LED’s on all the three sides in a particular sequence, in which the actual Traffic Lights works. Like, at a time, there will be two Red signals on any of the two sides and one Green light on the remaining side. And yellow light will also glow, for 1 second each time, in between transition from Red to Green, means first red light glows for 5 second then yellow light glows for 1 second and then finally green light will be turned on.

In the program, first we have declared pins (2,3…10) as output in void setup() for 9 LEDs (three on each side i.e. forward, right and left side).

 void setup() { // configure the output pins pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(7,OUTPUT); pinMode(8,OUTPUT); pinMode(9,OUTPUT); pinMode(10,OUTPUT);}

Then in void loop() function we have written the code for traffic lights to be turned on and off in sequence as mentioned above.

void loop() { digitalWrite(2,1); //enables the 1st set of signals digitalWrite(7,1); digitalWrite(10,1); digitalWrite(4,0); digitalWrite(3,0); digitalWrite(6,0); digitalWrite(8,0); digitalWrite(9,0); digitalWrite(5,0); delay(5000); ..... .... ..... ....

This process is well demonstrated in the Video Below. First the upside/forward side is opened (green), while the other two sides (i.e. left side and right side) remains closed with Red signal, with a delay of 5 seconds. Then the yellow light gets turned on at the right side for 1sec followed by the Green light, leaving other two sides (i.e. upside and left side is red) closed with Red Light and 5seconds delay. Then yellow on the left side glows for 1sec followed by green one, leaving upside and right side Red with 5sec delay. This process is looped in void loop() function for continuous process. Here we can modify delays for which the Red, yellow and Green light remain on and off.

The complete Arduino code and Video for this Arduino Traffic Light Project is given below.

Code

void setup() {

// configure the output pins

pinMode(2,OUTPUT);

pinMode(3,OUTPUT);

pinMode(4,OUTPUT);

pinMode(5,OUTPUT);

pinMode(6,OUTPUT);

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

pinMode(9,OUTPUT);

pinMode(10,OUTPUT);

}

void loop()

{

digitalWrite(2,1); //enables the 1st set of signals

digitalWrite(7,1);

digitalWrite(10,1);

digitalWrite(4,0);

digitalWrite(3,0);

digitalWrite(6,0);

digitalWrite(8,0);

digitalWrite(9,0);

digitalWrite(5,0);

delay(5000);

digitalWrite(3,1); //enables the yellow lights

digitalWrite(6,1);

digitalWrite(2,0);

digitalWrite(7,0);

delay(1000);

digitalWrite(4,1); //enables the 2nd set of signals

digitalWrite(5,1);

digitalWrite(10,1);

digitalWrite(2,0);

digitalWrite(3,0);

digitalWrite(6,0);

digitalWrite(8,0);

digitalWrite(9,0);

digitalWrite(7,0);

delay(5000);

digitalWrite(9,1); //enables the yellow lights

digitalWrite(6,1);

digitalWrite(10,0);

digitalWrite(5,0);

digitalWrite(4,0);

delay(1000);

digitalWrite(8,1); //enables the 3rd set of signals

digitalWrite(4,1);

digitalWrite(7,1);

digitalWrite(2,0);

digitalWrite(3,0);

digitalWrite(5,0);

digitalWrite(6,0);

digitalWrite(9,0);

digitalWrite(10,0);

delay(5000);

digitalWrite(9,1); //enables the yellow lights

digitalWrite(3,1);

digitalWrite(7,0);

digitalWrite(8,0);

digitalWrite(4,0);

delay(1000);

}

Video

Tags

arduino uno

arduino

traffic light

LED

Have any question realated to this Article?

Ask Our Community Members

Forum

Comments

other microcontroller boards

I have an HCS12 microcontroller. Can I use my board to make this? How would I adjust the code or does it even need to be adjusted?

  • Log in or register to post comments

HCS12 is very different from

HCS12 is very different from Arduino the whole code has to be changed

  • Log in or register to post comments

i have nucleoF030R8 embedded

i have nucleoF030R8 embedded.can I apply this idea on it?

  • Log in or register to post comments

Sure you can

Sure you can

  • Log in or register to post comments

Interfacing of lcd with 3 way traffic light controller using ard

Hey can I interface lcd with traffic light controller using arduino(without using I2C lcd module) so that I can display the comments.Stop-when red leds are on,Go- when green leds are on,Ready-when orange leds are on(this things should be displayed simultaneously on the lcd).I tried this experiment but the pins are not enough to connect the lcd pins as 9 leds has occupied from 3 to 10 digital pins.If I connect the lcd pins to analog pins it's not working.
So my question is can I connect the lcd pins to to analog pins on the arduino board to display the comments as I mentioned above?
If it's not possible ,then how can I connect lcd pins to arduino?
Plz reply me a.s.a.p

  • Log in or register to post comments

Yes you can use the analog

Yes you can use the analog pins on arduino as digital pins and so you can also interface LCD with it

  • Log in or register to post comments

Arduino

Can we make the program quite short by using the Ports in program ?

  • Log in or register to post comments

pls can an Arduino Nano be

pls can an Arduino Nano be used for this circuit

  • Log in or register to post comments

Yes Arduino nano can be used

Yes Arduino nano can be used

  • Log in or register to post comments

reply

if pins are not enough to connect lcd pins try to connect shift register to extend pins instead of connecting digital pins on arduino to analog pins

  • Log in or register to post comments

hello can these codes be

hello can these codes be modified to work with a ultrasonic sensor so as to change the lights based on traffic density?

  • Log in or register to post comments

Yes it can be

Yes it can be

  • Log in or register to post comments

I just wanted to say a big

I just wanted to say a big thanks, I made a set of 2 traffic lights and the code would not work properly when I tried to change it to run 3 sets of traffic lights, I found and used your code and now all is well.

As for the idea of 1 or 0 it is quicker to type than HIGH or LOW

Also I found it easy to "tweak" your code for the UK Traffic light sequence. (We have Red, Red & and Amber, Green, Green, Amber, Red)

Thanks again, from Some Bloke in the UK

  • Log in or register to post comments

hello

hello

?What Arduino is in the video, and what Arduino i need for this project

  • Log in or register to post comments

What is the part number?

What is the part number?

  • Log in or register to post comments
  • Log in or register to post comments

Ask Our Community Members

Forum
';var elements = document.getElementsByClassName("field--name-body");insertAfter(large, elements);//elements.insertAdjacentHTML('afterend', large);//$('.field--name-body').append(large);​//$('.field--name-body').after(large);
Arduino Based 3-Way Traffic Light Controller (2024)

References

Top Articles
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 5581

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.