Skip to content

Radio Messaging

Level Beginner
Board V1 & V2
Parts 2 × micro:bit

What you'll build

micro:bits can talk to each other wirelessly. Flash the sender onto one micro:bit and the receiver onto a second one. Press button A on the sender and the receiver scrolls the message.

Code

Flash this onto the first micro:bit.

4 radio-sender.py
'''
Example: Radio Messaging example using micro:bit (Sender Side)
By: Meqdad Darwish
'''

# Sender
from microbit import *
import radio
radio.config(group=5)
radio.on()

while True:
    if button_a.is_pressed():
        radio.send('A is pressed')

Flash this onto the second micro:bit.

5 radio-receiver.py
'''
Example: Radio Messaging example using micro:bit (Receiver Side)
By: Meqdad Darwish
'''

# Receiver
from microbit import *
import radio
radio.config(group=5)
radio.on()
while True:
    message = radio.receive()
    if message == 'A is pressed':
        display.scroll(message)

How it works

  • radio.config(group=5) puts both micro:bits on group 5. Only boards in the same group hear each other, so the sender and receiver must match.
  • radio.on() powers up the radio, which is off by default to save battery.
  • radio.send() broadcasts a string to every micro:bit in range on the same group.
  • radio.receive() returns the next queued message as a string, or None if nothing has arrived.

Try this next

  • Send a different message for button B, and show a different image for each one on the receiver.
  • Pick your own group number (0–255) so you don't clash with classmates.
  • Add a short sleep(200) on the sender so holding the button doesn't flood the radio.
  • Reply from the receiver so both boards can chat.
  • Use radio.receive_full() to read the signal strength and estimate distance.