๐Ÿšฆ

Working Traffic Light

Explorer ยท Ages 7โ€“9

  1. 1Read the conceptLearn the big idea behind this project.
  2. 2Check the partsSee which parts the robot needs.
  3. 3Follow the build stepsBuild it step by step, then test it.
  4. 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!

+ โˆ’BatteryMicrocontroller

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.

๐Ÿง  Project quiz

Question 1/10โญ 0

A traffic light showsโ€ฆ