Traffic Light System with Micro:bit

In this project, learners explore how traffic lights work and how technology improves road safety using the Micro:bit. They program red, yellow, and green LED lights to follow the correct sequence and timing, and learn important concepts like sequencing, timing, and logical thinking. We have included extra challenges that encourage learners to experiment with different light patterns, making learning fun and interactive. Through this hands-on experience, learners build creativity, problem-solving skills, and confidence. The project also introduces AI ideas, showing how smart traffic lights can respond to traffic flow and keep communities safe.

ItemPurpose
BBC Micro:bitThe brain of your project
USB cableConnects the Micro:bit to your computer
BreadboardFor building the circuit without soldering
Red LEDRepresents the stop light
Yellow LEDRepresents the get-ready light
Green LEDRepresents the go light
220Ω resistorsProtect the LEDs from too much current
Jumper wiresConnect all components together

Traffic Light Connections

  1. Connect the Red LED's long leg (+) of the LED to one end of the 220Ω resistor.

  2. Connect the other end of the resistor to Pin 0 on the Microbit
  3. Connect the Red LED's short leg (–) of the LED to GND on the Microbit

  1. Connect the Yellow LED's long leg (+) of the LED to one end of the 220Ω resistor.
  2. Connect the other end of the resistor to Pin 1 on the Microbit
  3. Connect the Yellow LED's short leg (–) of the LED to GND on the Microbit

  1. Connect the Green LED's long leg (+) of the LED to one end of the 220Ω resistor.
  2. Connect the other end of the resistor to Pin 2 on the Microbit
  3. Connect the Green LED's short leg (–) of the LED to GND on the Microbit

Tip: Always use a resistor between the LED and Microbit pin to prevent burning out your LED!

Follow these steps carefully to open and explore the project in Microsoft MakeCode for Micro:bit:

Plug in your Micro:bit to your computer using a USB cable, then follow the steps in the video to upload your code and bring your project to life!

Code Block                                 What It Does
Forever blockThis makes your program run over and over again.
digital write pin P0 to 1Turns ON the red LED connected to pin0.  (Stop!)
pause (3000 ms)Waits for 3 seconds before changing to the next light.
digital write pin P0 to 0Turns OFF the red LED.
digital write pin P1 to 1Turns ON the yellow LED connected to pin1.  (Get ready!)
pause (1000 ms)Waits for 1 second before turning green.
digital write pin P1 to 0Turns OFF the yellow LED.
digital write pin P2 to 1Turns ON the green LED connected to pin2.  (Go!)
pause (3000 ms)Waits for 3 seconds before switching back.
digital write pin P2 to 0Turns OFF the green LED, and the cycle starts again!

If the lights don’t behave correctly:

  • Check that your LEDs are connected to the correct pins (0, 1, 2).

  • Make sure the long leg of each LED is connected to the Micro:bit pin, and the short leg goes to GND.

  • Double-check that you didn’t forget a resistor!

  • How to connect and control multiple LEDs with the Micro:bit.
  • How to create a repeating sequence with loops.
  • The difference between digital HIGH (1) and LOW (0) signals.
  • How timing and delays control light changes, just like in real traffic lights!

  • Try adding a buzzer that beeps when the red light turns ON.
  • Make the lights blink faster (use smaller delay times).
  • Add a pedestrian crossing light using another LED and button input!

Use either Micro:bit's CreateAI or Edge Impulse to build, train, and deploy machine learning (ML) models to make the traffic lights more intelligent and playful. The AI can learn patterns and predict what should happen next.

For example:

  • Traffic Flow Predictor: The Micro:bit checks how often cars  “arrive” at the intersection (add a button to your project to simulate a car approaching when pressed). After a few tries, it predicts when the next car will come and changes the lights automatically.

  • Fun Game Mode: Students can press buttons randomly to test the AI, and the Micro:bit tries to match or adjust the light sequence, creating a fun interactive game.

  • Adaptive Timing: The AI can speed up or slow down the green light depending on how many cars are “waiting,” teaching kids about smart decision-making.