Working Traffic Light
Explorer ยท Ages 7โ9
- 1Read the conceptLearn the big idea behind this project.
- 2Check the partsSee which parts the robot needs.
- 3Follow the build stepsBuild it step by step, then test it.
- 4Answer the quizTap one answer for each of the 10 questions to earn XP.
๐ก The concept
A traffic light shows one light at a time in a fixed order: red, then green, then yellow, then back to red. Your program does the same with three LEDs and delays โ each light turns on for a few seconds, then hands over to the next. A program that is always in exactly one state, like red OR green, is called a state machine.
Parts you need
- 3 LEDs (red, yellow, green)
- 3 resistors (220ฮฉ)
- Microcontroller
- Battery
- Cardboard tube for the housing
๐ Parts specification
Exactly what each part is, which models to buy, and what it does.
Microcontrollerโธ
Suggested models: BBC micro:bit V2 or Arduino Uno R3
Features: Needs 3 digital output pins, one per colour. On the micro:bit you can even practise on its built-in red LEDs first. The Uno has plenty of spare pins.
LEDsโธ
Suggested models: Standard 5mm LEDs: 1 red, 1 yellow, 1 green
Features: Each colour needs about 2V. Long leg is + (anode), short leg is โ (cathode). Real traffic lights use super-bright versions, but any 5mm LED works for a model.
Resistorsโธ
Suggested models: 3ร 220ฮฉ
Features: One resistor per LED limits the current so the LEDs stay safe and bright.
Battery / powerโธ
Suggested models: 2รAA pack or USB cable
Features: 3Vโ5V is plenty. Keep the battery off while you build.
Housingโธ
Suggested models: Cardboard tube, black card, or a kitchen-roll roll
Features: Roll dark card into a tube and mount the LEDs inside โ it instantly looks like a real traffic light.
๐ป Program the microcontroller
๐ฒ App to use: Microsoft MakeCode (makecode.microbit.org) for micro:bit, or Arduino IDE for Arduino Uno
In MakeCode use: forever โ set red on, pause 3000 ms, set green on, pause 5000 ms, set yellow on, pause 2000 ms.
// Arduino IDE (C++) โ Working Traffic Light
const int RED = 2, YELLOW = 3, GREEN = 4;
void allOff() {
digitalWrite(RED, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, LOW);
}
void loop() {
allOff(); digitalWrite(RED, HIGH); // stop
delay(3000);
allOff(); digitalWrite(GREEN, HIGH); // go
delay(5000);
allOff(); digitalWrite(YELLOW, HIGH); // get ready
delay(2000);
}๐ง How it works: The light moves through a fixed cycle: 3 seconds red, 5 seconds green, 2 seconds yellow, then back to red forever. delay() is what makes each light stay on. To make a UK-style pattern, keep red on while yellow also lights up before green.
๐ ๏ธ Build it step by step
Press Play to watch every part go into place and every wire connect. Ask a grown-up to help with real wiring!
Step 1 of 6
๐ Power the board
Connect the battery to the microcontroller (red wire to +, black to โ). Keep the battery switched OFF while you build.