Arduino Traffic Light Project
Arduino Traffic Light Project
Traffic Light
Name ID
Yousef Mohamed 20212812
Karim Magdy 20210304
Maryam Ayman 20213997
Gehad Osama 20212176
Youssef Yasser 20213360
Mohammed Hazem 20213913
Arduino Traffic Light System with Pedestrian Crossing
1. Introduction
This project implements a traffic light system using an Arduino Uno. It includes two traffic
lights for cars and one pedestrian crossing light. The system operates under normal
conditions where cars move, and pedestrians wait until a button is pressed to request a
crossing.
2. Components Used
- 1 × Arduino Uno
- Jumper Wires
- 1 × Breadboard
3. Circuit Design
The circuit consists of:
- Two traffic light signals (TC1 & TC3) with Red, Yellow, and Green LEDs.
- A pedestrian light (TH2) with Red, Yellow, and Green LEDs.
- Two buttons:
- **Button 1 (Car Button)** controls traffic signals.
- **Button 2 (Pedestrian Button)** allows pedestrians to cross.
When Button 2 is pressed, the traffic lights transition safely, stopping vehicles and allowing
pedestrians to cross. Afterward, normal traffic resumes.
4. Code Implementation
The Arduino code controls the system based on button inputs and LED signals.
Code:
void setup() {
// Traffic Light 1 (TC1)
pinMode(8, OUTPUT); // Red LED TC1
pinMode(9, OUTPUT); // Yellow LED TC1
pinMode(10, OUTPUT); // Green LED TC1
// Traffic Light 2 (TC3)
pinMode(11, OUTPUT); // Red LED TC3
pinMode(12, OUTPUT); // Yellow LED TC3
pinMode(13, OUTPUT); // Green LED TC3
// Buttons
pinMode(4, INPUT_PULLUP); // Button 1 (Car Button)
pinMode(3, INPUT_PULLUP); // Button 2 (Pedestrian Button)
Serial.begin(9600);
void loop() {
int button1 = digitalRead(4); // Read Car Button
int button2 = digitalRead(3); // Read Pedestrian Button
Serial.print("Button 1: ");
Serial.print(button1);
Serial.print(" | Button 2: ");
Serial.println(button2);
void normalTraffic() {
// Cars move, Pedestrians stop
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH); // Green TC1
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH); // Green TC3
void changeTraffic() {
// Yellow transition for safety
digitalWrite(10, LOW);
digitalWrite(9, HIGH); // Yellow TC1
digitalWrite(13, LOW);
digitalWrite(12, HIGH); // Yellow TC3
digitalWrite(7, LOW);
digitalWrite(6, HIGH); // Yellow TH2
digitalWrite(12, LOW);
digitalWrite(11, HIGH); // Red TC3
digitalWrite(6, LOW);
digitalWrite(5, HIGH); // Green TH2 (Pedestrians walk)
5. Working Mechanism
- **Default State**: Cars move (green light), Pedestrians wait (red light).
- **Button Pressed**:
- The system transitions using yellow lights.
- Cars stop (red light), and pedestrians cross (green light).
- After the crossing duration, normal traffic resumes.
6. Conclusion
This project demonstrates a simple yet effective **smart traffic light system** using an
Arduino. It ensures safety for pedestrians while maintaining smooth traffic flow.