NTC thermometer on an Arduino Uno
The NTC temperature sensor module on A0, worked out in degrees with the beta equation every tutorial for it uses. The whole build, an Arduino Uno and 1 more part, 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 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $31. On Mokxi they're free.
What you'll learn
- NTC thermistors: resistance falls as it warms
- A voltage divider with a sensor
- The beta equation
- Turning a reading into degrees
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Arduino Uno R3
- Parts: 3
How it works
The NTC module is a 10 k thermistor under a 10 k resistor. At 25 C the two are equal, so OUT sits at half the supply. As the thermistor warms its resistance falls, so OUT falls too. OUT goes to A0.
Twice a second the sketch reads A0. A formula turns that reading back into the thermistor's resistance, and the beta equation, with BETA set to 3950, turns the resistance into degrees Celsius. It prints the raw reading and the temperature with one decimal.
Parts list
3 parts, plus the jumper wires. They retail for about $31; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Half breadboard
- 1 × NTC temperature sensor module
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 |
|---|---|
| NTC temperature sensor module pin VCC | Arduino Uno R3 pin 5V |
| NTC temperature sensor module pin GND | Arduino Uno R3 pin GND |
| NTC temperature sensor module pin OUT | 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.
// NTC thermometer: the NTC temperature sensor module on A0, worked out in
// degrees with the beta equation every tutorial for this module uses.
//
// module VCC -> 5 V GND -> GND OUT -> A0
//
// The module is a 10 k thermistor under a 10 k resistor: at 25 C the two are
// equal and OUT is half the supply, and as the thermistor warms its
// resistance falls, so OUT falls too. The formula turns the reading back into
// the thermistor's resistance over 10 k, and the beta equation turns that
// into a temperature.
//
// Drag the temperature slider on the module.
const float BETA = 3950;
void setup() {
Serial.begin(9600);
Serial.println("NTC thermometer");
}
void loop() {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("reading ");
Serial.print(analogValue);
Serial.print(", temperature ");
Serial.print(celsius, 1);
Serial.println(" C");
delay(500);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Starts serial at 9600 and prints "NTC thermometer". The sensor on A0 needs no other setup.
void setup() {
Serial.begin(9600);
Serial.println("NTC thermometer");
}loop sketch.ino
Reads analogRead(A0) into analogValue, then works out celsius with the beta equation. The formula uses BETA and 298.15, which is 25 C in kelvin, and subtracts 273.15 at the end. It prints both numbers and waits 500 ms.
void loop() {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("reading ");
Serial.print(analogValue);
Serial.print(", temperature ");
Serial.print(celsius, 1);
Serial.println(" C");
delay(500);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The temperature looks way off This project
The formula assumes a 10 k thermistor with a 10 k resistor and aBETAof 3950. A different module needs different numbers. - A reading of 0 or 1023 gives nonsense This project
Check that OUT goes to A0, and that VCC and GND are connected. - The temperature numbers are wrong. NTC temperature sensor module
The voltage falls as it warms, so convert it to resistance, then use the Steinhart-Hart or Beta equation. Use the right reference resistor value, usually 10 k, and the beta value from the sheet. - Readings jump around. NTC temperature sensor module
Average several analog readings. Use the same supply voltage as the analog reference. Do not use the module on pins that share the ADC with Wi-Fi on an ESP32. - 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.