Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

Arduino Traffic Light System — Project Guide

Introduction

Build a traffic light simulation with red, yellow, and green LEDs. Optionally add a pedestrian button to trigger a safe crossing phase.

Overview

  • Difficulty: Beginner level — requires a basic understanding of Arduino concepts, components, and simple coding. Learners should already know how to connect sensors and upload basic sketches
  • Estimated Time: 45–60 minutes
  • Concepts:
    • Digital Output
    • Timing
    • State Machines
    • Debouncing

Components Required

Item Quantity Notes
Arduino Uno (or compatible) 1 Main controller
LEDs (Red, Yellow, Green) 1 each 5mm
Resistors 220Ω 3 LED current limit
Push Button (optional) 1 Pedestrian request
Breadboard & Jumpers

Circuit Connections

Arduino Pin Connection
D8 Red LED (+ via 220Ω)
D9 Yellow LED (+ via 220Ω)
D10 Green LED (+ via 220Ω)
GND All LED negatives
D2 Button to GND (INPUT_PULLUP)

Arduino Code

const int RED = 8, YELLOW = 9, GREEN = 10, BUTTON = 2;

void setup(){
  pinMode(RED, OUTPUT); pinMode(YELLOW, OUTPUT); pinMode(GREEN, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
}

void phase(int r, int y, int g, unsigned long ms){
  digitalWrite(RED, r); digitalWrite(YELLOW, y); digitalWrite(GREEN, g);
  delay(ms);
}

void normalCycle(){
  phase(HIGH, LOW, LOW, 3000);  // Red
  phase(HIGH, HIGH, LOW, 1000); // Red+Yellow
  phase(LOW, LOW, HIGH, 3000);  // Green
  phase(LOW, HIGH, LOW, 1000);  // Yellow
}

void pedestrianCycle(){
  // Ensure safe stop
  phase(HIGH, HIGH, LOW, 1000);
  phase(HIGH, LOW, LOW, 4000); // Red for crossing
}

void loop(){
  if (digitalRead(BUTTON) == LOW) {
    pedestrianCycle();
  } else {
    normalCycle();
  }
}

Assembly Steps

  1. Place LEDs on a breadboard with resistors to Arduino pins D8, D9, D10.
  2. Wire a pushbutton to D2 and GND; use INPUT_PULLUP in code.
  3. Upload the sketch and test the cycle; press the button to trigger crossing.

Tips

  • Use long delays first, then refactor to non-blocking millis() logic.
  • Swap LEDs for a 4-way junction model by duplicating channels.
  • Enclose in a small cardboard model for a fun display.

Learn More

Leave a Reply

Your email address will not be published. Required fields are marked *