Home / Arduino / How to Interface a Thermistor
How to Interfaca a Thermistor

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:

{1 \over T}=a+b\,\ln(R)+c\,(\ln(R))^{3}

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:

{\displaystyle {\frac {1}{T}}={\frac {1}{T_{0}}}+{\frac {1}{B}}\ln \left({\frac {R}{R_{0}}}\right),}

where T_{0} = 25 °C and R_{0} is the resistance of the thermistor at T_{0}.

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:

Arduino Temperature Sensor Interface Circuit

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,

R=R_{0}e^{{-B\left({\frac {1}{T_{0}}}-{\frac {1}{T}}\right)}}

R = (10000)e^{-3880(\frac{1}{298.15} - \frac{1}{300.15})}

R \approx 9272.432

In the voltage divider circuit, the corresponding voltage to this resistance would be:

V_{therm} = \frac{3.3*R}{R + R_{ser}}

V_{therm} = \frac{3.3*9272.432}{9272.432+10000}

 \approx 1.588

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

codevalue = \frac{V_{therm}*1023}{3.3}

codevalue \approx 492

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

V_{therm}=\frac{3.3R}{R + R_{ser}} = \frac{3.3*codevalue}{1023}

\frac{R}{R + R_{ser}} = \frac{codevalue}{1023}

\frac{codevalue}{1023} = \frac{R}{R+ R_{ser}}

codevalue(R) + codevalue({R_{ser}}) = 1023R

1023R-codevalue(R) =codevalue({R_{ser}})


R = \frac{1023-codevalue}{codevalue({R_{ser}})}

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:

{\displaystyle {\frac {1}{T}}={\frac {1}{T_{0}}}+{\frac {1}{B}}\ln \left({\frac {R}{R_{0}}}\right),}

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:

Check Also

L298N Motor Controller Tutorial

How to Use L298N Motor Driver

You can drive a LED on or off using a microcontroller like Arduino or PIC. …

Leave a Reply

Your email address will not be published. Required fields are marked *