A thermistor is a resistor whose value changes with temperature. It's very cheap and found everywhere: chargers, batteries, 3D printers and air conditioners. The most common type is the NTC: when the temperature rises, the resistance falls.
The two key specifications
- R25: the resistance at 25 °C. The most common is 10k.
- B (Beta): describes the shape of the curve. A common value is 3950 (there are also 3435 and 3380). Get it from the seller or the datasheet.
Don't know its value? Measure it with a multimeter in a room at about 25 °C: if it reads about 10k, it's 10k, and if 100k, it's 100k. And don't hold it in your fingers while measuring, because your hand's warmth changes the reading within seconds, which is exactly what makes it a sensor.
Wiring: a voltage divider
A fixed resistor of the same value as the thermistor gives you the best sensitivity around 25 °C. See the voltage divider and the divider calculator.
The figures in the diagram show why the thermistor is sensitive: from zero to 50 °C, the voltage moves from 3.85 to 1.32 V, which is about 50 mV per degree, and the ADC on the Uno has a step of about 5 mV, so it sees the change easily. And if you want to focus on a high temperature (such as 100 °C), choose a fixed resistor close to the thermistor's value at that temperature.
The code (the Beta equation)
const float R_FIXED = 10000.0;
const float R0 = 10000.0, T0 = 298.15; // 25 °C in kelvin
const float B = 3950.0;
void loop() {
int raw = analogRead(A0);
float r = R_FIXED * raw / (1023.0 - raw); // the thermistor's resistance
float tK = 1.0 / (1.0 / T0 + log(r / R0) / B);
float tC = tK - 273.15;
Serial.println(tC, 1);
delay(1000);
}
This equation assumes the thermistor is at the bottom (towards ground), as in the diagram. If you reverse the order, reverse the calculation of r.
A worked example
A reading of raw = 300:
- The resistance: 10000 × 300 ÷ 723 ≈ 4150 Ω.
log(4150 ÷ 10000)≈ −0.88, divided by 3950 ≈ −0.000223.1 ÷ 298.15≈ 0.003354, and the sum ≈ 0.003131.- 1 ÷ 0.003131 ≈ 319.4 K → about 46 °C.
And if you want to see these numbers without the arithmetic, use the thermistor calculator.
Averaging the readings
A single reading jitters by a degree or two from noise. Take an average:
long sum = 0;
for (int i = 0; i < 16; i++) sum += analogRead(A0);
float raw = sum / 16.0;
Accuracy
- The Beta equation is approximate: accurate around 25 °C, and drifting a little at the extremes. For higher accuracy there's the Steinhart-Hart equation with three constants.
- The tolerance of the thermistor itself (1% or 5%) and of the fixed resistor both matter. A 1% resistor is better.
- The ADC reference: in this circuit it's the ratio that's measured, so a change in the 5 V has little effect as long as the divider and the ADC are on the same voltage. See the ADC.
- Self-heating: the current through the thermistor warms it. Larger resistances (for example a 100k thermistor with 100k) reduce this.
- Take an average of several readings.
Self-heating in numbers
With 10k and 10k on 5 V, the current is a quarter of a milliamp, and the power in the thermistor is about 0.6 mW. A small thermistor in air warms by roughly one degree per 1–2 mW, so the error is less than half a degree. In a battery project, you can power the divider from a GPIO pin and switch it on only at the moment of reading, saving power and heating at once.
Calibration
Put the thermistor in a glass of ice and water (very nearly exactly zero degrees), then in water with a trusted thermometer at about 50. If both readings are off by the same amount, correct by adding a number. If the error grows with temperature, the B value is probably wrong: try 3435 or 3380 instead of 3950.
With an ESP32
The ESP32's ADC is 12-bit (0–4095), so change 1023 to 4095. But it isn't linear at the extremes (near zero and near 3.3 V). It's better to use analogReadMilliVolts() and calculate the resistance from the voltage, and to power the divider from 3.3 V.
Reading faults
| Reading | Usual cause |
|---|---|
| −273 or a very strange value | The thermistor is disconnected or shorted |
| The temperature falls when you heat it | The thermistor and fixed resistor are swapped |
| A constant error of a few degrees | The R25 value or the fixed resistor is wrong |
| The error grows away from 25 | The B value is wrong |
| The reading jumps around | Noise; take an average and add a 100 nF capacitor on A0 |
A completely different NTC: inrush protection
If you open a power supply you'll sometimes find a large black disc marked something like 5D-9. That's an NTC too, but with a different job: when cold its resistance is a few ohms, so it limits the high current at switch-on while charging the large capacitors. After a few seconds it warms from the current and its resistance falls, so it wastes almost nothing. It's not a measuring sensor.
And there's the opposite, the PTC: its resistance rises with temperature. One example is the self-resetting fuse (polyfuse); see the fuse article.
NTC or DS18B20?
| NTC | DS18B20 | |
|---|---|---|
| Price | Much cheaper | More expensive |
| Signal | Analog | Digital |
| Accuracy without calibration | Moderate | About ±0.5 |
| High temperature | Some types go to 250 °C and beyond | Up to 125 |
| Speed | Fast (depending on its size) | Conversion can take 750 ms |
Uses
- Protecting batteries while charging.
- 3D printers (a 100k thermistor in the hotend).
- Switching on a fan when the temperature rises. With a comparator it can even be done without a microcontroller.
FAQ
Can I extend the thermistor's wire? Yes, a metre or two is fine, because the wire's resistance is tiny next to 10k. For longer, add a 100 nF capacitor at A0 against noise.
The printer thermistor is 100k; what do I change? Set R0 and R_FIXED to 100000, and find B for its type (many are 3950).