Lesson at a glance
maze.education/microbit/lessons/data-logger
- Grades
- Grades 7 to 9
- Time
- 45 to 60 minutesThe CAPS gives Coding and Robotics 2 hours a week (Coding and Robotics CAPS, Grades 7 to 9, page 22).
- Level
- Confident codersFor confident classes: more steps to build, with variables, radio or data.
- Board
- micro:bit V2 onlyThis lesson needs a micro:bit V2, for its data logging.
- Code with
- MakeCode blocks, with Python as an extension
- CAPS
- Mathematics, Natural Sciences, Coding and RoboticsFits: Grade 9, Term 2 · Where it fits
Learning intentions
Learners will learn to:
- Program the micro:bit V2 to log sensor readings at a fixed interval.
- Open the logged data, and represent it on a line graph.
- Describe a trend in the data and suggest a reason for it.
Success criteria
Each learner can say:
- I can program the micro:bit V2 to log three readings every ten seconds.
- I can open MY_DATA and draw a line graph of one column against time.
- I can describe the trend in my graph and give a reason for it.
Competencies
From the Coding and Robotics CAPS places this lesson cites.
- D.1Outline the concept of technology and purpose of information technology (IT)
- D.7Present a basic understanding of the concept of input processing and output
Key words
- data logger
- A device that records measurements by itself, at set times.
- interval
- The time between two measurements.
- timestamp
- The time each row of data was recorded.
- trend
- The general direction data moves in over time.
- CSV
- A plain table file that spreadsheets can open.
- trace table
- A table that follows the value of each variable, step by step, as a program runs.
What you need
- A micro:bit V2 per group (data logging needs a V2), with a USB cable and a battery holder
- A computer with Chrome or Edge, and a spreadsheet program or graph paper
- A place to log: a sunny windowsill, the corridor, the classroom during a lesson
From our shop: BBC micro:bit V2 Go, BBC micro:bit V2.21 Next Gen Classroom Pack
Safety
- Leave logging boards where they cannot fall, get wet or be knocked, and never in direct sun inside a closed car or box.
- Use the battery holder with two AAA batteries. Never mix old and new batteries, and take the batteries out before the kits are packed away.
- Unplug the battery holder by holding its plug, never by pulling the wires.
The lesson plan
One lesson of 45 to 60 minutes in three parts: introduction, lesson development and consolidation. The CAPS gives Coding and Robotics 2 hours a week, so it fits one of the week's lessons. Times are a guide.
Introduction
5 to 10 minutesRetrieval practiceWhen is a line graph better than a bar graph? (A line graph shows how something changes over time; a bar graph compares separate groups.)
Problem statementSome classrooms get uncomfortably hot by the afternoon, and the school wants evidence before it spends money on blinds or fans. Program a data logger that records temperature, light and sound every ten seconds, and use its graph to describe what happens.
- Show a weather graph of a day's temperatures. Ask: who measured all these? Usually a machine did: a data logger.
- Read the problem statement. Ask: what would you measure to find out when a classroom is hottest, and for how long?
Lesson development
35 to 40 minutes- Unplugged first. Learners log by hand for three minutes: every 30 seconds, one learner rates how bright it is outside the window from 1 (dull) to 5 (bright sun), and another writes the time and the rating in a table. Discuss how boring and error-prone this gets.
- Plan on paper first. Groups write the logger's algorithm, then complete the trace table: the value of logging, and whether a row is added, at each moment of a test run.
- Predict. Before logging, each group sketches the graph they expect for their chosen place: will the line go up, go down or stay flat?
- Build in blocks. Each group has one computer and one micro:bit V2. Two learners build at a time: the driver adds the datalogger extension and builds the logger from the Blocks tab; the navigator checks each block against the algorithm. Swap roles halfway, at the every 500 ms loop, so two others take over. Download it to the micro:bit V2.
- Test and debug. Press A and check the tick; press B and check the cross. Then log for real: press A, leave the board in your chosen place on batteries for at least 15 minutes, and press B. If MY_DATA is empty afterwards, check the program against the trace table: logging must be true while the every loop runs.
- Plug the micro:bit into the computer, open the MICROBIT drive and double-click MY_DATA. Your data opens as a table in the browser. Use its visual preview, or download it and open it in a spreadsheet. Draw or make a line graph of one column against time, and describe the trend.
Plan on paper: a model answer
In groups, write the logger's algorithm, then complete the trace table for a test run.
Algorithm
- Set up three columns: temperature, light and sound.
- When A is pressed, set logging to true and show a tick.
- When B is pressed, set logging to false and show a cross.
- Every 10 seconds: if logging is true, add a row with the temperature, the light level and the sound level.
Trace table
A test run: the board starts at 0 seconds, A is pressed straight away and B is pressed at 35 seconds. Time (s) Event logging Row added? 0 A pressed true No 10 Every 10 seconds true Yes, row 1 20 Every 10 seconds true Yes, row 2 30 Every 10 seconds true Yes, row 3 35 B pressed false No 40 Every 10 seconds false No Consolidation
5 to 10 minutes- Groups show their graphs. Did the data match the graph they predicted?
- Ask: why is a data logger better than a person for measuring all day?
- Back to the problem: does your graph give the school evidence about heat? What would you measure next, and for how long? Then ask: what should we do before the next class uses the board? (Delete the log, so the data does not mix.)
Build it, step by step
Pairs build the program in blocks, following the numbered steps, with the same program as text beside them to check against or paste. Test in the simulator before sending it to a board.
These are the MakeCode steps. The other routes are on the lesson's web page.
Build it in MakeCode blocks
- Start a New Project. Click Extensions (under Advanced), search for datalogger and add it. A Data Logger drawer appears.
- From Data Logger, drag set columns into on start and type temperature, then use the plus sign to add light and sound.
- Make a variable called logging. Add on button A pressed: set logging to true (from Logic) and show icon tick. Add on button B pressed: set logging to false and show icon cross.
- From Loops, drag in every 500 ms and change it to 10000 (ten seconds).
- Inside it, add if logging, then log data from Data Logger with three columns: temperature with temperature (°C), light with light level and sound with sound level, all from Input.
- Download to a micro:bit V2.
let logging = false
input.onButtonPressed(Button.A, function () {
logging = true
basic.showIcon(IconNames.Yes)
})
input.onButtonPressed(Button.B, function () {
logging = false
basic.showIcon(IconNames.No)
})
loops.everyInterval(10000, function () {
if (logging) {
datalogger.log(
datalogger.createCV("temperature", input.temperature()),
datalogger.createCV("light", input.lightLevel()),
datalogger.createCV("sound", input.soundLevel())
)
}
})
datalogger.setColumnTitles(
"temperature",
"light",
"sound"
)To use the text instead: open MakeCode, start a new project, click JavaScript at the top, replace what is there with this code, then click Blocks to see it as blocks.
To send it to the board, click Download. In Chrome or Edge, MakeCode can connect to the micro:bit by USB so the program goes straight onto it. Otherwise a .hex file downloads: drag it onto the MICROBIT drive.
No Purple Mash route for this lesson
We could not find a Purple Mash unit or project that matches this lesson, so it is MakeCode blocks, with Python as an extension. These lessons have a Purple Mash route:
Extension: text-based coding, beyond the CAPS
The same program in MicroPython, for the micro:bit Python Editor. It suits Grade 7 to 9 learners who are ready for text-based code. The CAPS itself follows a block-based approach (Coding and Robotics CAPS, Grades 7 to 9, page 24).
# Data logger: A starts logging temperature, light and sound every ten seconds, B stops it (micro:bit V2).
from microbit import *
import log
log.set_labels("temperature", "light", "sound", timestamp=log.SECONDS)
logging = False
@run_every(s=10)
def record():
if logging:
log.add({
"temperature": temperature(),
"light": display.read_light_level(),
"sound": microphone.sound_level()
})
while True:
if button_a.was_pressed():
logging = True
display.show(Image.YES)
if button_b.was_pressed():
logging = False
display.show(Image.NO)
sleep(100)run_every runs the record function every ten seconds while the main loop watches the buttons. Both need a micro:bit V2.
Open the Python editor, replace the code that is there with this program (or open the downloaded file), then click Send to micro:bit. MakeCode also has a Python view, which is written a little differently.
Extension or homework
Challenges for learners who finish early, or to take further in a club or as homework.
- Challenge 1
Graph the sound of a whole lesson and look for patterns in the How loud is our classroom? A sound graph lesson.
- Challenge 2
Put two loggers in different places, such as a sunny and a shady window, and compare the two graphs.
- Challenge 3
Log the temperature inside a lunch box with a frozen bottle of water, and work out how long food stays cold.
Support and extension
Support
For learners who need more help
- Log one column only, temperature, and graph it together on the board.
- Give learners a graph with the axes already drawn and labelled.
Extension
For learners who are ready for more
- Log every minute for a whole school day and compare the morning with the afternoon.
- Find the mean, the median and the range of each column in a spreadsheet, and write a short report.
Informal assessment
Ask these as learners work. Informal assessment happens every day and is not recorded.
- What does the interval of 10000 milliseconds mean?
- Why does the log need a timestamp?
- Describe the trend in your graph in one sentence.
Give one reason your readings might not be accurate.
Observation checklist
Watch pairs as they plan, build and test. Write each pair's initials under the level you see.
| Watch for | Beginning | Developing | Accomplished | Exemplary |
|---|---|---|---|---|
| Writes the algorithm and completes the trace table before building. | ||||
| Builds the logger so that it records only while logging is true. | ||||
| Predicts the shape of the graph, then compares it with the data. | ||||
| Describes a trend with a reason, using the graph as evidence. |
- Beginning:
- not yet, even with help
- Developing:
- with help
- Accomplished:
- on their own
- Exemplary:
- on their own, and explains it or takes it further
The four levels are the CAPS rubric levels (Coding and Robotics CAPS, Grades 7 to 9, page 163). The short descriptions are ours.
This lesson is not a formal task, but it is good practice for the mini-PATs in Grades 7 to 9 (Coding and Robotics CAPS, Grades 7 to 9, page 157).
Common mistakes and fixes
- There is no Data Logger drawer.Add the extension: Extensions, search datalogger, then click it.
- MY_DATA is empty.Press A to start logging, and leave the board for at least a minute before pressing B.
- Nothing is logged on our board.Data logging needs a micro:bit V2. Check for the gold touch logo on the front.
Where it sits in CAPS
- Coding and RoboticsFitsGrade 9, Term 2: record sensor readings on the micro:bit at short intervals, then show them.Source: Coding and Robotics CAPS, Grades 7 to 9, Grade 9, Term 2, Digital Concepts, D.7 Present a basic understanding of the concept of input processing and output, page 145:
Micro: bit Application using accelerometer readings in an array (list) in short intervals.
- Coding and RoboticsFitsGrade 7, Term 3: charts and graphs make data easier to understand.Source: Coding and Robotics CAPS, Grades 7 to 9, Grade 7, Term 3, Digital Concepts, D.1 Outline the concept of technology and purpose of information technology (IT), page 81:
IT experts create charts and graphs to help
- MathematicsGrades 7 to 9 Mathematics: drawing graphs by hand or with technology, and interpreting them.Source: CAPS Mathematics, Grades 7 to 9, Section 2, topic 5.2 Represent data (Grades 7, 8 and 9):
Draw a variety of graphs by hand/technology to display and interpret data
- Natural SciencesFits Natural Sciences: an investigation that collects measurements over time.
Coding and Robotics quotes come from the Department of Basic Education's final CAPS, with the page number of the 2024 printed edition (the Department's October 2025 library copies number their pages differently). Schools may teach a topic in another term: the CAPS leaves the order to each school's annual teaching plan.
micro:bit is a trade mark of the Micro:bit Educational Foundation, and BBC is a trade mark of the British Broadcasting Corporation. Maze Education is an independent reseller of genuine BBC micro:bit products. Our teacher training and our other products and services are our own, and are not endorsed by the Foundation or the BBC.

