micro:bit MakeCode Tutorials: Project 5 of 5

ages 11+ ages 7+ ages 8+ ages 9+ BBC micro:bit BBC microbit BBC microbit v2 Classroom coding digital technologies display educational electronics light sensors makecode microbit tutorials wireless

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.
    MakeCode microbit block code to set the radio channel variable to 0 when the microbit starts

  • We will use the A and B buttons on our micro:bit to change the channel between 0 and 4 (because the LED display on our micro:bit is only 5 LEDs wide)
    MakeCode microbit block code to increment or decrement the channel variable when the B or A buttons are pressed, respectively

  • Now we can write our main loop. To let us recognise our brightness and temperature data, we can send a name with each, too.
    MakeCode microbit block code to set radio channel using the channel variable and display a graph of received data

    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 between 0 and 4 using the A and Bbuttons 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 a screen variable to let us select between displaying the brightness or the temperature information. We also want to use a forever loop to set the radio to match the channel number we used on the sending micro:bit, once our code is running.
    MakeCode microbit block code to set channel and screen variables when the microbit starts and plot data on the LED matrix

  • We can reuse the same controls as we used on our sender micro:bit, to change the radio channel using the A and B buttons.
    MakeCode microbit block code to change the channel variable when the A or B buttons are pressed individually

  • 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 and B buttons have both been pushed at the same time.
    MakeCode microbit block code to change the screen variable when both the A and B buttons are pressed simultaneously

  • Finally, for the radio channel we select, we will either:

    • Show a graph of the brightness; or
    • Display the temperature

    MakeCode microbit block code to receive radio data and store it in a variable and display selected information on the LED matrix

    Here is the complete code for the receiving micro:bit so you can check your work:
    The complete MakeCode microbit block code for Project 5

    Save this onto your receiving micro:bit by attaching the USB lead to your computer and downloading your .hex file to the MICROBIT 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:

    microbit screen instructions for project 5

    You can change the radio channel using the A and B buttons separately and change between brightness and temperature display but pressing both the A and B buttons together.

Creative Commons Licence
This tutorial is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Older Post Newer Post