micro:bit MakeCode Tutorials: Project 4 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 4: Remote Brightness Monitor

Did you know that we can use the lights on the front of the micro:bit, to measure brightness in the room? This project will use two (2) micro:bits: one to measure brightness and send it over radio, and another to receive and display the brightness levels. To understand the radio functions better, you should first have completed Project 3: Radio Talk. If you haven’t, that’s OK too, since this project will take you through the steps required.

In this project, you will learn:

  • How to measure light using the micro:bit’s built-in sensor
  • How to send our light information to another micro:bit, wirelessly

You will need:

  • One of more micro:bits (V1 or V2 is fine) and at least one matching USB cable
  • A computer with an Internet connection and a modern web browser

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

  • on the first micro:bit, you’ll need to set the radi ochannel to be group 1.
    MakeCode microbit block code to set the radio group to 1 when the microbit starts

  • Now, in the main forever loop, we’ll get the light level and display it in a graph, then send the light information to our other micro:bit using radio.
    MakeCode microbit block code to plot a bar graph of the light level and send it over radio

    Save this onto the micro:bit by attaching the USB lead to your computer and downloading the .hex file to the MICROBIT device. Ask for help if you don’t remember how to do this.

    You should see a dot at the bottom of the micro:bit light matrix. Hold it up to the light, and you should see a graph growing from the bottom of the matrix display.

Step 3: The receiving micro:bit’s code

  • This code will go onto the second micro:bit. Plug the second micro:bit into your computer and start a new project.
  • Drag the following code into your new project - it’s just a variation on our previous code.
    MakeCode microbit block code to set the radio group to 1 and receive light data over radio

    Save this onot the second micro:bit by attaching the USB lead to your computer and downloading the .hex file to the MICROBIT device.

    Now, when the first micro:bit is exposed top light, the graph should show up on the second micro:bit as well. Try this from another room, and seeif you can tell whether the first room is light or dark. As the LED that we are using for light detection is not as sensitive as a specialised sensor, it may take more light to notice a difference in your graph.

Challenge

Can you set this project up to use two micro:bits as light detectors, each on a separate radio group, and swap between monitoring each one?

 

Continue to the next project in this series here..

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

Older Post Newer Post