Project Overview
Arduino Uno LED Traffic Light Controller: Build a three-LED traffic light (red, yellow, green) that cycles on realistic timings using clean, reusable functions instead of one giant loop.
- Time: ~30 minutes
- Skill level: Beginner
- What you will build: A breadboard traffic light with clean stop()/caution()/go() functions that can be extended to a pedestrian button or a full 4-way intersection.
Parts List
From ShillehTek
- Arduino Uno R3 Super Starter Kit - includes the LEDs, resistors, and breadboard used here
- Resistor Kit - 220a9 for each LED
- Tactile Button Kit - for the pedestrian-crossing upgrade
- 400-Point Breadboard - for prototyping the circuit
- Dupont Jumper Wires - to connect the Arduino pins to the LEDs and rails
External
- None - everything is in the kits
Note: LEDs always need a current-limiting resistor (220a9 here). Long leg (anode) goes toward the Arduino pin; short leg goes to ground through the resistor.
Step-by-Step Guide
Step 1 - Wire the Three LEDs
Goal: Build the red, yellow, and green outputs on a breadboard.
What to do: Connect the red LED to D2, yellow to D4, and green to D6. For each LED, add a 220a9 resistor to the ground rail. Arrange the LEDs vertically so the layout matches a real traffic light.
Expected result: The three LEDs are wired and ready for code.
Step 2 - Write Functions for Each Light State
Goal: Create readable, reusable code that matches the traffic sequence.
What to do: Define pins for the LEDs, write a helper that sets all three, then create go(), caution(), and stop() functions that take a duration. Call them in loop() using realistic timing.
Code:
const int RED = 2, YELLOW = 4, GREEN = 6;
void setLights(bool r, bool y, bool g) {
digitalWrite(RED, r);
digitalWrite(YELLOW, y);
digitalWrite(GREEN, g);
}
void go(int ms) { setLights(LOW, LOW, HIGH); delay(ms); }
void caution(int ms) { setLights(LOW, HIGH, LOW); delay(ms); }
void stop(int ms) { setLights(HIGH, LOW, LOW); delay(ms); }
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);
}
void loop() {
go(5000); // green: 5 s
caution(2000); // yellow: 2 s
stop(5000); // red: 5 s
}
Expected result: The LEDs cycle green, then yellow, then red on the programmed timings.
Step 3 - Add a Pedestrian Button
Goal: Make the traffic light interactive.
What to do: Wire a tactile button from D8 to ground and set pinMode(8, INPUT_PULLUP). Check the button during the green phase. When pressed, jump to caution then stop early, and hold red a few extra seconds to simulate a crossing button.
Expected result: Pressing the button triggers an early change from green to yellow to red.
Step 4 - Scale to an Intersection
Goal: Extend the same pattern to two directions of traffic.
What to do: Add a second set of LEDs for the other road (D3/D5/D7). Interlock the logic so road B stays red while road A cycles, then swap. Keep using the same setLights idea, just expanded for the extra signal head.
Expected result: Two signal heads that never show green at the same time.
Conclusion
You built an Arduino Uno LED traffic light controller that cycles red, yellow, and green using simple state functions. This same structure can grow into button-controlled crossings, multiple signal heads, and eventually non-blocking timing when you outgrow delay().
Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.
Image credit: leos on Hackster.io.







