Learning Overview
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.
What You will Need
| Item | Purpose |
|---|---|
| BBC Micro:bit | The brain of your project |
| USB cable | Connects the Micro:bit to your computer |
| Breadboard | For building the circuit without soldering |
| Red LED | Represents the stop light |
| Yellow LED | Represents the get-ready light |
| Green LED | Represents the go light |
| 220Ω resistors | Protect the LEDs from too much current |
| Jumper wires | Connect all components together |
Understand the Circuit
Traffic Light Connections

Connect the Red LED's long leg (+) of the LED to one end of the 220Ω resistor.
- Connect the other end of the resistor to Pin 0 on the Microbit
Connect the Red LED's short leg (–) of the LED to GND on the Microbit

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

- Connect the Green LED's long leg (+) of the LED to one end of the 220Ω resistor.
- Connect the other end of the resistor to Pin 2 on the Microbit
- 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!
The Project Code
Follow these steps carefully to open and explore the project in Microsoft MakeCode for Micro:bit:
When you open the link, you will see a few colorful blocks that makes the project.
Next, click Edit Code tab to be directed to the MakeCode editor
Uploading the Code
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!
Understand the code
| Code Block | What It Does |
|---|---|
| Forever block | This makes your program run over and over again. |
| digital write pin P0 to 1 | Turns 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 0 | Turns OFF the red LED. |
| digital write pin P1 to 1 | Turns ON the yellow LED connected to pin1. (Get ready!) |
| pause (1000 ms) | Waits for 1 second before turning green. |
| digital write pin P1 to 0 | Turns OFF the yellow LED. |
| digital write pin P2 to 1 | Turns ON the green LED connected to pin2. (Go!) |
| pause (3000 ms) | Waits for 3 seconds before switching back. |
| digital write pin P2 to 0 | Turns OFF the green LED, and the cycle starts again! |
Troubleshooting the code
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!
What You Have Learned
- 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!
Extra Challenge
- 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!
AI Extension Ideas
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.


