← Back to Basic Projects

🚦 Smart Traffic Light System

Smart Arduino Traffic Light Project: build a real-world timed traffic light simulation with pedestrian button controls and state machine Arduino code.

πŸ“‹ Overview

Traffic lights are a perfect real-world model for learning state machines. Each light (Red, Yellow, Green) represents a state, and transitions happen on a timer, or when a button is pressed.

Technical Insight: This project replicates a real 3-phase traffic sequence (Red-Yellow-Green) which is the absolute standard in 98% of municipal street crossings worldwide. It is the ideal introductory project to learn how industrial state-machine logic controls safety-critical systems.

In simple terms: The traffic light is always in one of four states (Green, Yellow, Red, or Pedestrian Crossing). By writing code that tracks the active state and listens for button interruptions, we build a system that is far more interactive than a simple timer loop.

What you'll learn: Controlling multiple digital pin outputs simultaneously, timed state sequences, push-button input reading, and basic state-machine logic.

Estimated time: 45-60 minutes. Difficulty: ⭐⭐ Easy: a great next step after blinking a single LED.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R3ATmega328P, 5V1
Red LED5mm, 2V 20mA1
Yellow LED5mm, 2V 20mA1
Green LED5mm, 2V 20mA1
Resistors220Ohm3One per LED
Push ButtonMomentary SPST1Pedestrian button
Resistor10kOhm pull-down1For button
Breadboard + WiresStandard1

πŸ—ΊοΈ Component Pin Mapping

Smart Traffic Light System Component Pin Mapping Infographic

πŸ“– Step-by-Step Tutorial

1

Place the LEDs

Insert Red, Yellow, and Green LEDs into the breadboard vertically with spacing between each.
2

Add Resistors

Wire a 220Ohm resistor from each LED cathode (short leg) to GND rail.
3

Connect to Arduino

Red β†’ Pin 8, Yellow β†’ Pin 9, Green β†’ Pin 10.
4

Add Button

Connect button between pin 2 and 5V. Add 10kOhm pull-down resistor from pin 2 to GND.
5

Upload and Test

Upload the code. Normal cycle runs automatically. Press button to trigger pedestrian signal (green held, then red).
πŸ’‘
The pedestrian button uses a pull-down resistor to keep the pin at LOW by default. Without it, the pin floats and gives random readings.

πŸ’» Arduino Code

traffic_light.ino
INO
// Smart Traffic Light β€” Volt X
const int RED = 8, YELLOW = 9, GREEN = 10;
const int BUTTON = 2;

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

void setLight(int r, int y, int g) {
  digitalWrite(RED, r);
  digitalWrite(YELLOW, y);
  digitalWrite(GREEN, g);
}

void loop() {
  // Green phase
  setLight(LOW, LOW, HIGH);
  for (int i = 0; i < 50; i++) {
    if (digitalRead(BUTTON) == HIGH) break;
    delay(100);
  }

⭐ Reviews & Ratings

β€”0 reviews
5β˜…
0
4β˜…
0
3β˜…
0
2β˜…
0
1β˜…
0
...

Loading reviews...