Microcontroller Tutorials

Arduino, Raspberry Pi, PIC, Beaglebone Resources

# How to Interface a Thermistor

A thermistor is a special resistor whose resistance varies with temperature. Learn how to interface a thermistor with a microcontroller in this tutorial.

### Introduction to Thermistors

There are two types of thermistors: NTC and PTC. Negative Type Coefficient (NTC) thermistors have resistance that decreases when the temperature increases while Positive Type Coefficient (PTC) behaves the opposite.

The relationship between thermistor resistance and temperature is given by the Steinhart-Hart equation: here, a, b and c are known as Steinhart–Hart parameters and is different for every thermistor. Note that T here is the temperature in Kelvins.

Most of the time, the Steinhart-Hart parameter for a thermistor will not be present on its datasheet. This is why the equation below is much more useful in engineering systems: where T0 = 25 °C and R0 is the resistance of the thermistor at T0.

B is known as beta (β) parameter and is provided in the datasheet.

The B value is true only for a given range. For example, this thermistor has the following B values: Here's what those numbers mean: at temperatures from 25 °C to 50 °C, the B value is 3380 (K is Kelvins) while at 25 °C to 85 °C, the B value becomes 3434. The B value increases to 3455 at 25 °C to 100 °C.

Knowing the exact temperature range for your application is needed to use the correct B value.

### Interface Circuit

Since microcontrollers read voltage and not resistance, we need to find a way to convert the resistance change to voltage change. The simplest circuit to use is a voltage divider: I recommend using the 3.3V as supply for the circuit because it is less noisy compared to the 5V supply on the Arduino board. For bare microcontrollers like PICs, there is no problem using the 5V supply.

The 10k resistor is chosen because it is the same value as the nominal (R0) value of my thermistor. This makes it more sensitive to resistance changes compared to having a large difference between the two.

Let's say the temperature is 27 °C and the maximum possible temperature is 100 °C. Using the same thermistor as our example above, the B value should be 3380. Manipulating the equation, the resistance at 27 °C is therefore, In the voltage divider circuit, the corresponding voltage to this resistance would be:

This voltage value would then be interpreted by the analog to digital converter as:

A better equation is to combine the voltage divider equation with the analog-to-digital equation like this,

So here's how the above equations translate to an Arduino sketch:

Once we have the thermistor resistance, all we need is use the Steinhart-Hart equation to find the temperature: The above code works but there will always be reading errors due to measurement noise and other factors. Thus, it's better to take as many samples as you can and get the average of those samples. Let's say we use 100 samples:

This would be the full code for a thermistor-based arduino temperature sensor:

The sketch above is what I used for my Arduino temperature sensor project. Here it is in action:

## 2 thoughts on “How to Interface a Thermistor”

1. Ivor says:

shouldn't the equation above be R = codeValue x Rser / (1023 - codeValue)

As you are cross dividing. I am using your analysis for a project but i think the last equation is inverted??

This site uses Akismet to reduce spam. Learn how your comment data is processed.