Introduction: 🚦 Micro:bit Traffic Light – Step-by-Step Guide

About: Enhance Your Skills in Today's Digital World Dive into an immersive experience at the forefront of the digital revolution! Our association provides a unique opportunity to explore a diverse range of exciting d…

πŸ“… 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. 1 Γ— BBC micro:bit
  2. 1 Γ— micro:bit battery pack (optional)
  3. 3 Γ— LEDs (red, yellow, green)
  4. 3 Γ— Resistors (220–330 Ξ©)
  5. Jumper wires
  6. Breadboard
  7. USB cable

Step 2: πŸ”Œβ€” Wire the LEDs

Connect the LEDs like this:

  1. πŸ”΄ Red LED β†’ Pin P0
  2. 🟑 Yellow LED β†’ Pin P1
  3. 🟒 Green LED β†’ Pin P2

All LEDs β†’ resistor β†’ GND

Make sure the flat side of each LED is connected to GND.

Step 3: πŸ’» β€” Open MakeCode

  1. Go to makecode.microbit.org
  2. Click New Project
  3. Name it: Traffic_Light

Step 4: πŸ”§ β€” Initialize the Pins (On Start)

Inside the On start block, set all pins to 0:

  1. Set P0 to 0
  2. Set P1 to 0
  3. 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)

  1. P0 = 1
  2. P1 = 0
  3. P2 = 0
  4. Pause 2000 ms

🟑 Yellow light (1 second)

  1. P0 = 0
  2. P1 = 1
  3. P2 = 0
  4. Pause 1000 ms

🟒 Green light (2 seconds)

  1. P0 = 0
  2. P1 = 0
  3. P2 = 1
  4. Pause 2000 ms

Repeat forever!

Step 6: ▢️ β€” Download and Run

  1. Click Download
  2. Drag the file onto the MICROBIT drive
  3. Watch your traffic light sequence come to life! 🚦✨

Step 7: πŸŽ‰ β€” Improve It! (Optional)

Try adding extra features:

  1. ⚑ Button A β†’ Start/Stop the traffic light
  2. ⏱️ Button B β†’ Change durations
  3. πŸš— Add a pedestrian crossing mode
  4. πŸ”Š 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

  1. Power the receiver micro:bit (the one driving the LEDs).
  2. Power the transmitter micro:bit (the remote).
  3. Press buttons on the remote:
  4. πŸ”΄ A β†’ Red
  5. 🟒 B β†’ Green
  6. 🟑 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

  1. Power ON the receiver (the micro:bit connected to the LEDs).
  2. πŸ‘‰ It shows β€œRX” and all LEDs turn OFF.
  3. Power ON the transmitter (the remote-control micro:bit).
  4. πŸ‘‰ It shows β€œTX”.
  5. Press the buttons on the remote to control the traffic light:
  6. πŸ”΄ Button A β†’ Red light
  7. 🟒 Button B β†’ Green light
  8. 🟑 Button A + B β†’ Yellow light
  9. The receiver shows a small icon, updates the LED color, then clears the screen.
  10. πŸ‘‰ Only one LED is lit at a time.


Step 11: Have Fun

Enjoy