Traffic Light
Build a real working traffic light that cycles red, yellow and green — your first timing project.
What You'll Build
You are going to build a tiny traffic light that looks and behaves like the real one at the end of your street. Three LEDs light up one after another in the correct order, each one staying on for a realistic amount of time. By the end you will understand how a program can control time, and how to switch several outputs on and off in a repeating pattern.
What You Need
- ✓Arduino Uno
- ✓Red / Yellow / Green LED
- ✓3 × 220Ω resistor
- ✓Breadboard
- ✓Jumper wires
How It Works
Each LED is connected to its own digital pin on the Arduino. A digital pin can be HIGH (about 5 volts, LED on) or LOW (0 volts, LED off). Your program turns one pin HIGH, waits, turns it LOW, then moves to the next colour. Because loop() repeats forever, the light cycles all day long — exactly like a real traffic light controller.
Wiring
- 1Push the three LEDs into the breadboard. The long leg (anode) goes to the right, the short leg (cathode) to the left.
- 2Connect each short leg through the blue ground rail back to the Arduino GND pin.
- 3Put a 220Ω resistor between each long leg and its own row.
- 4Wire red to pin 10, yellow to pin 9, green to pin 8.
Step-by-Step Instructions
- 1
Place your LEDs
Line the three LEDs up on the breadboard in traffic-light order: red on top, yellow in the middle, green at the bottom. Leave a couple of empty rows between them so the wires do not touch.
- 2
Add the resistors
Every LED needs a 220Ω resistor. It limits the current so the LED glows brightly instead of burning out. Resistors have no direction, so either way round is fine.
- 3
Wire the ground rail
Run a jumper from the Arduino GND pin to the blue (−) rail, then connect each LED's short leg to that rail. Now every LED shares one return path.
- 4
Connect the signal wires
Jumper pin 10 to the red LED's resistor, pin 9 to yellow, pin 8 to green.
- 5
Upload the code
Plug in the USB cable, choose your board and port, then press Upload. Within a few seconds the lights start cycling.
- 6
Tune the timing
Change the delay values to make your junction faster or slower — real traffic lights use different timings at busy and quiet times.
Arduino Code
const int RED = 10;
const int YELLOW = 9;
const int GREEN = 8;
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);
}
void loop() {
digitalWrite(RED, HIGH); // stop
delay(4000);
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH); // go
delay(4000);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH); // get ready to stop
delay(1500);
digitalWrite(YELLOW, LOW);
}Understanding the Code
const int RED = 10;Gives pin 10 a friendly name. If you rewire the LED later you only change this one line.
pinMode(RED, OUTPUT);Tells the Arduino that this pin will push electricity out to an LED instead of listening for a signal.
digitalWrite(RED, HIGH);Switches the pin fully on — about 5 volts — so the LED lights up.
delay(4000);Freezes the program for 4000 milliseconds (4 seconds) while the light stays on.
void loop()Everything inside runs top to bottom, then starts again from the top, forever.
Challenges & Upgrades
Troubleshooting
😖 One LED never lights
Fix: Flip it around. LEDs only work one way — the long leg must face the resistor and pin side.
😖 All LEDs are very dim
Fix: Check that your ground wire actually reaches the Arduino GND, not just the breadboard rail.
😖 Upload fails
Fix: Select the right board and port under Tools, and unplug anything connected to pins 0 and 1.
Up next
🌙 Smart Night Light