Arduino Traffic Light With Push-Button Activated 7-Segment Countdown

by 1073268 in Circuits > Arduino

17 Views, 2 Favorites, 0 Comments

Arduino Traffic Light With Push-Button Activated 7-Segment Countdown

image_2026-06-19_013212257.png

In this project, I created a working traffic light system using an Arduino Uno, three LEDs (red, yellow, green), a 7‑segment display, and a push button.

The system stays OFF until the button is pressed. When pressed, the 7‑segment display counts down from 9 to 0, then the traffic light runs through its full sequence: green → yellow → red.

This project helped me learn:

- How microcontrollers control digital outputs

- How 7‑segment displays work

- How to use a push button with a pull‑down resistor

- How real traffic systems use timing and sensors


Supplies

image_2026-06-19_013410717.png

- Arduino Uno

- Breadboard

- Red LED

- Yellow LED

- Green LED

- 7‑segment display

- 5 × 220Ω resistors

- 1 × 10kΩ resistor

- Push button

- USB cable

Circuit Overview

This project uses:

- Pins 2, 3, 5 for the traffic lights

- Pins 7–13 for the 7‑segment display

- Pin 4 for the push button

The button uses a pull‑down resistor, meaning the input stays LOW until the button is pressed.

Wiring the Components

Traffic Light LEDs

- Green LED → Pin 2

- Yellow LED → Pin 3

- Red LED → Pin 5

Each LED must have a 220Ω resistor to ground.


Place the 7-segment display on the breadboard

Connect each segment (a–g) to Arduino pins:

  1. a → D11
  2. b → D10
  3. c → D9
  4. d → D8
  5. e → D9
  6. f → D13
  7. g → D12

Common cathode pins → 5V


Push Button Wiring

- One side of button → 5V

- Other side → Pin 4

- Same side → 10kΩ resistor → GND

This ensures the Arduino reads a stable LOW until the button is pressed.

How the System Works

- The Arduino waits for the button to be pressed

- When pressed:

1. The 7‑segment display counts down from 9 → 0

2. The green LED turns on for 10 seconds

3. The yellow LED turns on for 2 seconds

4. The red LED turns on for 5 seconds

- After the cycle, everything resets and waits for the next button press

This simulates a pedestrian crossing button at a real intersection.

Upload the Arduino Code

int greenLED = 2;

int yellowLED = 3;

int redLED = 5;

int pushButt = 4;

int a = 11;

int b = 10;

int c = 9;

int d = 8;

int e = 7;

int f = 13;

int g = 12;


void setup() {

pinMode(greenLED, OUTPUT);

pinMode(yellowLED, OUTPUT);

pinMode(redLED, OUTPUT);


pinMode(a, OUTPUT);

pinMode(b, OUTPUT);

pinMode(c, OUTPUT);

pinMode(d, OUTPUT);

pinMode(e, OUTPUT);

pinMode(f, OUTPUT);

pinMode(g, OUTPUT);

pinMode (pushButt, INPUT);

}


void zero() {

digitalWrite(a, LOW);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, LOW);

digitalWrite(g, HIGH);

}


void one() {

digitalWrite(a, HIGH);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, HIGH);

digitalWrite(e, HIGH);

digitalWrite(f, HIGH);

digitalWrite(g, HIGH);

}


void two() {

digitalWrite(a, LOW);

digitalWrite(b, LOW);

digitalWrite(c, HIGH);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, HIGH);

digitalWrite(g, LOW);

}


void three() {

digitalWrite(a, LOW);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, LOW);

digitalWrite(e, HIGH);

digitalWrite(f, HIGH);

digitalWrite(g, LOW);

}


void four() {

digitalWrite(a, HIGH);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, HIGH);

digitalWrite(e, HIGH);

digitalWrite(f, LOW);

digitalWrite(g, LOW);

}


void five() {

digitalWrite(a, LOW);

digitalWrite(b, HIGH);

digitalWrite(c, LOW);

digitalWrite(d, LOW);

digitalWrite(e, HIGH);

digitalWrite(f, LOW);

digitalWrite(g, LOW);

}


void six() {

digitalWrite(a, LOW);

digitalWrite(b, HIGH);

digitalWrite(c, LOW);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, LOW);

digitalWrite(g, LOW);

}


void seven() {

digitalWrite(a, LOW);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, HIGH);

digitalWrite(e, HIGH);

digitalWrite(f, HIGH);

digitalWrite(g, HIGH);

}


void eight() {

digitalWrite(a, LOW);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, LOW);

digitalWrite(g, LOW);

}


void nine() {

digitalWrite(a, LOW);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, LOW);

digitalWrite(e, HIGH);

digitalWrite(f, LOW);

digitalWrite(g, LOW);

}


void countdown() {

nine(); delay(1000);

eight(); delay(1000);

seven(); delay(1000);

six(); delay(1000);

five(); delay(1000);

four(); delay(1000);

three(); delay(1000);

two(); delay(1000);

one(); delay(1000);

zero(); delay(1000);

}

void loop() {


int buttonState = digitalRead (pushButt);

if (buttonState == High){

digitalWrite(greenLED, HIGH);

digitalWrite(yellowLED, LOW);

digitalWrite(redLED, LOW);

countdown();


digitalWrite(greenLED, LOW);

digitalWrite(yellowLED, HIGH);

digitalWrite(redLED, LOW);

zero();

delay(2000);


digitalWrite(greenLED, LOW);

digitalWrite(yellowLED, LOW);

digitalWrite(redLED, HIGH);

zero();

delay (8000);

} else {

digitalWrite(greenLED, LOW);

digitalWrite(yellowLED, LOW);

digitalWrite(redLED, LOW);

}

}

Observe the System

Green light turns ON

7-segment counts down from 9 to 0

Yellow light flashes briefly

Red light turns ON

Cycle repeats automatically

Testing

Check all LED connections

Verify 7-segment digits display correctly

Adjust delays if countdown is too fast/slow

Reflection

This project taught me how to combine electronics and programming to simulate a real‑world system.

Adding the push button helped me understand how sensors trigger events in real traffic lights.

If I improved this project, I would add a buzzer or a pedestrian walk symbol.