Microbit
Beginner
40 mins
Teacher/Student led
+120 XP
Pupils work on their own device

Connecting Two Micro:bits with Radio

Students program two micro:bits to send and receive string, number and name-value messages over radio, then discuss how the devices cooperate and one data-privacy issue with logging readings about people.

Teacher Class Feed

Load previous activity

    1 - Start: What We're Building ~4 mins

    Illustration for Start: what we're buildingYou can already work with micro:bit inputs and the display. Today you will connect two micro:bits with radio so one can send a message and the other can show it.

    You will start a new project in the MakeCode editor and build it up in stages at your own device: think first about what should happen, then build it, run it and fix whatever does not work.

    2 - How Two Micro:bits Find Each Other ~3 mins

    Two micro:bits can only hear each other if they are on the same radio group. A radio group is just a number, and it works like a channel: set both to 1 and they talk; leave one on a different number and nothing arrives, with no error to tell you why.

    That is the first thing to get right and the first thing to check when a message does not turn up. Today one micro:bit sends and the other shows what it receives: first a message, then a number, then a name and a value together.


    3 - Create a New Project ~2 mins

    Go to the https://makecode.microbit.org website and create a new project.

    4 - Choose a Radio Group ~4 mins

    The first thing we need to do is set the radio group that our micro:bits will be broadcasting on. A radio group is the channel that the Microbit both sends its messages and listens for other messages. A Microbit can only send or receive in one group at a time.

    A Microbit that is on radio group 2 will not be able to receive a message from another Microbit that is on radio group 3. However, if they are both on radio group 3, they can communicate with each other.

    Add the following code to set the radio group to 1.

    radio.setGroup(1)

    5 - Send a Message ~3 mins

    We can send different types of messages, we can send:

    1. A string (text) message.
    2. A number message.
    3. A name and value message.

    Let's start off by sending a string message. Add the following code to send the message "Hello" when you press the A button.

    input.onButtonPressed(Button.A, function () {
        radio.sendString("Hello")
    })
    123learn · Online learning platform

    Unlock the full learning experience

    You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2026. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more