NTC thermometer
Measure temperature with an NTC thermistor and the Beta equation.
Sensors · Beginner
In a real product: Battery pack temperature sensing (Automotive): Thermistors watch each module's temperature.
A thermistor's resistance changes with temperature. An NTC (negative temperature coefficient) one drops as it warms up. With a fixed resistor it makes a voltage divider, and a formula turns the reading back into degrees.
What you'll learn
- Reading an analog sensor and converting it to physical units
- The Beta equation for NTC thermistors
- Floating-point maths:
log()and printing with decimals
How it works
The module has a 10 kΩ NTC (at 25 °C) above a 10 kΩ resistor, and OUT goes to A0. From the reading, the resistance ratio is 1023 / reading - 1. The Beta equation then gives the temperature in kelvin:
1/T = ln(R / R25) / Beta + 1 / 298.15
where Beta (3950 for this part) says how steeply the resistance falls. Subtracting 273.15 gives degrees Celsius.
Try this
- Change the sensor's temperature slider while it runs and watch the reading follow.
- Show Fahrenheit too:
F = C × 9 / 5 + 32. - Switch on an LED or a fan (DC motor) above 30 °C.
sketch.ino
// An NTC thermistor module on A0: the Beta equation turns the reading into degrees Celsius.
const float BETA = 3950; // the thermistor's Beta coefficient
void setup() {
Serial.begin(9600);
}
void loop() {
int reading = analogRead(A0);
float celsius = 1 / (log(1 / (1023.0 / reading - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius, 1);
Serial.println(" C");
delay(1000);
}