Arduino Traffic Light Project
Arduino Traffic Light Project
Project
Share
Tweet
Share
Pin
If you are looking for something easy, simple and at the same time you want
to impress everyone with your Arduino then traffic light project is probably
the best choice especially when you are a beginner in the world of Arduino.
We shall first see how to make a simple traffic light mechanism then to make
it more interesting add the provision of pedestrian crossing as well. This
post will cover the items required, step by step procedure and final code that
needs to be uploaded on the Ardunio to make it all work.
So let’s start!
TABLE OF CONTENTS
Items required
How does the traffic light system works?
Steps to follow
Video
Arduino Code
Read our other interesting Electronic Engineering articles here
Items required
Arduino Uno
CHECK IT OUT
LEDs
CHECK IT OUT
CHECK IT OUT
Push Buttons
CHECK IT OUT
Connecting Wires
CHECK IT OUT
Steps to follow
First let’s make the circuit for normal traffic light system without the
pedestrian crossing feature. Make sure to follow the exact circuit diagram
since the program is designed accordingly.
Now that you got the first half in place, let’s add the pedestrian crossing
feature with little more addition to the existing circuit diagram.
Upload the Arduino code which is made for this project. You can find the
code at the bottom of the post.
Bingo! you are all set to test your traffic light system with pedestrian
crossing.
NOTE: If you want to run the project without the pedestrian feature then the
void loop() of the code needs to be changed with the following code :
void loop()
changeLights();
delay(15000);
Video
Here is a short video which can help you to get it right:
Arduino Code
int red = 10;
int yellow = 9;
int green = 8;
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(button, INPUT);
digitalWrite(green, HIGH);
void loop() {
if (digitalRead(button) == HIGH){
if (digitalRead(button) == HIGH) {
changeLights();
}
}
void changeLights(){
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
digitalWrite(yellow, HIGH);
delay(2000);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(3000);
int yellow = 9;
int green = 8;
int button = 12; // switch is on pin 12
void setup(){
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(button, INPUT);
digitalWrite(green, HIGH);
void loop() {
if (digitalRead(button) == HIGH){
if (digitalRead(button) == HIGH) {
changeLights();
void changeLights(){
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
digitalWrite(yellow, HIGH);
delay(2000);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(3000);