top of page
Search

micro:bit Radio Project: Build a Two-Player Reaction Game (MicroPython)

Nov 10
4 min read

A great first micro:bit radio project is a two-player reaction game: two micro:bits talk to each other over their built-in radio, a heart appears after a random wait, and whoever presses button B first wins. It takes about an hour, needs no wiring, and teaches three big ideas at once: wireless messages, random numbers and fair game rules. Below you'll find the full MicroPython code (tested), how it works, and ideas to make it your own.

What you need

  • Two BBC micro:bit boards (V1 or V2 both work), each with a USB cable and battery pack. If you don't own any yet, our kit guide explains which boards and starter kits our coaches recommend.

  • A computer with the free micro:bit Python Editor (python.microbit.org) to flash the code.

  • Two players, ideally sitting a few feet apart so nobody can see the other's hands.

No sensors or wires are needed. The radio is built into every micro:bit.

How micro:bit radio works (the simple version)

Each micro:bit can send and receive short text messages to any other micro:bit nearby. Think of it like walkie-talkies:

  • Channel (group): radio.config(group=7) puts both boards on the same "channel." Boards on other groups ignore your messages, which matters in a classroom full of micro:bits.

  • Send: radio.send("WIN") broadcasts a short string to everyone in the group.

  • Receive: radio.receive() returns the oldest message waiting, or None if nothing has arrived. Your program has to keep checking it in a loop.

Messages are small (up to 32 characters by default), and once in a while one can get lost, so good radio programs keep messages short and simple.

The game rules

  1. Either player presses button A to start a round.

  2. That board picks a random wait between 1 and 4 seconds and radios it to the other board, so both wait the same amount of time.

  3. When the wait ends, both screens show a heart. First to press button B wins and sees a happy face; the other board gets a sad face.

  4. Press B before the heart appears and it's a false start: you lose that round.

The full MicroPython code

Flash this same program onto both micro:bits. We ran it in a simulator with stubbed micro:bit and radio modules to check every case: a normal win, a normal loss, a false start by you and a false start by your opponent.

from microbit import display, button_a, button_b, Image, sleep
import radio
import random

radio.on()
radio.config(group=7)   # both boards must use the same group number

def play_round(delay_ms):
    display.clear()
    button_b.was_pressed()          # forget any old button presses
    waited = 0
    # Phase 1: wait. Pressing B now is a false start.
    while waited < delay_ms:
        if radio.receive() == "EARLY":
            display.show(Image.HAPPY)   # the other player jumped early
            return
        if button_b.was_pressed():
            radio.send("EARLY")
            display.show(Image.SAD)
            return
        sleep(10)
        waited += 10
    # Phase 2: GO! First to press B wins.
    display.show(Image.HEART)
    while True:
        if radio.receive() == "WIN":
            display.show(Image.SAD)
            return
        if button_b.was_pressed():
            radio.send("WIN")
            display.show(Image.HAPPY)
            return
        sleep(5)

display.show(Image.YES)
while True:
    if button_a.was_pressed():
        delay = random.randint(1000, 4000)
        radio.send("START:" + str(delay))
        play_round(delay)
    msg = radio.receive()
    if msg and msg.startswith("START:"):
        play_round(int(msg[6:]))
    sleep(20)

How the code works

  • Sharing the random wait: the starting board sends "START:2350" (for example). The other board slices off the number with msg[6:] and turns it into an integer, so both boards count the same delay.

  • Two phases: play_round() first waits in small 10 ms steps, checking for a false start, then shows the heart and waits for the first press of B.

  • Telling the other board: the winner sends "WIN" and a false-starter sends "EARLY," so the other screen can update right away.

  • Clearing old presses: button_b.was_pressed() remembers presses from earlier, so we call it once at the start of each round to throw away stale presses.

One honest limitation: if both players press within a few milliseconds of each other, both boards may show a happy face, because each sent "WIN" before hearing the other. That's a fun thing to discuss with kids. How would you build a fair referee? (One answer: a third micro:bit that only judges.)

Ideas to level it up

  • Keep score: add a variable that counts wins and scroll it with display.scroll() after each round.

  • Add sound on a micro:bit V2 with the music module for the countdown and the win.

  • Make it a best-of-five match and show the champion at the end.

  • Change the group number for each pair of players so a whole class can play at once without interference.

If your child enjoyed this, our micro:bit step counter project uses the accelerometer next, and the motion-sensing light-up pumpkin is another quick weekend build.

Common questions

Do I need two micro:bits for a radio project?

Yes. Radio needs at least one sender and one receiver. Many families pair up with a friend or classmate who has a board.

Can a micro:bit V1 talk to a V2?

Yes. The radio works between V1 and V2 boards as long as both use the same group and the same code.

What age is this project good for?

Kids around 9–14 who have tried a little block coding can follow it with some help. Younger kids can build the same game in MakeCode blocks first.

Keep learning with Fusion Robotics Education

Want a guided path? Start with our free Robotics Explorers micro:bit course, then move to Advanced micro:bit. Browse the full catalog of online courses, try All-Access free for 7 days ($39/month after), or book Remote 1-on-1 live lessons ($149/month) by texting (619) 786-5731.

Live in San Diego? Our weekend group sessions in Scripps Ranch are 1.5 hours a week for ages 6–18, with at most 10 kids and every child working on their own project. See the program and text (619) 786-5731 to book a free first session.

 
 
 

Comments


bottom of page