Data logger

The micro:bit V2 records temperature, light and sound every ten seconds; learners open the data as a table, graph it and explain the pattern.

Go to the code ↓

Lesson at a glance

45 to 60 minutes · Grades 7 to 9

maze.education/microbit/lessons/data-logger

Grades
Grades 7 to 9
Time
45 to 60 minutes
The CAPS gives Coding and Robotics 2 hours a week (Coding and Robotics CAPS, Grades 7 to 9, page 22).
Level
Confident coders
For confident classes: more steps to build, with variables, radio or data.
Board
micro:bit V2 only
This 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 Robotics
Fits: Grade 9, Term 2 · Where it fits

Learning intentions

Learners will learn to:

  1. Program the micro:bit V2 to log sensor readings at a fixed interval.
  2. Open the logged data, and represent it on a line graph.
  3. 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.

  1. Introduction

    5 to 10 minutes
    Retrieval practice

    When 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 statement

    Some 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.

    1. Show a weather graph of a day's temperatures. Ask: who measured all these? Usually a machine did: a data logger.
    2. Read the problem statement. Ask: what would you measure to find out when a classroom is hottest, and for how long?
  2. Lesson development

    35 to 40 minutes
    1. 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.
    2. 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.
    3. Predict. Before logging, each group sketches the graph they expect for their chosen place: will the line go up, go down or stay flat?
    4. 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.
    5. 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.
    6. 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
    1. Set up three columns: temperature, light and sound.
    2. When A is pressed, set logging to true and show a tick.
    3. When B is pressed, set logging to false and show a cross.
    4. 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)EventloggingRow added?
    0A pressedtrueNo
    10Every 10 secondstrueYes, row 1
    20Every 10 secondstrueYes, row 2
    30Every 10 secondstrueYes, row 3
    35B pressedfalseNo
    40Every 10 secondsfalseNo
  3. Consolidation

    5 to 10 minutes
    1. Groups show their graphs. Did the data match the graph they predicted?
    2. Ask: why is a data logger better than a person for measuring all day?
    3. 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.

Button A starts logging (tick) and B stops it (cross). Every 10 seconds a new row is added with the time in seconds, temperature in °C, light level 0 to 255 and sound level 0 to 255, saved in MY_DATA.
One row every 10 000 milliseconds: open MY_DATA on the MICROBIT drive to see the table and its visual preview.

These are the MakeCode steps. The other routes are on the lesson's web page.

Build it in MakeCode blocks

  1. Start a New Project. Click Extensions (under Advanced), search for datalogger and add it. A Data Logger drawer appears.
  2. From Data Logger, drag set columns into on start and type temperature, then use the plus sign to add light and sound.
  3. 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.
  4. From Loops, drag in every 500 ms and change it to 10000 (ten seconds).
  5. 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.
  6. Download to a micro:bit V2.
The same blocks as text (to paste into MakeCode)
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.

Extension or homework

Challenges for learners who finish early, or to take further in a club or as homework.

  1. Challenge 1

    Graph the sound of a whole lesson and look for patterns in the How loud is our classroom? A sound graph lesson.

  2. Challenge 2

    Put two loggers in different places, such as a sunny and a shady window, and compare the two graphs.

  3. 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.

  1. What does the interval of 10000 milliseconds mean?
  2. Why does the log need a timestamp?
  3. Describe the trend in your graph in one sentence.
Exit question

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 forBeginningDevelopingAccomplishedExemplary
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

  • Problem: There is no Data Logger drawer.Fix: Add the extension: Extensions, search datalogger, then click it.
  • Problem: MY_DATA is empty.Fix: Press A to start logging, and leave the board for at least a minute before pressing B.
  • Problem: Nothing is logged on our board.Fix: 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 (opens in a new tab), 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 (opens in a new tab), 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 (opens in a new tab), 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.

Ready to teach it?

Get a micro:bit for every learner or pair, and let us train your staff to run lessons like this one.

More lessons

All lessons →
  • Grades 7 to 9

    Grades 7 to 945 to 60 minLevel: Some experience

    Radio messages

    Boards in the same radio group send YES and NO across the room: learners build a wireless system and explore groups.

    Subjects: Technology · Coding and Robotics

    Code with: MakeCodePython

  • Grades 7 to 9

    Grades 7 to 945 to 60 minLevel: Confident coders

    Fall alarm

    The accelerometer senses a fall, or the wearer presses a panic button, and an alarm goes off on a carer's board across the room.

    Subjects: Technology · Coding and Robotics · Natural Sciences

    Code with: MakeCodePython

  • Grades 6 to 9

    Grades 6 to 945 to 60 minLevel: Some experience

    Reaction timer

    Wait for the dot, then press A as fast as you can: learners time their reactions in milliseconds and analyse the class's data.

    Subjects: Mathematics · Coding and Robotics

    Code with: MakeCodePython

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.

WhatsApp