KritikaVikas SharmaDr. Umesh DuttaVaishnavi
Published

4-Way Traffic Light System with Arduino

Revolutionize road safety with our Arduino 4-way traffic light system for smarter, more efficient traffic flow management.

BeginnerFull instructions provided1,716
4-Way Traffic Light System with Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
The main microcontroller board used to control the traffic light system. It processes the code and manages the input/output pins to control the LEDs.
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
The USB cable connects the Arduino to the computer, allowing code upload and providing power to the Arduino.
×1
Jumper wires (generic)
Jumper wires (generic)
Jumper wires are used to make connections between the Arduino, breadboard, and LEDs. They help transmit electrical signals from the Arduino to each component.
×1
LED Traffic Light Signal Module
Four sets of red, yellow, and green LEDs are used to represent traffic lights for four directions. Each color represents the traffic control signals: Red: Stop Yellow: Prepare to stop Green: Go
×1

Software apps and online services

Arduino IDE
Arduino IDE
The Arduino IDE is used to write, compile, and upload the code to the Arduino board. It provides an easy-to-use interface for writing the traffic light control code and testing the logic.
Tinkercad
Autodesk Tinkercad
Tinkercad is an online 3D design and electronics simulation platform. It can be used to virtually design and simulate the traffic light system before building it in real life. This allows for easy testing and debugging of the circuit and code without physical components.
Windows 10
Microsoft Windows 10
The project was developed using Windows 10, which is compatible with the Arduino IDE for uploading code to the Arduino board.

Hand tools and fabrication machines

Tape, Electrical
Tape, Electrical
For assembling and securing the cardboard enclosure or fixing components in place, ensuring everything stays stable during the project.
Tape Measure, Manual
Tape Measure, Manual
To measure and ensure the correct dimensions of the enclosure, so the Arduino and LEDs fit properly inside.
Scissor, Electrician
Scissor, Electrician
Used for cutting wires and cables as well as cardboard for the enclosure. The serrated edge provides a better grip and cuts through various materials efficiently.

Story

Read more

Custom parts and enclosures

Arduino Traffic Light Design

CARDBOARD ENCLOSURE
The traffic light system is housed in a cardboard enclosure to protect the Arduino and LEDs, keeping wiring organized and stable.

CUSTOM CUTOUTS
Openings for LEDs allow light to shine through clearly.
Optional ventilation cutouts can be added for airflow.

ASSEMBLY
Cardboard was cut to fit components and assembled using glue and tape for stability.

DESIGN CONSIDERATION
The lightweight cardboard design allows for easy modifications and is cost-effective for future projects.

Schematics

Arduino Traffic Light Circuit

SCHEMATIC OVERVIEW
The circuit connects four sets of LEDs (red, yellow, and green) to specific pins on the Arduino. Each LED corresponds to a traffic light direction and operates based on the programmed logic.

CONNECTIONS
LED Connections:
Red LEDs: Connected to pins 13, 10, 7, and 4
Yellow LEDs: Connected to pins 12, 9, 6, and 3
Green LEDs: Connected to pins 11, 8, 5, and 2

POWER SUPPLY
Powered directly from the Arduino, ensuring that the LEDs receive the necessary voltage to operate.

CIRCUIT LOGIC
The circuit operates by sequentially lighting up the green, yellow, and red LEDs in a specified order to simulate traffic lights for four directions. The logic is defined in the code, ensuring that traffic is controlled efficiently.

Code

Arduino Code for 4-Way Traffic Light Control

C/C++
Each function (case1 to case8) represents a different traffic light scenario, managing the LED states for each direction.
Delays between each case ensure proper timing, simulating real traffic light behavior.
// Define pin numbers for each traffic light color for all four directions
int red1 = 13;   // Red light for direction 1
int yellow1 = 12; // Yellow light for direction 1
int green1 = 11;  // Green light for direction 1
int red2 = 10;   // Red light for direction 2
int yellow2 = 9; // Yellow light for direction 2
int green2 = 8;  // Green light for direction 2
int red3 = 7;    // Red light for direction 3
int yellow3 = 6; // Yellow light for direction 3
int green3 = 5;  // Green light for direction 3
int red4 = 4;    // Red light for direction 4
int yellow4 = 3; // Yellow light for direction 4
int green4 = 2;  // Green light for direction 4

void setup() {
  // Set each pin as an OUTPUT
  pinMode(red1, OUTPUT);
  pinMode(yellow1, OUTPUT);
  pinMode(green1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(yellow2, OUTPUT);
  pinMode(green2, OUTPUT);
  pinMode(red3, OUTPUT);
  pinMode(yellow3, OUTPUT);
  pinMode(green3, OUTPUT);
  pinMode(red4, OUTPUT);
  pinMode(yellow4, OUTPUT);
  pinMode(green4, OUTPUT);
}

// Function to turn on green light for direction 1 and red for others
void case1() {
  digitalWrite(red1, LOW);
  digitalWrite(yellow1, LOW);
  digitalWrite(green1, HIGH);
  digitalWrite(red2, HIGH);
  digitalWrite(yellow2, LOW);
  digitalWrite(green2, LOW);
  digitalWrite(red3, HIGH);
  digitalWrite(yellow3, LOW);
  digitalWrite(green3, LOW);
  digitalWrite(red4, HIGH);
  digitalWrite(yellow4, LOW);
  digitalWrite(green4, LOW);
}

// Function for yellow light for direction 1
void case2() {
  digitalWrite(red1, LOW);
  digitalWrite(yellow1, HIGH);
  digitalWrite(green1, LOW);
  digitalWrite(red2, HIGH);
  digitalWrite(yellow2, LOW);
  digitalWrite(green2, LOW);
  digitalWrite(red3, HIGH);
  digitalWrite(yellow3, LOW);
  digitalWrite(green3, LOW);
  digitalWrite(red4, HIGH);
  digitalWrite(yellow4, LOW);
  digitalWrite(green4, LOW);
}

// Function to turn on green light for direction 2
void case3() {
  digitalWrite(red1, HIGH);
  digitalWrite(yellow1, LOW);
  digitalWrite(green1, LOW);
  digitalWrite(red2, LOW);
  digitalWrite(yellow2, LOW);
  digitalWrite(green2, HIGH);
  digitalWrite(red3, HIGH);
  digitalWrite(yellow3, LOW);
  digitalWrite(green3, LOW);
  digitalWrite(red4, HIGH);
  digitalWrite(yellow4, LOW);
  digitalWrite(green4, LOW);
}

// Function for yellow light for direction 2
void case4() {
  digitalWrite(red1, HIGH);
  digitalWrite(yellow1, LOW);
  digitalWrite(green1, LOW);
  digitalWrite(red2, LOW);
  digitalWrite(yellow2, HIGH);
  digitalWrite(green2, LOW);
  digitalWrite(red3, HIGH);
  digitalWrite(yellow3, LOW);
  digitalWrite(green3, LOW);
  digitalWrite(red4, HIGH);
  digitalWrite(yellow4, LOW);
  digitalWrite(green4, LOW);
}

// Function to turn on green light for direction 3
void case5() {
  digitalWrite(red1, HIGH);
  digitalWrite(yellow1, LOW);
  digitalWrite(green1, LOW);
  digitalWrite(red2, HIGH);
  digitalWrite(yellow2, LOW);
  digitalWrite(green2, LOW);
  digitalWrite(red3, LOW);
  digitalWrite(yellow3, LOW);
  digitalWrite(green3, HIGH);
  digitalWrite(red4, HIGH);
  digitalWrite(yellow4, LOW);
  digitalWrite(green4, LOW);
}

// Function for yellow light for direction 3
void case6() {
  digitalWrite(red1, HIGH);
  digitalWrite(yellow1, LOW);
  digitalWrite(green1, LOW);
  digitalWrite(red2, HIGH);
  digitalWrite(yellow2, LOW);
  digitalWrite(green2, LOW);
  digitalWrite(red3, LOW);
  digitalWrite(yellow3, HIGH);
  digitalWrite(green3, LOW);
  digitalWrite(red4, HIGH);
  digitalWrite(yellow4, LOW);
  digitalWrite(green4, LOW);
}

// Function to turn on green light for direction 4
void case7() {
  digitalWrite(red1, HIGH);
  digitalWrite(yellow1, LOW);
  digitalWrite(green1, LOW);
  digitalWrite(red2, HIGH);
  digitalWrite(yellow2, LOW);
  digitalWrite(green2, LOW);
  digitalWrite(red3, HIGH);
  digitalWrite(yellow3, LOW);
  digitalWrite(green3, LOW);
  digitalWrite(red4, LOW);
  digitalWrite(yellow4, LOW);
  digitalWrite(green4, HIGH);
}

// Function for yellow light for direction 4
void case8() {
  digitalWrite(red1, HIGH);
  digitalWrite(yellow1, LOW);
  digitalWrite(green1, LOW);
  digitalWrite(red2, HIGH);
  digitalWrite(yellow2, LOW);
  digitalWrite(green2, LOW);
  digitalWrite(red3, HIGH);
  digitalWrite(yellow3, LOW);
  digitalWrite(green3, LOW);
  digitalWrite(red4, LOW);
  digitalWrite(yellow4, HIGH);
  digitalWrite(green4, LOW);
}

void loop() {
  case1();  // Green light for direction 1
  delay(5000);  // Wait for 5 seconds
  
  case2();  // Yellow light for direction 1
  delay(2000);  // Wait for 2 seconds
  
  case3();  // Green light for direction 2
  delay(5000);  // Wait for 5 seconds
  
  case4();  // Yellow light for direction 2
  delay(2000);  // Wait for 2 seconds
  
  case5();  // Green light for direction 3
  delay(5000);  // Wait for 5 seconds
  
  case6();  // Yellow light for direction 3
  delay(2000);  // Wait for 2 seconds
  
  case7();  // Green light for direction 4
  delay(5000);  // Wait for 5 seconds
  
  case8();  // Yellow light for direction 4
  delay(2000);  // Wait for 2 seconds
}

Credits

Kritika
5 projects • 3 followers
Contact
Vikas Sharma
4 projects • 6 followers
Contact
Dr. Umesh Dutta
42 projects • 60 followers
Working as Director of Innovation Centre at Manav Rachna, India. I am into development for the last 12 years.
Contact
Vaishnavi
2 projects • 1 follower
Beginner
Contact

Comments

Please log in or sign up to comment.