Thermistor Thermometer
A thermistor and a fixed resistor form a divider the Arduino reads. The sketch turns the voltage back into degrees Celsius.
- Intermediate
- Analog Electronics
- 3 parts
Opens in your browser with the parts, wiring and code already in place. Press Run to watch it work, then change anything you like.
How it works
A thermistor is a resistor whose resistance changes with temperature. This one is an NTC (negative temperature coefficient) type: 10 kilohms at 25 degrees Celsius, and less as it warms. An Arduino cannot measure resistance, only voltage, so the thermistor is put in a divider with a fixed 10 kilohm resistor: 5 volts, then R1, then the thermistor to ground, with A0 on the point between them. At 25 degrees the two are equal and A0 sits at half the supply, about 512. Warm it up and its resistance falls, so less of the 5 volts is across it and the reading drops.
The sketch works backwards. From the reading it finds the thermistor’s resistance with ohms = 10000 × raw ÷ (1023 − raw), which is the divider equation turned round. Then the beta equation turns resistance into temperature: kelvin = 1 ÷ (1 ÷ 298.15 + log(ohms ÷ 10000) ÷ 3950), and subtracting 273.15 gives Celsius. The number 3950 is the thermistor’s beta, a figure from its datasheet. The Serial tab shows the resistance and the temperature twice a second. The reading comes from the circuit solver, so it follows the real wiring: swap the two parts round and the reading goes the other way.
Parts
- Arduino Uno
- Resistor
- Thermistor
Wiring
- Arduino Uno 5V → Resistor A
- Resistor B → Arduino Uno A0
- Resistor B → Thermistor A
- Thermistor B → Arduino Uno GND
Arduino code
// Thermistor Thermometer
// 5 V - R1 - A0 - thermistor - GND. A0 reads the voltage across the thermistor.
const float SERIES_OHMS = 10000.0; // the fixed resistor, R1
const float NOMINAL_OHMS = 10000.0; // the thermistor's resistance at 25 C
const float BETA = 3950.0; // how steeply its resistance changes with temperature
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(A0);
if (raw <= 0 || raw >= 1023) {
Serial.println("Check the wiring: A0 should sit between R1 and the thermistor");
} else {
float ohms = SERIES_OHMS * raw / (1023.0 - raw);
float kelvin = 1.0 / (1.0 / 298.15 + log(ohms / NOMINAL_OHMS) / BETA);
float celsius = kelvin - 273.15;
Serial.print("Thermistor: ");
Serial.print(ohms);
Serial.print(" ohms ");
Serial.print(celsius);
Serial.println(" C");
}
delay(500);
}
Try changing it
- Select the thermistor and change its temperature to 50. Its resistance falls to about 3.5 kilohms and the Serial tab shows about 50 degrees.
- Swap the two parts round (thermistor to 5 V, R1 to ground) and the raw reading rises with temperature instead. The sketch would then need its formula turned round too.
- Print the raw reading too by adding Serial.print(raw); above Serial.print(ohms); and watch it fall as you warm the thermistor.
Next challenge
More projects in Analog Electronics
- Voltage DividerTwo resistors share a supply voltage in proportion to their values. Measure the middle…
- Voltage ReaderAn Arduino reads a two-resistor divider with analogRead and prints the voltage. Change a…
- LED Current LimitingA resistor sets how much current an LED carries. Put a multimeter in series and see it.
- RC Low-Pass FilterA resistor and capacitor let slow signals through and soften fast ones. Watch both on an…