Analog temperature module on A0, on an Arduino Uno
A thermistor module on A0: the sketch works out the thermistor’s resistance from the reading and the beta equation turns it into degrees, once a second. 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 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $28. On Mokxi they're free.
What you'll learn
- A voltage divider with a thermistor
- NTC means resistance falls as it warms
- Turning a reading into resistance
- The beta equation for temperature
- Difficulty: Beginner
- Time: About 15 minutes
- Board: Arduino Uno R3
- Parts: 2
How it works
The module holds a 10k thermistor and a fixed 10k resistor as a voltage divider. Its OUT pin goes to A0. As the thermistor warms, its resistance falls, so the reading falls.
Every half second the sketch reads A0, works out the thermistor's resistance, then uses the beta equation with a beta of 3950 to get kelvin. It subtracts 273.15 and prints the result in degrees Celsius. Drag the module's temperature to see it change.
Parts list
2 parts, plus the jumper wires. They retail for about $28; on Mokxi they're free.
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.
// Analog temperature module on A0.
//
// module S -> A0 + -> 5V - -> GND
//
// The module is a 10k thermistor in a divider with a fixed 10k, so the
// reading falls as it warms. From the reading the sketch finds the
// thermistor's resistance, and the beta equation, 1/T = 1/T0 + ln(R/R0)/B,
// turns that into kelvin.
//
// Drag the module's temperature.
void setup() {
Serial.begin(9600);
Serial.println("Mokxi Uno: Thermistor module on A0");
}
void loop() {
int reading = analogRead(A0);
float r = 10000.0 * reading / (1023.0 - reading);
float kelvin = 1.0 / (log(r / 10000.0) / 3950.0 + 1.0 / (25.0 + 273.15));
Serial.print(kelvin - 273.15);
Serial.println(" C");
delay(500);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Starts the serial port at 9600 baud and prints a hello message. The analog pin needs no setup.
void setup() {
Serial.begin(9600);
Serial.println("Mokxi Uno: Thermistor module on A0");
}loop sketch.ino
analogRead(A0) gives 0 to 1023. The line for r turns that into the thermistor's resistance in ohms. The line for kelvin applies the beta equation, and subtracting 273.15 gives Celsius, which is printed. Then delay(500) waits.
void loop() {
int reading = analogRead(A0);
float r = 10000.0 * reading / (1023.0 - reading);
float kelvin = 1.0 / (log(r / 10000.0) / 3950.0 + 1.0 / (25.0 + 273.15));
Serial.print(kelvin - 273.15);
Serial.println(" C");
delay(500);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The temperature looks wrong. This project
Check the module wiring: VCC to 5V, GND to GND and OUT to A0. - You get odd numbers with a different thermistor. This project
The sketch assumes a 10k thermistor with a beta of 3950. Change the 10000.0 and 3950.0 values to match yours. - 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.