Thermometer: a thermistor on A0, on an Arduino Uno
A thermistor and a 10k resistor in a divider on A0: the sketch works out the thermistor’s resistance and turns it into degrees with the beta equation, twice a second. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $30. On Mokxi they're free.
What you'll learn
- Voltage dividers
- NTC thermistors and the beta equation
- Writing a helper function that returns a value
- Converting between kelvin and Celsius
- Difficulty: Beginner
- Time: About 15 minutes
- Board: Arduino Uno R3
- Parts: 4
How it works
A 10k NTC thermistor is a resistor whose value falls as it warms. It forms a voltage divider with a fixed 10k resistor from 5V, and A0 reads the middle point. As the temperature changes, the voltage on A0 changes. Drag the thermistor's temperature in the simulator to see it.
The sketch turns the reading into volts, then into the thermistor's resistance, then into a temperature using the beta equation with B = 3950 and 10k at 25 C. Twice a second it prints the temperature in kelvin and in Celsius.
Parts list
4 parts, plus the jumper wires. They retail for about $30; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Half breadboard
- 1 × Thermistor, 10k NTC
- 1 × Resistor, 10k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
Kits that can build it
These 7 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Thermistor, 10k NTC pin 1 | Arduino Uno R3 pin GND |
| Resistor, 10k Ω pin 2 | Arduino Uno R3 pin 5V |
| Thermistor, 10k NTC pin 2 | Arduino Uno R3 pin A0 |
| Resistor, 10k Ω pin 1 | Arduino Uno R3 pin A0 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A thermometer: a thermistor on A0, degrees in the serial monitor.
//
// 10k from 5V -> A0; the thermistor from A0 -> GND
//
// Drag the thermistor's temperature on the canvas.
// The thermistor is the bottom of a divider under a 10k, so its resistance
// is 10k * v / (5 - v). The beta equation turns that into kelvin:
// 1/T = 1/T0 + ln(R/R0)/B, with T0 = 25 C, R0 = 10k and B = 3950.
float celsius() {
float v = analogRead(A0) * 5.0 / 1024.0;
float rt = 10.0 * v / (5.0 - v);
float kelvin = 1.0 / (log(rt / 10.0) / 3950.0 + 1.0 / (273.15 + 25.0));
return kelvin - 273.15;
}
void setup() {
Serial.begin(9600);
Serial.println("UNO is ready!");
}
void loop() {
float c = celsius();
Serial.print("Current temperature is: ");
Serial.print(c + 273.15);
Serial.print(" K, ");
Serial.print(c);
Serial.println(" C");
delay(500);
}
Code walkthrough
The key functions of the sketch, and what each one does.
celsius sketch.ino
Reads A0 and converts it to volts. From the divider, the thermistor's resistance is 10.0 * v / (5.0 - v), in kilohms. The beta equation then gives kelvin, and subtracting 273.15 gives degrees Celsius.
// The thermistor is the bottom of a divider under a 10k, so its resistance
// is 10k * v / (5 - v). The beta equation turns that into kelvin:
// 1/T = 1/T0 + ln(R/R0)/B, with T0 = 25 C, R0 = 10k and B = 3950.
float celsius() {
float v = analogRead(A0) * 5.0 / 1024.0;
float rt = 10.0 * v / (5.0 - v);
float kelvin = 1.0 / (log(rt / 10.0) / 3950.0 + 1.0 / (273.15 + 25.0));
return kelvin - 273.15;
}setup sketch.ino
Opens serial at 9600 baud and prints "UNO is ready!".
void setup() {
Serial.begin(9600);
Serial.println("UNO is ready!");
}loop sketch.ino
Calls celsius(), then prints the temperature in kelvin (adding 273.15) and in Celsius. It waits 500 ms between lines.
void loop() {
float c = celsius();
Serial.print("Current temperature is: ");
Serial.print(c + 273.15);
Serial.print(" K, ");
Serial.print(c);
Serial.println(" C");
delay(500);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The temperature is far off This project
Check the divider: 5V to the 10k resistor, then A0 and the thermistor, then GND. - Readings are swapped warm and cool This project
The sketch assumes the thermistor is the bottom of the divider. Do not swap it with the resistor. - The temperature reads far off or jumps around. Thermistor
Use a fixed resistor equal to the thermistor's 10k at 25 C in the divider. Convert with the Steinhart-Hart or Beta equation (Beta is about 3950 for common parts), not a straight line. - The reading goes the wrong way, or self-heating shifts it. Thermistor
An NTC lowers its resistance as it warms, so the divider voltage moves with the wiring side. Check which side the thermistor is on. Keep current small, with 3.3 V or 5 V through 10k, so it does not self-heat. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.