Electronics School · Stage 5: Electronics in the Real World · Lesson 30

Data Logging

Recording readings over time, so you can see patterns you’d never notice by watching.

The question

How cold did it really get last night, and at what time?

What you’ll discover: how to record measurements at regular intervals, store them in a file, graph them, and deal with missing or bad readings honestly.

In simple terms

BeginnerA diary for your sensor

A data logger takes a reading, writes it down, waits, and repeats, all by itself. Each reading is a sample, and the time between samples is the interval.

Choosing the interval is a balance. Temperature outdoors changes fairly slowly, so one reading a minute, or even every five minutes, shows the pattern well. A gust of wind lasts only seconds, so wind needs much faster sampling. Sample too slowly and you miss things; sample too fast and you fill your storage with nearly identical numbers.

Storing readings: CSV files

The simplest way to store logged data is a CSV (comma-separated values) file: plain text, one reading per line, with commas between the parts. It opens in any spreadsheet program.

seconds,temp_c
0,4.2
60,4.1
120,3.9

Every reading needs a timestamp: when it was taken. A Pico has no battery-backed clock, so it forgets the date and time when the power goes off. A simple, honest solution is to record the seconds since logging started and write down when you started it.

Go deeper

IntermediateGraphs show the story

Open your CSV in a spreadsheet, select the two columns and insert a line chart, with time across the bottom and temperature up the side. Patterns jump out: the overnight low, the warm-up after sunrise, the sudden jump when a chinook arrives in southern Alberta.

Always label the axes with units, start the graph at a sensible scale, and say where and how the readings were taken. A graph without that information can mislead.

AdvancedMissing and bad readings

Real loggers miss readings: the battery dies, a wire comes loose, the sensor fails. The honest thing to do is leave the gap blank, not fill it with 0 or copy the last value. A 0 °C (32°F) that never happened can be mistaken for a real frost.

Look out for impossible values too. The DS18B20 sensor reports exactly 85.0 °C (185°F) when it has just powered up or a reading didn’t finish properly, so a sudden 85 in a winter log is a glitch, not a heat wave. Good loggers check each reading against sensible limits and mark suspicious ones rather than silently deleting them.

Storage wears out too. A Pico’s flash memory can be rewritten many thousands of times, but writing every second, all day, for months adds up, which is another reason to choose a sensible interval.

Quick check

What is a sample interval?

The time between one reading and the next.

Why shouldn’t you fill a missing reading with 0?

A 0 that never happened can be mistaken for a real reading, like a false frost.

Why does a Pico log usually record seconds since starting, instead of the date and time?

It has no battery-backed clock, so it doesn’t keep the real date and time after power is lost.

Words to know

Sample
One recorded measurement.
Interval
The time between samples.
CSV
Comma-separated values: a simple text format for tables of data.
Timestamp
The recorded time of a reading.

Electronics School is part of the Discovery Zone. Every activity here runs on small batteries or a USB cable: never wall outlets. The one plug-in tool is the optional soldering iron, set up by an adult.

Was this page helpful?
Get all four of our sites in one free email every Friday: Prairie Signals
⇧Top
Hello! “A truly rich person is one whose children run into their arms when their hands are empty.”