Skip to main content

09 April 2022

Visualizing logged data with a micro:bit

CAS logo
Written by

Computing at School

So far these posts have looked at how to measure external factors such as light, temperature and sound (with micro:bit V2). The LEDs have been able to give a numerical value that students can record, then enter into a graphing application such as Excel or Sheets. This process is good practice for students in collecting and recording data and great investigative science, especially for younger students.

The real power of data logging is when the device not only takes measurements, but stores and displays them in real time for instant analysis. Amazingly the micro:bit can do this with two lines of code. The micro:bit V2 has some specialised data logging that offer additional functionality , I will discuss that in a future post. This method will work on both versions.

Firstly you need to connect the micro:bit so that you can directly flash data to it. Details how to do this can be found here – https://youtu.be/qSjMDG84bMY

Next …

Download the following code on to a micro:bit – https://makecode.microbit.org/_eR4KF2MiFA0m 

The plot bar graph block can be found under the LED commands, drag into it the input from a sensor you want to measure. In this case light, enter 255. This represents the maximum value for light, and 50 for temperature. The command then works out the number of LEDs to illuminate to illustrate the proportion of the level value. So a value of 0, dark, shows 1 LED, a maximum value 255, full light is illustrated by all 25 leds being illuminated. Values in between are represented proportionally.

But this command hides a fantastic secret. A clue is given by the ‘Show Console button’. Click this and the simulator will change. By altering the value of the light, by click and dragging over the yellow circle. You will see not only the number of LEDs illuminating changing, but a line trace, plotted in real time. The values are also listed below.

Download this code to a micro:bit via USB. Keep the micro:bit connected to the computer. An extra button will appear, labelled Show Console …. Device. Click this. The screen will now show the data from the sensor on the micro:bit. Try covering and uncovering the LEDs on the micro:bit and see the changes in the line being plotted.

Using the pause button will pause the stream of data so that the line graph can be analysed. The other feature is the download button. This will allow you to download all the data over period measured as a CSV file.

This can then be imported in to your preferred spreadsheet application.

Discussion

Please login to post a comment