Introduction: π¦ Micro:bit Traffic Light β Step-by-Step Guide
π On the program:
β¨ Discover the BBC micro:bit
π‘ Learn how to turn on lights and move a servo motor
π¦ Build your own traffic light
π§ Leave with your code and a head full of new ideas!
Supplies
Step 1: π§° β Gather Your Materials
You will need:
- 1 Γ BBC micro:bit
- 1 Γ micro:bit battery pack (optional)
- 3 Γ LEDs (red, yellow, green)
- 3 Γ Resistors (220β330 Ξ©)
- Jumper wires
- Breadboard
- USB cable
Step 2: πβ Wire the LEDs
Connect the LEDs like this:
- π΄ Red LED β Pin P0
- π‘ Yellow LED β Pin P1
- π’ Green LED β Pin P2
All LEDs β resistor β GND
Make sure the flat side of each LED is connected to GND.
Step 3: π» β Open MakeCode
- Go to makecode.microbit.org
- Click New Project
- Name it: Traffic_Light
Step 4: π§ β Initialize the Pins (On Start)
Inside the On start block, set all pins to 0:
- Set P0 to 0
- Set P1 to 0
- Set P2 to 0
This makes sure all LEDs start OFF.
Step 5: π β Create the Traffic Light Loop (Forever)
Inside the Forever block:
π΄ Red light (2 seconds)
- P0 = 1
- P1 = 0
- P2 = 0
- Pause 2000 ms
π‘ Yellow light (1 second)
- P0 = 0
- P1 = 1
- P2 = 0
- Pause 1000 ms
π’ Green light (2 seconds)
- P0 = 0
- P1 = 0
- P2 = 1
- Pause 2000 ms
Repeat forever!
Step 6: βΆοΈ β Download and Run
- Click Download
- Drag the file onto the MICROBIT drive
- Watch your traffic light sequence come to life! π¦β¨
Step 7: π β Improve It! (Optional)
Try adding extra features:
- β‘ Button A β Start/Stop the traffic light
- β±οΈ Button B β Change durations
- π Add a pedestrian crossing mode
- π Add sounds with the micro:bitβs buzzer
Step 8: β Add a Start/Stop Button (Button A)
Give your traffic light an ON/OFF switch!
π― Goal
Press Button A to pause the traffic light.
Press Button A again to resume the sequence.
Step 9: π β Add a Wireless Remote Control (RF Transmitter)
In this step, we turn a second micro:bit into a wireless remote control for your traffic light.
Using the micro:bitβs built-in radio, you can change the color of the traffic light from a distance, with no wires at all!
π How to Use It
- Power the receiver micro:bit (the one driving the LEDs).
- Power the transmitter micro:bit (the remote).
- Press buttons on the remote:
- π΄ A β Red
- π’ B β Green
- π‘ A + B β Yellow
Your traffic light now responds wirelessly!
Step 10: π¦ β Build the Wireless Traffic-Light Receiver
In this step, we program the micro:bit that is connected to the 3 LEDs (Red, Yellow, Green).
This micro:bit receives radio commands sent by the remote control from te last step.
π Using the System
- Power ON the receiver (the micro:bit connected to the LEDs).
- π It shows βRXβ and all LEDs turn OFF.
- Power ON the transmitter (the remote-control micro:bit).
- π It shows βTXβ.
- Press the buttons on the remote to control the traffic light:
- π΄ Button A β Red light
- π’ Button B β Green light
- π‘ Button A + B β Yellow light
- The receiver shows a small icon, updates the LED color, then clears the screen.
- π Only one LED is lit at a time.
Step 11: Have Fun
Enjoy







