Read an NTC temperature sensor with an Arduino

FunduinoPublished on

Temperatur mit einem Thermistor messen – mit einem Sensor und mit mehreren

Ein NTC-Temperatursensor, auch Thermistor genannt, ist einer der günstigsten Wege, mit dem Arduino eine Temperatur zu messen – er ist nämlich nichts weiter als ein Widerstand, dessen Wert sich mit der Temperatur ändert.

In dieser Anleitung baust du den Sensor mit einem Vorwiderstand zu einem Spannungsteiler auf, liest ihn über einen analogen Eingang aus und lässt eine Bibliothek die Umrechnung in Grad Celsius übernehmen. Zum Schluss erweiterst du den Aufbau um einen zweiten Sensor.

Circuit diagram: NTC sensor with series resistor on the Arduino UNO
The NTC sensor and 10 kΩ series resistor form a voltage divider at A0.

You need this

10 kOhm NTC temperature sensor - waterproof, -20 to 105 °C, 1 m cable 10 kOhm NTC temperature sensor - waterproof, -20 to 105 °C, 1 m cable 1,01 € *Item no. F23107476About the product — 10 kOhm NTC temperature sensor - waterproof, -20 to 105 °C, 1 m cable
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W 1,72 € *Item no. F23107216About the product — Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W

All 4 parts together 15,59 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

What an NTC thermistor is

A thermistor is a resistance thermometer - a resistor whose resistance changes with temperature. The term combines “thermal” and “resistor.” It consists of metal oxides coated with plastic, epoxy, or glass for protection.

Technically, there are two types:

  • NTC (negative temperature coefficient): Resistance decreases as the temperature rises, and increases as it falls.
  • PTC (positive temperature coefficient): exactly the opposite. This type is rarely used.

Thermistors are easy to use, which is why they are found in many everyday devices, such as 3D printers and robots. Their simple design makes them inexpensive and durable. However, compared with expensive temperature sensors, they are more prone to measurement errors if the supply voltage is unstable.

The resistance of thermistors does not change linearly. Converting resistance to temperature therefore requires a complex formula called the Steinhart-Hart equation. For simplicity, this guide skips implementing the formula and instead uses a library that calculates the value in the background.

Waterproof NTC temperature sensor with metal sleeve and lead wire
The waterproof NTC temperature sensor with a 1 m lead cable

You need these technical specifications

Thermistors come in various shapes and types, so they are always supplied with technical specifications. Without this information, you can't determine the correct temperature from the measured value. You need:

  • the resistance at 25 °C - thermistors are classified by this value
  • the maximum and minimum measurement temperatures
  • the required series resistor
  • the B-value from the sensor's datasheet

The sensor used in this guide has the following specifications:

  • Measurement range: −20 °C to 105 °C
  • Resistance at 25 °C: 10 kOhm
  • B-value: B3950

Build the circuit

The NTC sensor is connected in series with the series resistor. Together, they form a voltage divider whose midpoint you read at analog input A0. For a 10 kΩ NTC, use a 10 kΩ resistor.

Circuit diagram: NTC sensor with series resistor on the Arduino UNO
The NTC sensor and 10 kΩ series resistor form a voltage divider at A0.

Include library

Search in the Arduino IDE's Library Manager for NTC_Thermistor and install the library. It converts the resistance value to temperature.

The sketches in this guide were created using version 2.0.3 of Yurii Salimov’s “NTC_Thermistor” library.

Arduino IDE library management with the NTC_Thermistor library
The NTC_Thermistor library in the Library Manager

Read temperature

In the sketch, enter the four key values for your sensor at the top: reference resistance, nominal resistance, nominal temperature, and B value. After that, simply call readCelsius() to get the temperature.

After uploading, open the serial monitor at 9600 baud. A temperature reading will appear every second.

Read the temperature of an NTC sensor
#include <Thermistor.h>
#include <NTC_Thermistor.h>

int Sensor_Pin = A0;

#define ReferenceResistance  10000  // Resistance value of the resistor connected in series with the NTC
#define NominalResistance   10000  // Resistance of the NTC at normal temperature
#define NominalTemperature      25  // Temperature at which the NTC has the specified resistance
#define BValue                3950  // Beta coefficient (found in the NTC's datasheet)

Thermistor* thermistor;

void setup()
{
  Serial.begin(9600);
  // The sensor is now initialized with the specific data.
  thermistor = new NTC_Thermistor(Sensor_Pin, ReferenceResistance, NominalResistance, NominalTemperature, BValue);
}

void loop()
{
  const double celsius = thermistor->readCelsius();  // Read the temperature

  Serial.print("Temperature: ");  // Output to the serial monitor - text only
  Serial.print(celsius);         // Send the temperature value here
  Serial.println(" °C");         // The unit appears after it

  delay(1000);  // One-second pause: one temperature reading per second
}

Use multiple sensors at the same time

You can operate additional sensors at the same time using the same wiring diagram. Each sensor needs its own series resistor.

In the following example, a second sensor is connected to analog pin A1. In addition, a loop takes 1000 measurements in a row and adds the values together. The sum is then divided by 1000, giving an average that is much steadier than a single measurement.

Read and average two NTC sensors
#include <Thermistor.h>
#include <NTC_Thermistor.h>

int Sensor_Pin1 = A0;
int Sensor_Pin2 = A1;

#define Referenzwiderstand  10000  // Resistance value of the resistor connected in series with the NTC
#define Nominalwiderstand   10000  // NTC resistance at normal temperature
#define Nominaltemperatur      25  // Temperature at which the NTC has the specified resistance
#define BWert                3950  // Beta coefficient (found in the NTC datasheet)

Thermistor* thermistor1;
Thermistor* thermistor2;

void setup()
{
  Serial.begin(9600);
  // Now the two sensors are initialized with the specific data.
  thermistor1 = new NTC_Thermistor(Sensor_Pin1, Referenzwiderstand, Nominalwiderstand, Nominaltemperatur, BWert);
  thermistor2 = new NTC_Thermistor(Sensor_Pin2, Referenzwiderstand, Nominalwiderstand, Nominaltemperatur, BWert);
}

void loop()
{
  double celsius1 = 0;
  double celsius2 = 0;

  // Add up 1000 readings ...
  for (int i = 0; i <= 999; i++)
  {
    celsius1 = celsius1 + thermistor1->readCelsius();
    celsius2 = celsius2 + thermistor2->readCelsius();
  }

  // ... and divide by 1000: this gives the average.
  celsius1 = celsius1 / 1000;
  celsius2 = celsius2 / 1000;

  Serial.print("Temperature1: ");
  Serial.print(celsius1);
  Serial.print(" °C   ");
  Serial.print("Temperature2: ");
  Serial.print(celsius2);
  Serial.println(" °C");

  delay(100);  // A tenth of a second pause
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.