Skip to content

Embedded Systems

How to measure temperature with a thermistor and Arduino

An NTC thermistor is a resistor whose resistance falls as it warms. To read one with an Arduino, put it in a voltage divider with a fixed resistor of about the same value, read the middle on A0, then turn the reading into degrees: with map() between two known temperatures for a narrow range, or with the Beta equation for a wide one.

Wire it up

Join a 10 kΩ NTC thermistor from 5 V to A0 and a 10 kΩ resistor from A0 to GND. As the thermistor warms, its resistance falls, it takes less of the 5 V, and more lands on A0. Warmer means a higher reading: about 396 at 15 °C and 620 at 35 °C.

Live experiment

Two known points and a straight line

Warm the thermistor from 0 to 50 °C. The curve is what A0 really reads; map(reading, 396, 620, 15, 35) is the straight line through two known points, 15 °C and 35 °C. Between them it lands on the degree; outside them the curve bends away.

Try it yourself: free lesson

“How warm is it?” is lesson 4 of 6 in Signal Shore, Embedded Systems World 3. Free with an account. Lessons unlock in order, so you’ll do the 17 before it first.

Quick: two points and map()

Measure the reading at two known temperatures, a cold one and a warm one, and draw a straight line through them:

int reading = analogRead(A0);
int celsius = map(reading, 396, 620, 15, 35);

A reading of 564 is three quarters of the way from 396 to 620, so it's three quarters of the way from 15 to 35: 30 °C. Between the two points, this is good to about a degree. But a thermistor's curve bends, so outside them the line drifts off: at 45 °C the reading is 713 and map() says 43.

Accurate: the Beta equation

First turn the reading back into the thermistor's resistance. Then the datasheet's B value, often 3950 K, gives the temperature in kelvin:

1 over T = 1 over T₀ + 1 over B × ln(R over R₀)

where R₀ is the resistance at T₀ = 25 °C, or 298.15 K.

float r = 10000.0 * (1023.0 - reading) / reading;   // thermistor's ohms
float kelvin = 1.0 / (1.0 / 298.15 + log(r / 10000.0) / 3950.0);
float celsius = kelvin - 273.15;

In Arduino code log() is the natural logarithm, ln. Check that the reading isn't 0 before dividing by it.

Thermistor or sensor chip?

Thermistors are cheap, small and quick to respond, which is why they sit in kettles, 3D printer beds, battery packs and car engines. Their curve needs a little maths, and each part varies by a percent or so. A digital sensor chip gives degrees directly, at a higher price. For a thermostat or a greenhouse, a thermistor and ten lines of code are plenty.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“How warm is it?” is lesson 4 of 6 in Signal Shore, Embedded Systems World 3. Free with an account. Lessons unlock in order, so you’ll do the 17 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3A thermistor gets warmer. Its resistance…
    Show the answer

    Answer: Falls. This kind, NTC, falls as it warms.

    • Why not “Rises”? Rising with heat is a PTC thermistor's behaviour. The common NTC kind falls as it warms.
    • Why not “Goes negative”? Resistance can't go negative. An NTC thermistor's resistance falls smoothly, a few percent per degree.
    • Why not “Stays the same”? A thermistor that stayed the same would be an ordinary resistor; changing with temperature is its whole job.
  2. Question 2 of 3Why do you need two known temperatures to use map()?
    Show the answer

    Answer: Two points fix a straight line: where it starts and how steep it is. map() draws a line through two points and reads off everything in between.

    • Why not “map() needs four”? map() takes two points, written as two ranges of two numbers: input low and high, output low and high.
    • Why not “To average them”? Averaging two temperatures gives one number, not a rule for turning every reading into degrees.
    • Why not “One is enough”? One point gives a place but no slope: infinitely many lines pass through a single point.
  3. Question 3 of 3At 45 °C the thermistor reads 713, and map(713, 396, 620, 15, 35) says 43. Why 2 °C out?
    Show the answer

    Answer: Past the two known points, the thermistor's curve bends away from map's straight line. map only knows the straight line through 396 at 15 °C and 620 at 35 °C. The thermistor's real curve bends a little, so outside the two points the line drifts off it.

    • Why not “analogRead rounds down”? analogRead's rounding moves a reading by less than one count, a tiny fraction of a degree, not 2 °C.
    • Why not “The thermistor is broken”? A broken thermistor reads wildly wrong or stuck at an end. Being 2 °C out past the calibration points is normal for a curve.
    • Why not “map can't count past 35”? map() has no limit at 35; it simply carries on along its straight line, which is the problem here.
Keep practising: free lesson

“How warm is it?” is lesson 4 of 6 in Signal Shore, Embedded Systems World 3. Free with an account. Lessons unlock in order, so you’ll do the 17 before it first.

Questions people ask

What is an NTC thermistor?

A resistor whose resistance falls as it warms: NTC stands for negative temperature coefficient. A common one is 10 kΩ at 25 °C, about 16 kΩ at 15 °C and 6.5 kΩ at 35 °C. PTC thermistors do the opposite and are mostly used as resettable fuses.

What is the B value of a thermistor?

A constant from the datasheet, often around 3950 K for a 10 kΩ NTC, that describes how steeply its resistance changes with temperature. With B and the resistance at 25 °C, the Beta equation turns any resistance into a temperature.

Why is my thermistor reading wrong at high temperatures?

If you convert with map() or any straight line, it's only right near the points you calibrated at, because the real response curves. Use the Beta equation for a wide range, and check which way round the divider is wired.

How accurate is a thermistor on an Arduino?

With a 1% thermistor, a 1% fixed resistor and the Beta equation, within about a degree is typical over everyday temperatures. Running a lot of current through it warms it a little, so keep the fixed resistor around 10 kΩ.

Every topic