This is a series of projects that grew from an introductory set of group workshops that we wrote for a local school's open day to promote their Code Club. Projects 1 to 3 ran for about 20 minutes each, and projects 4 and 5 became workshops at the Code Club where I volunteer (these can each be completed within an hour). These projects were easily completed by kids from ages 7-11. The projects that use multiple micro:bits are scaleable and can work well with any number of micro:bits from 2 to class sets; with the option for kids to collaborate in pairs or larger groups.
Project 5: Send Temperature and Brightness Data From Up To Five micro:bits
This project is an extension of project 4, except that we will use more than one micro:bit to send data about light and temperature levels. We can get the temperature of a micro:bit’s central processing unitl (CPU) - think of this as the micro:bit’s brain. The CPU temperature can give us a rough idea of the temperature near the micro:bit. We will add temperature to our previous project 4, to allow us to measure both light and temperature on the same device.
To let us send brightness and temperature data from more than one micro:bit, we will use the A and B buttons to change the radio channel. Finally, we will learn how to display the data on the receiving micro:bit.
In this project, you will learn:
- How to wirelessly use one micro:bit to access data collected from multiple micro:bits in real time.
You will need:
- Two or more micro:bits (V1 or V2 is fine) and matching USB cables
- One or more computers with an Internet connection and a modern web browser
- To have previously completed Project 4: Remote Brightness Monitor
This is a great project for groups of kids working in pairs to coordinate
Step 1: Launch your browser, and got to the MakeCode website
- Launch your web browser by clicking on its icon
- Once your web browser loads, click in the address bar at the top and, in the address bar, type in:
https://makecode.microbit.org
Step 2: Write your code for the ‘sender’ micro:bit
-
Plug the micro:bit that you will be using to send light and temperature data, into your computer’s USB port, using the USB cable. Since we want to be able to easily change our radio channel, we’ll store our channel in a variable called `channel’. Note that we are not yet setting our radio channel, only creating a variable to store it.
-
We will use the
A
andB
buttons on our micro:bit to change the channel between0
and4
(because the LED display on our micro:bit is only 5 LEDs wide) -
Now we can write our main loop. To let us recognise our brightness and temperature data, we can send a name with each, too.
Save this onto the mciro:bit by attaching the USB lead to your computer and downloading the.hex
file onto the MICROBIT device. Ask for help if you don’t remember how to do this.
Once your program is downloaded and starts running on the micro:bit, you’ll see a blinking light, which tells us that our micro:bit is sending data over radio. We can set the channel between0
and4
using theA
andB
buttons to change the numbers up and down, respectively. The position of the light on the micro:bit LED display tells us which channel we are sending on - we can put this code onto more than one micro:bit as long as we set a different channel for each. This means we can have multiple sets of micro:bits communicating other micro:bits on their own radio channels. But first, we need to write some code for another micro:bit to receive our radio messages.
Step 3: Write your code for the receiving micro:bit
-
Remove the sender micro:bit and attach the receiving micro:bit. We’ll create a
channel
variable again, and also create ascreen
variable to let us select between displaying the brightness or the temperature information. We also want to use aforever
loop to set the radio to match the channel number we used on the sending micro:bit, once our code is running. -
We can reuse the same controls as we used on our sender micro:bit, to change the radio channel using the
A
andB
buttons. -
Because we want to be able to receive radio data from more than one micro:bit, we also need another control to change radio channels: since we only have two buttons, this control will be activated when we detect that the
A
andB
buttons have both been pushed at the same time. -
Finally, for the radio channel we select, we will either:
- Show a graph of the brightness; or
- Display the temperature
Here is the complete code for the receiving micro:bit so you can check your work:Save this onto your receiving micro:bit by attaching the USB lead to your computer and downloading your
.hex
file to theMICROBIT
device. -
Power on the sender micro:bit(s) and set each to a different channel using the A and B buttons.
Here’s how the display on our receiving micro:bit works:
You can change the radio channel using the
A
andB
buttons separately and change between brightness and temperature display but pressing both theA
andB
buttons together.
This tutorial is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.