Micro:bit Project with a Traffic Light Module: An Easy STEM Coding Activity

A couple of year ago during my planning period, I was brainstorming ideas for a fun, beginner-friendly BBC micro:bit project that combines coding, electronics, and real-world logic. A browser ad about a tiny (and cheap) traffic light module came to my rescue and I immediately came up with the idea about this project! Using a simple traffic light module connected to a micro:bit and programmed in MakeCode, students create a working traffic light sequence – red, yellow, green – right on their desk. It is a perfect STEM coding activity for grades 4–8, requires no breadboard, and can be completed in a single lesson and with minimum stress.

The traffic light module is the star of the show here – it’s a small board with three built-in LEDs (red, yellow, green) and four pins: one for each color and one for GND. No soldering, no breadboard, just clip and code. I like it when things are simple.

micro:bit traffic light connected

If you’d like to try this project using 3 individual LEDs and 6 crocodile clip cables instead of a module, I have a separate post for that version too – check it out here (link)!

Materials list

  • A BBC micro:bit (any version)
  • A USB cable to connect it to a computer
  • A traffic light LED module (available on AliExpress, Amazon, or similar – search “traffic light module”)
  • 4 crocodile clip cables
  • Access to makecode.microbit.org (free, no account needed)

Preparation steps

  1. I ordered a traffic light module/element/circuit board from Aliexpress and it was unbelievably cheap – $1.21 (price from 2022, price from 2026 = $0.36 ! ) 😮 😮 😮 What I typed in the search bar was “LED traffic light module”, I sorted the products by number of orders and “voilà”! You can do the same to get the module or just look for it in Amazon, I am sure there are plenty there too. I waited about a month for the module to arrive
  2. I prepared 4 crocodile clip cables, one for each LED of the module – red light, yellow light, green light, and one for the ground “GND” pin
This screenshot is from 2022, in 2026 the price of this same module is around $0.36

Logic behind the project

Before we jump into the code, it helps to understand the logic behind a traffic light. I did a lot of research on that. At any given moment, all three lights have a specific state – either ON or OFF. Only one light is on at a time, and each phase lasts for a set amount of time before switching to the next, usually depending on whether the traffic light is serving a big 3-lane boulevard, a small street next to a school or something else.

In MakeCode, we control this using the digital write pin block. Think of it like a light switch for a specific pin on your micro:bit – you tell it which pin and whether to set it to 1 (ON) or 0 (OFF). Digital just means it only has two states – on or off – nothing in between.

For timing, we use the pause (ms) block. This tells the code how long to wait before moving to the next phase. The time is measured in milliseconds – 1 second = 1000 ms.

Wiring the module

Connect your traffic light module to the micro:bit using crocodile clip cables like this:

  • Red pin → Pin 2
  • Yellow pin → Pin 1
  • Green pin → Pin 0
  • GND pin → GND

Make sure the metal teeth of each crocodile clip are gripping the silver pin pads on the micro:bit firmly — not the plastic edge.

Coding part

Open makecode.microbit.org and create a new project. Here is how the code is structured: Place a forever block from the Basic menu – this makes your code loop continuously, just like a real traffic light that never stops. Inside the forever block, build three phases:

Green phase:

digital write pin P0 to 1
digital write pin P1 to 0
digital write pin P2 to 0
pause 3000 ms

Yellow phase:

digital write pin P0 to 0
digital write pin P1 to 1
digital write pin P2 to 0
pause 1500 ms

Red phase:

digital write pin P0 to 0
digital write pin P1 to 0
digital write pin P2 to 1
pause 3000 ms

You can do the project EVEN IF YOU DON’T HAVE THE TRAFFIC LIGHT MODULE. Yes, yes you can. Just buy 3 LEDs – a red one, a yellow one, and a green one and connect them the same way you would connect the traffic module. Only difference is that you will need to connect each minus (the short one) leg of the 3 LEDs to the GND of the microbit.

Last thing you will need is a way to use the project and have fun with it 😊 Either try it out in class with your students, or at home with your kids! I used my bluetooth controllable mini cars from the Shell gas station, that’s the new BMW collection (new for 2022 at least). I then used colorful tape to trace some race tracks on the floor, and I made a great race track, using the microbit traffic light at the center. It was lots and lots of fun!

My Shell x BMW bluetooth cars 😊 I also have the Ferraris from the previous collection

I hope you liked my little project. Try it out and don’t forget to message me if you do and give me feedback. I would love to hear all about it! DM me on Instagram, click here to go to my account :)

The racing track I created using some colorful tape

If you want a complete ready-to-teach version of this project (with 3 LEDs, not with the module, but it is very similar) for your classroom, I have created a full TPT resource that covers everything – wiring diagrams, step-by-step coding instructions, 6 progressive coding tasks, a creative cardboard build section, answer keys, teacher notes with standards alignment, and a full troubleshooting guide. It is designed to be projected directly in class so students can follow along while building at their desks. You can find it here, click this link to the resource.

One comment

Leave a Reply