Three LEDs run the red → red + yellow → green → yellow cycle of a real traffic light. You will control several outputs and write your own function.
| Part | How many |
|---|---|
| UNO R3 + USB cable | 1 |
| 400-point breadboard | 1 |
| Red, yellow and green LED | 1 each |
| 220 Ω resistors (red-red-brown) | 3 |
| Jumper wires | about 8 |
Nothing extra - just the kit and your computer.
Each LED has its own pin: red on 2, yellow on 3, green on 4. HIGH turns an LED on and LOW turns it off.
showLights() switches all three LEDs at once, prints the name of the phase and waits. loop() calls it four times, one full cycle, and then starts again.
The order is the one many countries use: red (stop), red + yellow (get ready), green (go), yellow (prepare to stop).
Every item is in the kit — nothing extra to buy.
All 10 parts in one box, with this project and 6 more to build from them.
One of each part. Packs (resistor assortment, jumper wires) already hold more than a single build needs. red/yellow/green LEDs: included in the kit, ask us for it loose. Delivery is AED 20, free on orders AED 100+.
Unplug USB before you change any wire. Pin names are the labels printed on the board.
| Part / pin | Connect to | Note |
|---|---|---|
| Red LED long leg (+) | 220 Ω → UNO pin 2 | |
| Yellow LED long leg (+) | 220 Ω → UNO pin 3 | Already wired in Lesson 1 |
| Green LED long leg (+) | 220 Ω → UNO pin 4 | |
| All three short legs (−) | − rail (GND) | |
| UNO 5V / GND | + rail / − rail | Already wired in Lesson 1 |
| Potentiometer | Can stay as in Lesson 1 | Not used in this lesson |
One thing at a time. Tick nothing off until it matches the diagram.
Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.
/*
DIY KIT - Arduino UNO Sensor & Output Starter Kit
Lesson 2 of 7: Traffic Light
WIRING (unplug the USB cable before you wire)
Keep the yellow LED from Lesson 1 on pin 3 and add two more:
Red LED long leg (+) -> 220 ohm resistor -> UNO pin 2
Yellow LED long leg (+) -> 220 ohm resistor -> UNO pin 3
Green LED long leg (+) -> 220 ohm resistor -> UNO pin 4
Every short leg (-) -> GND rail of the breadboard
The potentiometer from Lesson 1 can stay where it is.
WHAT SHOULD HAPPEN
Red (3 s) -> red + yellow (1 s) -> green (3 s) -> yellow (1.2 s) -> repeat.
*/
const int RED_PIN = 2;
const int YELLOW_PIN = 3;
const int GREEN_PIN = 4;
// How long each light stays on, in milliseconds (1000 ms = 1 second).
const unsigned long RED_MS = 3000; // stop
const unsigned long RED_YELLOW_MS = 1000; // get ready
const unsigned long GREEN_MS = 3000; // go
const unsigned long YELLOW_MS = 1200; // prepare to stop
// Switch the three lights, tell the Serial Monitor, then wait.
// true = on, false = off.
void showLights(bool red, bool yellow, bool green, const char *name, unsigned long holdMs) {
digitalWrite(RED_PIN, red ? HIGH : LOW);
digitalWrite(YELLOW_PIN, yellow ? HIGH : LOW);
digitalWrite(GREEN_PIN, green ? HIGH : LOW);
Serial.println(name);
delay(holdMs);
}
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Lesson 2: Traffic Light");
}
void loop() {
showLights(true, false, false, "RED", RED_MS);
showLights(true, true, false, "RED + YELLOW", RED_YELLOW_MS);
showLights(false, false, true, "GREEN", GREEN_MS);
showLights(false, true, false, "YELLOW", YELLOW_MS);
}
| In the code | What it does |
|---|---|
| const int RED_PIN = 2; ... | Names for the three LED pins. |
| const unsigned long RED_MS = 3000; | How long each phase lasts, in milliseconds. |
| showLights(red, yellow, green, name, holdMs) | Our own function: true means on, false means off. It also prints the phase name and waits holdMs. |
| loop() | Four calls to showLights(): one full traffic-light cycle. |
| Problem | What to check |
|---|---|
| One LED never lights | Unplug USB and turn that LED round (long leg towards the resistor). Check its wire goes to the right pin. |
| The wrong colour lights at the wrong time | Two pin wires are swapped. Red must be on 2, yellow on 3, green on 4. |
| All the LEDs stay off | Check the − rail is connected to a UNO GND pin. |
| Nothing in the Serial Monitor | Set the speed in the Serial Monitor to 9600 baud. |
Use a stopwatch (or a phone) to time the green phase. Is it really 3 seconds? Change GREEN_MS and time it again.
2500.
Only the yellow LED.
Because loop() runs over and over for ever.
Most problems are one wire in the wrong hole. Check these first:
Open the troubleshooting table for this step →
Hi DIY KIT, I'm stuck on the Arduino UNO Sensor & Output Starter Kit. Lesson: __ Step number: __ What should happen: __ What happens instead: __ Error message (copied exactly): __ I'll attach a photo of my wiring.
Blink an LED, then fade it with a knob. Learn which LED leg is +, why every LED needs a resistor, and how the UNO dims a light. Do Start here first.
The buzzer plays a slow beep, a fast alarm and SOS in Morse code. Type 0-3 in the Serial Monitor to choose: your first commands from the computer.
Measure distance with sound. The HC-SR04 times an echo and the UNO turns it into centimetres, drawn live in the Serial Plotter.
We use cookies that the shop needs to work — signing in, your cart, form security. We also measure how the shop is used so we can stock the right parts and fix what is broken. Choose “Only essential” and we will not load Google Analytics or the Meta pixel, and will not record your visit. Read more.