Traffic Lights With Working Pedestrian Button With a 7 Segment Timer and Buzzer
by Abdullah9099 in Circuits > Arduino
24 Views, 0 Favorites, 0 Comments
Traffic Lights With Working Pedestrian Button With a 7 Segment Timer and Buzzer

This project shows how to make a traffic light with a pedestrian crossing using Arduino. It includes lights for cars and pedestrians, a button for pedestrians to activate the crossing, a 7-segment display to count down crossing time, and a buzzer to give sound signals.
When the button is pressed, the pedestrian crossing starts. The car light turns red, and the pedestrian light turns green while the countdown runs. Once the countdown ends, the car light turns green again, and the pedestrian light turns red.
The buzzer makes the system more useful by providing sound signals for blind pedestrians, making it safer and more realistic for real life applacations.
Downloads
Supplies
- Arduino Uno
- Breadboard
- LEDs - Red, Yellow, Green (for vehicles) - Green, Red (for pedestrians)
- 7-Segment Display
- Push Button (for pedestrians to request crossing)
- Resistors (330 ohm for LEDs, 560 ohm for the 7-segment display)
- Piezo Buzzer (for pedestrian alerts)
- Jumper Wires
- External Power Supply (Battary)
Downloads

Here are some pictures to show how the wiring should look.
- Arduino Pins: Some analog pins like a0 - a5 are used to connect components like the 7-segment display to save space.
- LEDs: Each LED is connected to a resistor and a digital pin on the Arduino.
- Push Button: It’s wired with a pull-down resistor to detect when the button is pressed.
- 7-Segment Display: A common cathode/anode display is connected through resistors to protect it from too much current.
- Buzzer: Connected to a digital pin to provide sound signals.
Tips for you:
- Use color-coded jumper wires to keep the wiring neat and easy to follow.
- Always double-check your connections to avoid short circuits or mistakes with pin numbers.
Step 2: Wiring
This project uses 5 LEDs, a push button, a 7-segment display, and a buzzer. The code controls everything and includes these features:
Traffic Light Cycle: The car lights switch between green, yellow, and red.
Pedestrian Crossing: Pressing the button starts the pedestrian crossing.
7-Segment Display Countdown: Shows how much time is left for pedestrians to cross.
Buzzer Alerts: Makes a sound during the crossing to keep it safe.
How It Works:
- The traffic lights follow the usual cycle: green to yellow to red.
- When the pedestrian button is pressed, the car light turns red, and the pedestrian light turns green.
- The 7-segment display counts down (e.g., from 10 seconds).
- The buzzer makes a sound while pedestrians are crossing.
- After the countdown, everything resets to the starting state.

Put this code:
#include <Servo.h>
// Pin assignments
const byte PEDESTRIAN_GREEN = 2;
const byte PEDESTRIAN_RED = 3;
const byte BUTTON = 5;
const byte BELL = 6;
const byte TRAFFIC_GREEN = 8;
const byte TRAFFIC_YELLOW = 9;
const byte TRAFFIC_RED = 10;
const byte SERVO_PIN = 7;
// 7-segment pins (Common Cathode)
const byte SEG_A = A3;
const byte SEG_B = A4;
const byte SEG_C = A5;
const byte SEG_D = 4;
const byte SEG_E = 0;
const byte SEG_F = A0;
const byte SEG_G = A1;
Servo barrier;
long cycle = 10000;
long last_cycle = 0;
int debounce_delay = 800;
int pedestrian_req = 0;
void setup() {
pinMode(PEDESTRIAN_GREEN, OUTPUT);
digitalWrite(PEDESTRIAN_GREEN, LOW);
pinMode(PEDESTRIAN_RED, OUTPUT);
digitalWrite(PEDESTRIAN_RED, HIGH);
pinMode(TRAFFIC_GREEN, OUTPUT);
digitalWrite(TRAFFIC_GREEN, HIGH);
pinMode(TRAFFIC_YELLOW, OUTPUT);
digitalWrite(TRAFFIC_YELLOW, LOW);
pinMode(TRAFFIC_RED, OUTPUT);
digitalWrite(TRAFFIC_RED, LOW);
pinMode(BUTTON, INPUT);
barrier.attach(SERVO_PIN);
barrier.write(90); // Barrier up
pinMode(SEG_A, OUTPUT);
pinMode(SEG_B, OUTPUT);
pinMode(SEG_C, OUTPUT);
pinMode(SEG_D, OUTPUT);
pinMode(SEG_E, OUTPUT);
pinMode(SEG_F, OUTPUT);
pinMode(SEG_G, OUTPUT);
Serial.begin(9600);
}
void loop() {
long ms = millis();
byte request = digitalRead(BUTTON);
if (request == HIGH && (ms - pedestrian_req) > debounce_delay) {
systemReset(); // FULL RESET
}
if (last_cycle + cycle < ms) {
startPedestrianCycle();
last_cycle = millis();
}
}
void systemReset() {
asm volatile ("jmp 0"); // Hard reset (like pressing Arduino reset button)
}
void startPedestrianCycle() {
stopVehicles();
pedestriansCycle();
startVehicles();
last_cycle = millis();
}
void stopVehicles() {
delay(1000);
digitalWrite(TRAFFIC_GREEN, LOW);
digitalWrite(TRAFFIC_YELLOW, HIGH);
delay(1000);
digitalWrite(TRAFFIC_YELLOW, LOW);
digitalWrite(TRAFFIC_RED, HIGH);
barrier.write(0); // Lower barrier
delay(1500);
}
void startVehicles() {
digitalWrite(TRAFFIC_RED, LOW);
digitalWrite(TRAFFIC_YELLOW, LOW);
digitalWrite(TRAFFIC_GREEN, HIGH);
barrier.write(90); // Raise barrier
}
void pedestriansCycle() {
digitalWrite(PEDESTRIAN_RED, LOW);
digitalWrite(PEDESTRIAN_GREEN, HIGH);
// 10 BEEPS before countdown
for (int i = 0; i < 10; i++) {
tone(BELL, 1760, 200);
delay(400);
noTone(BELL);
delay(100);
}
// Countdown from 6 to 0
for (int i = 6; i >= 0; i--) {
Serial.print("Countdown: ");
Serial.println(i);
displayNumber(i);
tone(BELL, 1760, 500);
delay(1000);
noTone(BELL);
}
blinkLights(PEDESTRIAN_GREEN, 5, 400);
digitalWrite(PEDESTRIAN_GREEN, LOW);
digitalWrite(PEDESTRIAN_RED, HIGH);
delay(2000);
}
void blinkLights(byte light, byte times, int duration) {
for (byte i = 0; i < times; i++) {
digitalWrite(light, LOW);
tone(BELL, 1760, 500);
delay(duration);
digitalWrite(light, HIGH);
delay(duration);
noTone(BELL);
}
}
// Turn off all segments
void clearSegments() {
digitalWrite(SEG_A, LOW);
digitalWrite(SEG_B, LOW);
digitalWrite(SEG_C, LOW);
digitalWrite(SEG_D, LOW);
digitalWrite(SEG_E, LOW);
digitalWrite(SEG_F, LOW);
digitalWrite(SEG_G, LOW);
}
// Manual display function for each number
void displayNumber(int num) {
clearSegments(); // Reset all segments first
switch (num) {
case 6:
digitalWrite(SEG_A, HIGH);
digitalWrite(SEG_C, HIGH);
digitalWrite(SEG_D, HIGH);
digitalWrite(SEG_E, HIGH);
digitalWrite(SEG_F, HIGH);
digitalWrite(SEG_G, HIGH);
break;
case 5:
digitalWrite(SEG_A, HIGH);
digitalWrite(SEG_C, HIGH);
digitalWrite(SEG_D, HIGH);
digitalWrite(SEG_F, HIGH);
digitalWrite(SEG_G, HIGH);
break;
case 4:
digitalWrite(SEG_B, HIGH);
digitalWrite(SEG_C, HIGH);
digitalWrite(SEG_F, HIGH);
digitalWrite(SEG_G, HIGH);
break;
case 3:
digitalWrite(SEG_A, HIGH);
digitalWrite(SEG_B, HIGH);
digitalWrite(SEG_C, HIGH);
digitalWrite(SEG_D, HIGH);
digitalWrite(SEG_G, HIGH);
break;
case 2:
digitalWrite(SEG_A, HIGH);
digitalWrite(SEG_B, HIGH);
digitalWrite(SEG_D, HIGH);
digitalWrite(SEG_E, HIGH);
digitalWrite(SEG_G, HIGH);
break;
case 1:
digitalWrite(SEG_B, HIGH);
digitalWrite(SEG_C, HIGH);
break;
case 0:
digitalWrite(SEG_A, HIGH);
digitalWrite(SEG_B, HIGH);
digitalWrite(SEG_C, HIGH);
digitalWrite(SEG_D, HIGH);
digitalWrite(SEG_E, HIGH);
digitalWrite(SEG_F, HIGH);
break;
}
}