Someone has been stealing my sandwiches. We'll use the two-way radio communication on the micro:bit to catch the thief.
Last time, we made a simple temperature gauge using the micro:bit and a servo. Now, we get a little more advanced as we examine two-way radio communication between micro:bits. The good news is that wireless communication is extremely simple using MakeCode.
To have two micro:bits talk to each other over the Bluetooth Low Energy (BLE) radio, you just need to assign a
Group Number in code and then use the
Radio Send String or
Radio Send Value to transmit a message. The receiving micro:bit will call code under the
On Radio Received block to do something with that message.
In the video, I first show how to create one program that gets uploaded to two different micro:bits. This simple app can be used to send the string “Yes” or “No” to the other micro:bit. In the second part of the episode, I show how to create a remote sensor that detects light before sending out a message on the BLE channel. The receiving micro:bit displays a static image and plays a simple tune on a tiny speaker whenever it receives that message.
Here is the messenger app. Upload it to two different micro:bits to try sending strings back and forth:
That concludes my “Getting Started with the micro:bit” series (at least for now). Hopefully, these tips and examples have helped you get an idea of how block programming can work with the micro:bit. What other things would you like to do or see done with the micro:bit? Please share your thoughts in the comments below.