Skip to main content

24 February 2022

Using code to make a simple Micro:bit Datalogger

CAS logo
Written by

Computing at School

Using code to make a simple Micro:bit Datalogger

The previous two posts explored how to use the built-in sensors on the micro:bit to make and display simple measurements such a light and temperature.

This post explores how students can use code to improve their data logger. They will be able to control when to record and display the sensor reading. This makes it easier to record sensor readings in a notebook, table, or spreadsheet.

Using the code commands students will be able to press a button to record and store a measurement, another button to display the measurement, and another to reset the measurement ready to take another.

This is an opportunity (if it has not already been explored), to discuss with students how the micro:bit with only two input buttons can have three inputs. Button A and Button B and pressing them both as A and B forms a third input. Also discuss with the practicality of using the Shake command as an input in this project. Is it a good idea?
In Makecode create the following programme.

For this students will need to create a variable. This a ‘place’ where values can be stored, manipulated and recalled. Create a variable called light ( use a name that is recognisable) . In the Makecode command list, click Variables, then Make a Variable. , name the variable, this will create three new blocks.

 

When the micro:bit is powered up the variable is set to zero.

When button A is pressed, the sensor is read and assigned to the variable’s value. This will not change, even if the sensor reading changes unless button A is pressed again. Add a show icon block to indicate the data has been captured.

Pressing button B displays the captured sensor reading. Students can now easily record this information on a spreadsheet or table.

Pressing A+B sets the variable value back to zero ready for the next reading.

The next post shows how students can automate processes using variables and algorithms in their code.

Download this code here - https://makecode.microbit.org/_TmCH0XUsubye 

 

Discussion

Please login to post a comment

Helen Waring
12/04/2023 11:44

That was fabulous - thank you!

Peter Marshman
06/02/2023 08:13
Helen Waring
03/02/2023 12:14

@pmarshman Do you a hex file for the bird count code you were showing the CAS micro:bit code-along last week (24th Jan)? I have tried to create it mysalf but my limited coding skills are sadly not up to the job!

anon15714985
03/02/2023 08:36

Graham , have a look here for tips on data transfer - Datalogging with the microbit

Also, if you are not keen on soldering, search for cold solder or conductive paint , works a treat

Graham Hastings
03/02/2023 07:52

Yes, data logging would be good. Particularly with tips on file handling and transferring data to a spreadsheet using the V2 micro:bit.
Graham

anon15714985
08/04/2022 13:08

Jo,
I have a load more post to put up. What sort of things would you like to see in a plan? Stuart

Jo Hodge
28/03/2022 09:06

Just wondered if you had formualted into a plan. No problem if not! Thanks!

anon15714985
25/03/2022 14:09

Jo, Thanks… these posts are just my observations and tinkerings. What sort of planning info are you looking for?

Jo Hodge
13/03/2022 10:40

Thanks Stuart - this looks great. Do you have planning for this as this would fit perfectly with out Year 5 classes who currently use data loggers.