Traffic Light System

Learn how to read a push button and count the number of presses using Arduino.

Components Needed

Arduino Uno

Red LED

Yellow LED

Green LED

3 × 220Ω Resistors

Breadboard

Jumper Wires

  • How It Works

    The Arduino controls three LEDs to simulate a real traffic light. The green light turns on first, followed by the yellow light, and then the red light. This sequence repeats continuously just like a real traffic signal.

  • What You'll Learn

    Controlling multiple LEDs

    Digital outputs

    Timing with delay()

    Sequential program logic

    Real-world automation concepts

  • Code

    int redLED = 8;
    int yellowLED = 9;
    int greenLED = 10;

    void setup() {
    pinMode(redLED, OUTPUT);
    pinMode(yellowLED, OUTPUT);
    pinMode(greenLED, OUTPUT);
    }

    void loop() {

    // Green Light
    digitalWrite(greenLED, HIGH);
    digitalWrite(yellowLED, LOW);
    digitalWrite(redLED, LOW);
    delay(5000);

    // Yellow Light
    digitalWrite(greenLED, LOW);
    digitalWrite(yellowLED, HIGH);
    digitalWrite(redLED, LOW);
    delay(2000);

    // Red Light
    digitalWrite(greenLED, LOW);
    digitalWrite(yellowLED, LOW);
    digitalWrite(redLED, HIGH);
    delay(5000);
    }