24. Thermistors, the Beta Equation & Calibration
Convert a thermistor divider reading to resistance and then to Celsius with the Beta equation, calibrate against a reference thermometer, and switch a fan with hysteresis.
Learning outcomes
- Explain how an NTC thermistor's resistance changes with temperature
- Calculate thermistor resistance from an ADC reading for the course wiring order
- Convert NTC resistance to Celsius using the Beta equation and datasheet constants
- Calibrate the reading against a reference thermometer and record the error
- Drive a fan through a MOSFET with separate ON and OFF temperatures
Parts and preparation
Uno, 10 kΩ NTC thermistor, 10 kΩ fixed resistor, breadboard, jumper wires and a reference thermometer. Optional: the MOSFET fan driver from Lesson 16 for the hysteresis demo.
Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.
Start from the divider
Lesson 23 turned an LDR's resistance into a voltage with a fixed resistor. A thermistor uses exactly the same divider and the same resistance formula. What is new here is the second step: converting that resistance into a temperature, then checking the result against a real thermometer.
Keep the course order - 10 kΩ to 5 V, thermistor to GND, junction to A0 - so the formula and the SimpleThermistor library in Lesson 30 both match your wiring.
How an NTC thermistor works
A thermistor is a resistor whose resistance depends strongly on temperature. NTC means Negative Temperature Coefficient: as temperature rises, resistance falls.
Inside a typical bead NTC, a metal-oxide semiconductor material changes how easily charge carriers move. Warmer material usually conducts better, so resistance drops. Classroom kits often use a 10 kΩ NTC: about 10 kΩ at 25 °C (298.15 K), with a datasheet Beta (B) value often near 3950 K.
PTC thermistors (Positive Temperature Coefficient) do the opposite and are less common in this course. Always check the marking or datasheet: wrong type or wrong R0 ruins the Beta maths.
| Term | Meaning |
|---|---|
| NTC | Resistance falls when temperature rises |
| R0 | Nominal resistance at reference temperature T0 (often 10 kΩ at 25 °C) |
| Beta (B) | Datasheet constant (kelvin) used in the simple temperature equation |
| Self-heating | Too much current through the NTC warms it and skews the reading - keep divider current modest |
Divider calculation (course wiring)
Course wiring uses a fixed pull-up to 5 V and the sensor to GND (same order as the SimpleThermistor library in Lesson 30):
5 V → 10 kΩ pull-up → junction to A0 → NTC → GND
Voltage at the junction: Vout = 5 V × Rsensor / (Rfixed + Rsensor).
The Uno ADC maps about 0-5 V to 0-1023. From the ADC count you can recover resistance:
Rsensor = Rfixed / (1023.0 / ADC - 1.0)
Equivalently: Rsensor = Rfixed × ADC / (1023.0 - ADC).
If you swap sensor and fixed resistor, both the voltage direction and this formula change. Always match the code to the physical order.
| ADC reading | Rough meaning (this wiring, 10 kΩ pull-up) |
|---|---|
| Near 0 | Junction near GND - shorted sensor, open pull-up, or very low Rsensor |
| Near 512 | Rsensor ≈ Rfixed (about equal share of 5 V) |
| Near 1023 | Junction near 5 V - open sensor / broken GND side, or very high Rsensor |
Worked resistance example
Suppose Rfixed = 10000 Ω and analogRead returns 512.
Rsensor = 10000 / (1023.0 / 512 - 1.0) ≈ 10000 / (2.00 - 1.0) ≈ 10000 Ω.
So the sensor is about equal to the pull-up - for a 10 kΩ NTC that is near room temperature if R0 is 10 kΩ at 25 °C (exact Celsius still needs the Beta step).
If ADC = 0 or 1023, do not trust the formula: you risk division by zero or a meaningless result. The worked sketch treats those as a divider fault.
Beta equation: resistance to temperature
The Beta model converts NTC resistance to absolute temperature in kelvin:
1/T = 1/T0 + ln(R / R0) / B
T and T0 are in kelvin. T0 is usually 25 °C → 25 + 273.15 = 298.15 K. R0 is the resistance at T0. B is the datasheet Beta constant.
Then Celsius = T - 273.15.
Use float maths and the C log() natural logarithm from math.h. Wrong B or R0 values produce smoothly wrong temperatures - always copy constants from your part datasheet.
| Symbol | Typical course value | Notes |
|---|---|---|
| R0 | 10000 Ω | At T0; confirm on your NTC |
| T0 | 298.15 K (25 °C) | Must match the temperature used for R0 |
| B | Often ~3950 K | Datasheet Beta; varies by part |
| R | From divider formula | Must use the same wiring as the formula |
#include <math.h>
const float seriesR = 10000.0; // Rfixed pull-up
const float nominalR = 10000.0; // R0 at T0
const float nominalK = 25.0 + 273.15;
const float beta = 3950.0; // B from datasheet
float resistance = seriesR / (1023.0 / raw - 1.0);
float invT = 1.0 / nominalK + log(resistance / nominalR) / beta;
float celsius = 1.0 / invT - 273.15;Calibration and hysteresis
Real parts have tolerance. Breadboard contact resistance, supply voltage and self-heating add error. Calibrate against a known reference (a room thermometer, or an ice-water bath for about 0 °C) and record the sketch reading, the reference reading and the difference in your logbook.
For on/off control (fan, lamp, alarm), do not use a single threshold. Noise around that point makes the output chatter. Use hysteresis: turn ON above one value and OFF only below a lower value (or the reverse for a heater / night light).
const float onC = 30.0;
const float offC = 27.0;
bool fanOn = false;
if (!fanOn && celsius >= onC) {
fanOn = true; // rising trip
} else if (fanOn && celsius <= offC) {
fanOn = false; // falling trip
}
// Drive MOSFET/fan from Lesson 16 using fanOn - never from an Uno pin directlyRecord the calibration
Take at least three reference points - for example ice water, room air and a warm hand around the sensor - and let each reading settle for a minute. If the error is roughly the same at every point, add a fixed offset in code. If it grows with temperature, check R0 and Beta against the datasheet before adding any correction.
Practical Task B asks for exactly this evidence: the formula, the reference points and the error you accepted.
| Condition | Reference (°C) | Sketch (°C) | Error (°C) |
|---|---|---|---|
| Ice water, stirred | 0.2 | 1.1 | +0.9 |
| Room air | 23.5 | 24.3 | +0.8 |
| Held in the hand | 32.0 | 32.9 | +0.9 |
Your own library
Once the thermistor maths works in a sketch, package it as a reusable library with a .h header and .cpp source file in Documents/Arduino/libraries/. See the course extension: How to create a SimpleThermistor library.
Wiring and safe build sequence

- 5 V -> 10 kΩ pull-up -> A0 junction -> NTC -> GND
- Drive any fan through the MOSFET circuit from Lesson 16 (not directly from an I/O pin)
Worked sketch: thermistor on A0
Download .ino sketch#include <math.h>
const float seriesR = 10000.0;
const float nominalR = 10000.0;
const float nominalK = 25.0 + 273.15;
const float beta = 3950.0;
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(A0);
if (raw <= 0 || raw >= 1023) {
Serial.println("Divider fault");
delay(500);
return;
}
float resistance = seriesR / (1023.0 / raw - 1.0);
float invT = 1.0 / nominalK + log(resistance / nominalR) / beta;
float celsius = 1.0 / invT - 273.15;
Serial.print(celsius, 1);
Serial.println(" C");
delay(500);
}How the code works
- Reads only the thermistor divider on A0.
- The formula assumes 10 kΩ pull-up to 5 V and thermistor to GND (course wiring / SimpleThermistor).
- Boundary checks avoid division by zero and flag open/short wiring.
- Use datasheet R0 and Beta values for your actual thermistor.
- Serial.print(celsius, 1) shows one decimal place.
Test and record evidence
Practical evidence checklist
Common faults and checks
- If temperature moves backwards or is unrealistic, check divider order and the resistance formula.
- Confirm R0, T0 and Beta match the datasheet for your NTC.
- Do not heat a thermistor with a flame or high-power source - use body heat or warm air only.
- ADC stuck at 0 or 1023: check for open wires, swapped rails, or a short across the sensor/resistor.
- Reading drifts upward the longer it runs: self-heating - check the fixed resistor is 10 kΩ, not a smaller value.
Check your understanding
Q1. Which part of this lesson is the same as for an LDR?
Show answer
The divider wiring and the formula that turns the ADC count into resistance.
Q2. What does NTC mean for resistance as temperature rises?
Show answer
Resistance falls (negative temperature coefficient).
Q3. For the course wiring (pull-up to 5 V, sensor to GND), what is Rsensor?
Show answer
Rsensor = Rfixed / (1023.0 / ADC - 1.0).
Q4. In the Beta equation, what units must T and T0 use?
Show answer
Kelvin.
Q5. What is hysteresis in an on/off control?
Show answer
Different switch-on and switch-off thresholds that prevent chatter.