Home · Academy · Robotics & Coding · micro:bit · Radio Communication

Radio Communication

Learn to send messages and numbers between two micro:bits over radio.

LESSON COMPASS

What will you use this page for?

Core idea

Two micro:bits can send each other messages and numbers over radio waves with no cable at all, and in this lesson we build a small system where pressing a button on one board makes an icon appear on the other.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

Setting the groups differently This is the most common mistake. If one board is on group 7 and the other on group 1, the message never arrives. Always make sure both boards are set to the same group number in "on start". Forgetting to turn the radio on (MicroPython) In Python, if you do not write radio.on() , the…

Next connection

Pins and External Components: Using the pins on the edge of the micro:bit to connect to the outside world, building small circuits with buttons, LEDs, and crocodile-clip wires.

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration30–45 min
PrerequisiteMeasuring Temperature and Light
ContentStandard lesson · 1,489 words
Last updated

One-sentence summary

Two micro:bits can send each other messages and numbers over radio waves with no cable at all, and in this lesson we build a small system where pressing a button on one board makes an icon appear on the other.

Why does it matter?

Every program you have written so far ran on a single micro:bit. The board read its own buttons and wrote to its own screen. But most real devices do not work alone. A phone talks to a cell tower, a remote talks to a toy car, a weather station talks to the display indoors.

Inside the micro:bit there is a small radio. A radio is a component that lets a board send and receive messages without any wire. When you set two boards to the same group, one can hear the other.

This lets you build your first system where more than one device works together: a wireless doorbell, a signal between two players, or a tiny network that carries temperature from one room to another.

How does the radio work?

The idea of a group

In a classroom, ten micro:bits might all be sending messages at once. So how does your board know which one to listen to? The radio group solves this.

A radio group is a number between 0 and 255. Only boards in the same group hear each other. Messages from other groups are ignored. Think of it like a walkie-talkie channel: if two people want to talk, they must switch to the same channel.

Short definition: A radio group is a channel number that lets micro:bits sharing the same number hear one another.

If you and your friend set your boards to group 7, the group 3 boards at the next desk will not receive your messages. This prevents confusion in a crowded classroom.

The send and receive events

Radio has two basic jobs:

To receive, instead of waiting inside "forever" we use an event. The "on radio received" event runs at the exact moment a message arrives. That way the board does not waste time waiting; it reacts when the message comes.

Example 1: Press a button, a heart appears over there

Goal: When you press button A on board A, a heart icon appears on the screen of board B.

MakeCode block sequence (sending board)

on start
  set radio group to 7
forever
  if <button A is pressed> then
    radio send number 1

MakeCode block sequence (receiving board)

on start
  set radio group to 7
on radio received (receivedNumber)
  if <receivedNumber = 1> then
    show icon heart
    pause 500 ms
    clear screen

Notice that both boards are set to group 7. The sending board sends the number "1". The receiving board shows the heart if the number it gets is 1. You can flash each board with a separate program, or put both the sending and receiving blocks together in a single program.

The same idea in MicroPython

Sending board:

from microbit import *
import radio

radio.on()
radio.config(group=7)

while True:
    if button_a.was_pressed():
        radio.send("1")

Receiving board:

from microbit import *
import radio

radio.on()
radio.config(group=7)

while True:
    message = radio.receive()
    if message == "1":
        display.show(Image.HEART)
        sleep(500)
        display.clear()

Blocks and Python look different, but the logic is the same: same group, send, receive, compare, show.

Example 2: A two-way signal

Now let both boards send and receive. Pressing button A on board A shows an up arrow on board B; pressing button B on board B shows a down arrow on board A.

A single program flashed onto both boards:

on start
  set radio group to 3
forever
  if <button A is pressed> then
    radio send string "up"
  if <button B is pressed> then
    radio send string "down"
on radio received (message)
  if <message = "up"> then
    show arrow up
  else if <message = "down"> then
    show arrow down

Here one file runs on both boards. A message sent by one board is received and shown by the other as an arrow. Systems that work this way are called peer to peer: both can speak and both can listen.

Two everyday examples:

Mini practice

Build a wireless rock-paper-scissors signal with a friend.

Task:

  1. Set both micro:bits to the same group (for example, group 12).
  2. When A is pressed, send the text "rock" and show R on your own screen.
  3. When B is pressed, send the text "paper" and show P on your own screen.
  4. When a radio string arrives, show the received choice on screen for a short time.

Starting block:

on start
  set radio group to 12
forever
  if <button A is pressed> then
    show string "R"
    radio send string "rock"

Ask yourself:

Common mistakes

Setting the groups differently

This is the most common mistake. If one board is on group 7 and the other on group 1, the message never arrives. Always make sure both boards are set to the same group number in "on start".

Forgetting to turn the radio on (MicroPython)

In Python, if you do not write radio.on(), the radio stays off and nothing is sent. In MakeCode, using a radio block turns it on automatically; in Python, turning it on is up to you.

Mixing up numbers and text

A message sent with radio send number is only caught by "on radio received (number)", while radio send string is caught by "on radio received (string)". The type you send must match the type you receive.

Never clearing the screen

If you show the heart but never clear the screen, the old image stays when the next message arrives and things get confusing. Adding clear screen after a short pause fixes it.

Safety note

Lesson summary

Check questions

  1. What does the radio group do, and what number range does it use?
  2. Which setting must be the same for two micro:bits to hear each other?
  3. Why is using the "on radio received" event better than waiting inside "forever"?
  4. Which block receives a message sent with radio send number 1?
  5. In MicroPython, which command must you call before using the radio?

Answers

  1. The radio group is a channel number that decides which boards hear each other; it ranges from 0 to 255. Only boards in the same group receive each other's messages.
  2. The radio group number must be the same. Boards in different groups do not hear each other.
  3. The event runs only at the moment a message arrives; instead of waiting for nothing, the board reacts as soon as a message comes. This keeps the code tidier and more efficient.
  4. You receive it with the "on radio received (number)" block. A message sent as a number is only caught by the number-receiving block.
  5. You must call radio.on(). You also set the group with radio.config(group=...).

Source and verification note

For “Radio Communication”, verification focuses on whether the relationship between How does the radio work? and The send and receive events remains consistent across examples. MakeCode and MicroPython names can vary slightly by version. Test in the simulator first; when external components are connected, check the board’s pin and voltage limits separately.

Next lesson

Pins and External Components: Using the pins on the edge of the micro:bit to connect to the outside world, building small circuits with buttons, LEDs, and crocodile-clip wires.

Start QuizBack to micro:bit
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.