Source: https://mokxi.com/learn/arduino-temperature-data-logger
Updated: 2026-10-05

Learn

# An Arduino temperature data logger, as a lab

Beginner

Written by the Mokxi team, updated October 5, 2026

Start building free Open the editor

Or see every lesson.

- 261 parts on the bench
- 31 boards running now
- 1.00x real time, on every board

Click to open it in the editor

An LM35 on A0 prints the temperature once a second. A Hall switch and a slotted wheel share the board.

A data logger reads a sensor again and again and keeps every reading with its time. A temperature logger is one of the most common Arduino labs, because it uses an analog input, timing, serial output and a file, all in one project.

The circuit above has an LM35 temperature sensor on A0 of an Arduino Uno. It prints the temperature on the serial monitor once a second. Drag the slider under the sensor to change the temperature it reads.

This page walks through the lab in five steps, from one reading to a CSV file you can graph. The same steps work for a TMP36, a DHT22 or a DS18B20.

## Step 1: Read the sensor

An LM35 gives 10 mV for each degree Celsius, starting from 0 V at 0 degrees. So 250 mV is 25 degrees. It needs at least 4 V, so power it from 5 V.

analogRead() gives 0 to 1023 for 0 to 5 V. One step is about 4.9 mV, which is about half a degree on an LM35. So the millivolts are the reading times 5000 divided by 1024, and the degrees are the millivolts divided by ten.

The sketch in the project above reads the sensor sixteen times and averages the result. That smooths out the last bit of noise in the reading. It uses whole-number math, so it prints tenths of a degree without floating point.

## Step 2: Add the time

A reading with no time is not a log. The simplest time stamp is millis(), the milliseconds since the board started. Print it before the temperature, with a comma between them.

Use millis() for the timing too, not delay(). Check if 1000 ms have passed since the last reading, and if so, take the next one. The project above does it this way, so the board can do other work between readings.

For the real date and time, add a DS3231 clock module on I2C. RTClib gives you the year, month, day, hour, minute and second. It works here and on a real board.

## Step 3: Save it from the serial plotter

Print one line per reading, like temp:24.5. Then open the Plot tab beside Serial. The plotter draws a curve, and the label goes in the legend.

Press CSV in the plotter. It downloads every point it drew, with one row for each moment and one column for each curve. Open the file in a spreadsheet and make your graph.

This is the quickest way to get data for a lab report. It needs no extra parts.

## Step 4: Save it to an SD card

A real logger has to work with no computer attached. For that, add a microSD card module on SPI. On an Uno, CS goes to pin 4, SCK to 13, MOSI to 11 and MISO to 12.

Open the file with SD.open for appending, print one line, and close it. Close it after each line, so a power cut loses one reading and not the whole file.

In Mokxi, the file shows up beside the card and grows while the sketch runs. Click its name to download it. The SD card tutorial has the full sketch.

## Step 5: Graph it and explain it

Plot time on the x axis and temperature on the y axis, with units. Say how often you took a reading, and why that rate fits what you measured.

A good first test in the simulator: set the slider to 20 degrees, then 30, then 25, about a minute apart. The log should show the same three steps at the right times. If it does not, the bug is in your code, not in the sensor.

Here is the honest limit of a simulated logger. The temperature comes from the slider, so the graph shows that your code works, not how a real room behaves. For real data, build the circuit on a bench and log a real change, like a cup of warm water cooling down.

## Which sensor to use

LM35: 10 mV per degree with no offset. It needs 4 V or more, so it does not suit a 3.3 V board like an ESP32. On one supply it cannot read below 0 degrees.

TMP36: 10 mV per degree with a 500 mV offset, so 750 mV is 25 degrees. It runs from 2.7 V, so it suits 3.3 V boards.

DHT22: temperature and humidity on one digital pin. It is slow, so read it no more than once every two seconds.

DS18B20: a digital sensor on the 1-Wire bus. Several can share one pin, each with its own serial number.

## Common mistakes

Subtracting 500 mV from an LM35 reading, as if it were a TMP36. Every reading comes out 50 degrees low.

Powering an LM35 from 3.3 V. It needs at least 4 V.

Logging too fast. A room does not change every millisecond. One reading a second, or one a minute, is usually enough.

Leaving the SD file open. On a real card, data not yet written can be lost when the power goes.

## Questions

Can I log to Excel directly?

Not directly. Download the CSV from the serial plotter or from the SD card, and open it in Excel, Google Sheets or any spreadsheet.

Does the LM35 model self-heating or accuracy error?

No. The number on the slider is the number it outputs. The datasheet’s accuracy spread and self-heating are not modeled.

How many readings fit on the SD card?

The card in Mokxi holds 4 MB. A line with a time and a temperature is a few bytes long, so tens of thousands of readings fit. On a real card, there is far more room.

Can I log from an ESP32 instead?

Yes, with a TMP36, a DHT22 or a DS18B20, which suit 3.3 V. An LM35 needs at least 4 V.

Related

## Keep going

Arduino TMP36 Temperature Sensor in °F and °C Arduino DHT22 Temperature and Humidity Sensor Arduino DS18B20 Temperature Sensor: Wiring and Code Arduino SD Card Module: A GPS Data Logger Arduino DS3231 Clock With a TM1637 Display Analog vs Digital Pins, and ADC Resolution Electronics Lab Report Template, With an Example The LM35 project Beginner A logger that writes a CSV to an SD card Advanced The serial plotter and its CSV Make a free account to save your logger The project page, with the full sketch Beginner

Sources

## Where the facts on this page come from

- Texas Instruments: LM35 datasheet, SNIS159 (checked 2026-09-30)
- Arduino reference: analogRead(), 10-bit resolution on the Uno (checked 2026-09-30)

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
