Arduino - NTC Thermistor Temperature Sensor

A thermistor probe is one of the cheapest ways to give a project a real thermometer, and this one is sealed in steel, so it can sit in a fish tank or a cup of tea. In this tutorial, we are going to learn:

Arduino Uno reading a waterproof 10K NTC thermistor probe as temperature in °C and °F

About NTC Thermistor Temperature Sensor

Put simply, a thermistor is a resistor that is very sensitive to heat. The letters "NTC" mean Negative Temperature Coefficient: the warmer it gets, the fewer ohms it has. Arduino finds those ohms and converts them into degrees.

The one in this tutorial is a 10K NTC thermistor with a B value of 3950, the most common type for hobby projects. It is hidden inside a small stainless steel tube with a round tip, on a 0.5m black cable. The kit has five probes and five matching 10K resistors, so you do not need to buy the resistor separately.

NTC thermistor temperature sensor pinout - waterproof steel probe, two-wire cable and white JST XH2.54 2-pin plug
image source: diyables.io

The cable has only two wires, and they end in a white JST XH2.54 2-pin plug. There is no adapter board. Just push two male jumper wires into the two holes of the plug. A thermistor has no + or - side, so it does not matter which wire is which:

  • Wire 1: needs to be connected to the 5V pin of the Arduino Uno
  • Wire 2: needs to be connected to an analog input pin (A0 in this tutorial)
  • 10K resistor: needs to be connected between that analog pin and GND (0V)
10K NTC Thermistor Probe
Thermistor Type NTC, 10kΩ at 25°C, ±1%
B Value 3950
Measuring Range -20°C to 105°C
Probe stainless steel, waterproof, 5mm x 25mm, round tip
Cable 0.5m, two wires
Connector JST XH2.54 2-pin plug
Dissipation Constant 5mW/°C (typical)
Output resistance (needs the 10K resistor and an analog input)

From Ohms to Degrees

Arduino cannot measure a resistance directly. It can only measure a voltage. So the thermistor and the 10K resistor are joined in series between 5V and GND, and the point between them goes to A0. This is called a voltage divider. When the probe gets warmer, its resistance falls, a bigger part of the 5V reaches A0, and analogRead() returns a bigger number.

Temperature Thermistor Voltage on A0 analogRead()
0°C 33.6kΩ 1.15V 235
10°C 20.2kΩ 1.66V 339
25°C 10.0kΩ 2.50V 512
50°C 3.6kΩ 3.68V 753
100°C 0.7kΩ 4.67V 956

The code goes the other way. From the ADC value it first finds the thermistor resistance R. Then the B formula (also called the beta equation) gives the temperature T in kelvin:

1/T = 1/T0 + (1/B) × ln(R/R0)

Here T0 = 298.15K (25°C), R0 = 10000Ω and B = 3950. Subtract 273.15 from T to get °C. Some tutorials use the Steinhart-Hart equation, which takes three coefficients; since DIYables gives this probe's B value (3950), one coefficient is enough. Expect the Uno to agree with a kitchen thermometer to about 1°C near room temperature. The small difference that is left comes from the 10K resistor and from the Arduino's ADC.

Why does wire 1 go to 5V and not to 3.3V? The Uno's ADC compares the voltage on A0 with its own 5V supply. When the divider gets the same 5V, only the ratio between the two counts. Say your USB port only delivers 4.85V: the divider output and the ADC reference drop by the same share, so the ratio, and the temperature, stay put. This is why the code never needs to know the exact supply voltage.

Wiring Diagram

One thermistor wire goes to 5V, the other goes to A0, and the 10K resistor connects A0 to GND. A small breadboard makes the meeting point of the A0 wire, the resistor and the GND wire easy to build. You can also twist or solder the resistor legs to the wires.

Arduino NTC thermistor wiring diagram

This image is created using Fritzing. Click to enlarge image

NTC Thermistor Circuit Arduino Uno Pin
Probe wire 1 (either wire) 5V
Probe wire 2 A0
10K resistor, first leg A0
10K resistor, second leg GND

Jumper wires can come loose when you move the project. You can stack a Proto Screw Terminal Block Shield or a Screw Shield V2 on the Arduino and connect the wires to its screw terminals. The diagram below shows the same wiring with the Screw Shield V2.

Arduino NTC thermistor Screw Shield Wiring Diagram

This image is created using Fritzing. Click to enlarge image

On the screw shield, the 10K resistor needs no extra wire: one leg goes into a GND terminal, and the other leg shares the A0 terminal with the probe wire. Tighten each screw over both.

※ NOTE THAT:

  • Water is fine for the steel tip only. The white plug and the spot where the resistor joins the wires must stay dry.
  • Do not move wire 1 to the 3.3V pin. The Uno's ADC still measures against 5V, so every reading would come out wrong.
  • Never put the probe in anything hotter than 105°C.

How To Program For NTC Thermistor

  • No library is needed. Define the analog pin and the numbers of the thermistor:
#define THERMISTOR_PIN A0 #define FIXED_RESISTOR 10000.0 // the 10K resistor #define NOMINAL_R 10000.0 // thermistor at 25°C #define NOMINAL_TEMP_K 298.15 // 25°C in kelvin #define B_VALUE 3950.0 #define ADC_MAX 1023.0 // 10-bit ADC of the Uno
  • Read A0 ten times and take the average. A single reading jumps a little, and the average is calmer:
long total = 0; for (int i = 0; i < 10; i++) { total += analogRead(THERMISTOR_PIN); delay(10); } float adcValue = total / 10.0;
  • Find the thermistor resistance from the ADC value. Because the thermistor is on the 5V side of the divider, the formula is:
float resistance = FIXED_RESISTOR * (ADC_MAX / adcValue - 1.0);
  • Use the B formula to get kelvin, then Celsius and Fahrenheit. In C++, log() is the natural logarithm (ln):
float tempK = 1.0 / (1.0 / NOMINAL_TEMP_K + log(resistance / NOMINAL_R) / B_VALUE); float tempC = tempK - 273.15; float tempF = tempC * 9.0 / 5.0 + 32.0;
  • Check the ADC value before the math. A value near 0 means the probe is not plugged in (the resistor pulls A0 to GND). A value near 1023 means a short or a missing resistor. Without this check, the sketch would print strange numbers such as inf or nan.

Arduino Code - NTC Thermistor Temperature Sensor

Once per second, the sketch prints the averaged ADC value, the thermistor resistance, and the temperature in °C and °F. If the probe is unplugged or shorted, it prints a warning instead.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-ntc-thermistor-temperature-sensor */ #define THERMISTOR_PIN A0 // Arduino pin connected to the point between the thermistor and the 10K resistor #define FIXED_RESISTOR 10000.0 // the 10K resistor from A0 to GND, in ohms #define NOMINAL_R 10000.0 // thermistor resistance at 25°C, in ohms #define NOMINAL_TEMP_K 298.15 // 25°C in kelvin #define B_VALUE 3950.0 // B value (beta) of the thermistor #define ADC_MAX 1023.0 // Arduino Uno has a 10-bit ADC: 0 to 1023 #define SAMPLE_COUNT 10 // number of readings to average void setup() { Serial.begin(9600); // start the Serial Monitor connection } void loop() { // read A0 several times and average, because a thermistor reading is a bit noisy long total = 0; for (int i = 0; i < SAMPLE_COUNT; i++) { total += analogRead(THERMISTOR_PIN); delay(10); } float adcValue = total / (float)SAMPLE_COUNT; if (adcValue < 10) { // the 10K resistor pulls A0 down to GND: the probe is not connected Serial.println("Probe not found - check the plug and the 5V wire"); } else if (adcValue > ADC_MAX - 10) { // A0 sits at 5V: the probe wires touch each other, or the 10K resistor is missing Serial.println("Reading at the top - check for a short or a missing 10K resistor"); } else { // voltage divider: thermistor on the 5V side, 10K resistor on the GND side float resistance = FIXED_RESISTOR * (ADC_MAX / adcValue - 1.0); // B formula: 1/T = 1/T0 + (1/B) * ln(R/R0), where log() is the natural log float tempK = 1.0 / (1.0 / NOMINAL_TEMP_K + log(resistance / NOMINAL_R) / B_VALUE); float tempC = tempK - 273.15; // kelvin to Celsius float tempF = tempC * 9.0 / 5.0 + 32.0; // Celsius to Fahrenheit Serial.print("ADC: "); Serial.print(adcValue, 1); Serial.print(" | R: "); Serial.print(resistance, 0); Serial.print(" ohm | "); Serial.print(tempC, 1); Serial.print(" °C | "); Serial.print(tempF, 1); Serial.println(" °F"); } delay(1000); // about one line per second }

Quick Steps

  • Connect Arduino to PC via USB cable.
  • Wire the thermistor probe and the 10K resistor to Arduino as shown in the wiring diagram.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Open the Serial Monitor and set the baud rate to 9600.
  • Fill a glass with ice and a little water, and stir it. Leave the probe in the air for a few lines, then put the steel tip into the ice water.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
ADC: 489.4 | R: 10903 ohm | 23.1 °C | 73.5 °F ADC: 489.9 | R: 10882 ohm | 23.1 °C | 73.6 °F ADC: 489.1 | R: 10916 ohm | 23.0 °C | 73.5 °F ADC: 412.6 | R: 14794 ohm | 16.4 °C | 61.6 °F ADC: 331.8 | R: 20832 ohm | 9.4 °C | 48.8 °F ADC: 279.5 | R: 26601 ohm | 4.5 °C | 40.1 °F ADC: 252.3 | R: 30547 ohm | 1.8 °C | 35.3 °F ADC: 241.7 | R: 32325 ohm | 0.7 °C | 33.3 °F ADC: 238.2 | R: 32947 ohm | 0.4 °C | 32.7 °F ADC: 236.9 | R: 33183 ohm | 0.2 °C | 32.4 °F ADC: 237.3 | R: 33110 ohm | 0.3 °C | 32.5 °F
Ln 11, Col 1
Arduino Uno on COM15
2

The first three lines are the air in the room. When the tip went into the ice water, the resistance grew and the reading fell for about ten seconds before it settled. Stirred ice water is always close to 0°C, so it is an easy test for your probe: a result within about 1°C is normal.

If the temperature goes DOWN when you hold the probe in your hand, the thermistor and the 10K resistor have changed places. Put the thermistor on the 5V side and the resistor on the GND side, as in the wiring table.

Ideas for what to build next:

  • A fridge or freezer alarm that beeps with a piezo buzzer when the inside gets warmer than a limit you choose.
  • An aquarium heater control that switches the heater with a relay.
  • A small thermometer for home brewing that shows the temperature on an LCD I2C.

Want a probe that sends a ready digital value, with no resistor and no formula? See Arduino - Temperature Sensor for the waterproof DS18B20. For an oven or a soldering iron, far above 105°C, use Arduino - MAX6675 Thermocouple Module.

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES