Traffic Light System
with 7-Segment Countdown
Combine three LEDs and a 7-segment display to build a real traffic light that counts down 5–0 for each phase — exactly like the signals on the road.
What Will You Build?
This project combines a 7-segment display (showing digits 0–5) with a three-LED traffic light. Instead of a plain delay(5000), the display counts down from 5 to 0 during each phase — exactly how real smart traffic signals work!
Traffic Light Phases
The traffic light cycles through three phases. During each, the 7-segment display counts down from 5 to 0, giving drivers and pedestrians a visual timer.
🔴 RED — Stop
Red LED ON. All traffic must stop. Display counts 5→0.
🟡 YELLOW — Caution
Yellow LED ON. Traffic prepares to move. Display counts 5→0.
🟢 GREEN — Go
Green LED ON. Traffic moves. Display counts 5→0.
Components Required
| # | Component | Qty | Role |
|---|---|---|---|
| 1 | Arduino UNO | ×1 | Controls all LEDs and the 7-segment display |
| 2 | Red LED | ×1 | Stop signal |
| 3 | Yellow LED | ×1 | Caution signal |
| 4 | Green LED | ×1 | Go signal |
| 5 | Common Cathode 7-Segment Display | ×1 | Countdown timer (5→0) for each phase |
| 6 | 220Ω Resistors | ×10 | 7 for segments + 3 for LEDs |
| 7 | Breadboard | ×1 | Clean prototyping surface |
| 8 | Jumper Wires | ~20 | All connections |
Interactive Preview
Watch the traffic light and countdown work together. Press Play to start the simulation.
Circuit Connections
The full circuit combines three LED connections and seven 7-segment pins. Follow the wiring guide below.
7-Segment Display Explorer
This project only uses digits 0–5 for the countdown. Click each to see the exact segment pattern light up.
Digit-by-Digit Pin States
Segment Truth Table (Digits 0–5)
1 = HIGH (ON) · 0 = LOW (OFF) · Only digits 0–5 are needed for the countdown timer.
| Digit | a (7) | b (8) | c (9) | d (10) | e (11) | f (12) | g (13) |
|---|
The Arduino Code
Two tabs below: the full traffic light + countdown code, and the standalone showDigit() function you can study separately.
// ── Traffic Light + 7-Segment Countdown ────── // Traffic Light LED Pins int redLED = 2; int yellowLED = 3; int greenLED = 4; // 7-Segment Pins (a–g) int a=7, b=8, c=9, d=10, e=11, f=12, g=13; void setup() { pinMode(redLED, OUTPUT); pinMode(yellowLED, OUTPUT); pinMode(greenLED, OUTPUT); pinMode(a,OUTPUT); pinMode(b,OUTPUT); pinMode(c,OUTPUT); pinMode(d,OUTPUT); pinMode(e,OUTPUT); pinMode(f,OUTPUT); pinMode(g,OUTPUT); } // Display a digit (0–5) on the 7-segment display void showDigit(int num) { int seg[6][7] = { {1,1,1,1,1,1,0}, // 0: a,b,c,d,e,f ON {0,1,1,0,0,0,0}, // 1: b,c ON {1,1,0,1,1,0,1}, // 2: a,b,d,e,g ON {1,1,1,1,0,0,1}, // 3: a,b,c,d,g ON {0,1,1,0,0,1,1}, // 4: b,c,f,g ON {1,0,1,1,0,1,1} // 5: a,c,d,f,g ON }; digitalWrite(a, seg[num][0]); digitalWrite(b, seg[num][1]); digitalWrite(c, seg[num][2]); digitalWrite(d, seg[num][3]); digitalWrite(e, seg[num][4]); digitalWrite(f, seg[num][5]); digitalWrite(g, seg[num][6]); } // Countdown 5→0, one second per digit void countdown() { for (int i = 5; i >= 0; i--) { showDigit(i); delay(1000); } } void loop() { // ── RED PHASE ────────────────────────────── digitalWrite(redLED, HIGH); digitalWrite(yellowLED, LOW); digitalWrite(greenLED, LOW); countdown(); // ── YELLOW PHASE ─────────────────────────── digitalWrite(redLED, LOW); digitalWrite(yellowLED, HIGH); digitalWrite(greenLED, LOW); countdown(); // ── GREEN PHASE ──────────────────────────── digitalWrite(redLED, LOW); digitalWrite(yellowLED, LOW); digitalWrite(greenLED, HIGH); countdown(); }
// Standalone showDigit() — drop into any project int a=7, b=8, c=9, d=10, e=11, f=12, g=13; void showDigit(int num) { int seg[6][7] = { {1,1,1,1,1,1,0}, {0,1,1,0,0,0,0}, {1,1,0,1,1,0,1}, {1,1,1,1,0,0,1}, {0,1,1,0,0,1,1}, {1,0,1,1,0,1,1} }; digitalWrite(a,seg[num][0]); digitalWrite(b,seg[num][1]); digitalWrite(c,seg[num][2]); digitalWrite(d,seg[num][3]); digitalWrite(e,seg[num][4]); digitalWrite(f,seg[num][5]); digitalWrite(g,seg[num][6]); } // Usage: showDigit(3); → displays "3" on the display
- 2D array —
seg[6][7]stores all 6 segment patterns in one compact structure - Function reuse —
countdown()is called once per phase instead of repeating 18 lines - for loop — counts from 5 down to 0, displaying each digit and waiting 1 second
Try It in Tinkercad
The complete circuit with traffic light LEDs and 7-segment countdown is pre-wired. Hit Start Simulation to watch the full cycle run.
Open Traffic Light Simulation
All LEDs and 7-segment display are connected. Start the simulation and watch the full RED→YELLOW→GREEN cycle with live countdown.
- Run the simulation — observe the full RED→YELLOW→GREEN cycle with countdown.
- Change the
forloop to count from 9→0 for a 9-second phase. - Make the yellow phase shorter (count from 2→0 instead of 5→0).
- Challenge: Add a buzzer that beeps once per second during the red phase only.
- Bonus: Add a second set of traffic lights for cross-traffic!
Test Your Knowledge
Click an option to check your answer instantly.
countdown() function do in this project?countdown() called as a function rather than repeating the code 3 times?seg[6][7] 2D array?Real-World Applications
- Add a buzzer that beeps every second during the countdown
- Use a push button to let pedestrians manually trigger the green phase
- Add a second 7-segment display for two-digit countdown (00–59)
- Use a PIR motion sensor to extend green when vehicles are detected
- Add an LCD screen showing STOP / CAUTION / GO text alongside the lights
Comments
Post a Comment