## Temperature sensor – A trip to Steinhart-Hart, Gaussian elimination and thermistors

I made a thermistor-based, water-resistant temperature sensor to be used with a micro controller. Here I document the process on how to get the thermistor calibration data.

Recently, my friend w0z visited after 28c3 and we ended up checking out Segor, a brick-and-mortar electronics shop in Berlin. It's to me like a candy shop is to kids. Among other things, a thermistor module piqued my interest, mostly because I had never used one before.

The thermistor module I got came as a thermistor and an op-amp on a PCB. I hooked it up to an Arduino's analog input pin and sure enough I could see the input data change when I exposed the sensor to warm air.

## Documentation

Of course, there is an article on thermistors on Wikipedia. While reading it, you'll learn:

- the ratio of the thermistor's resistance to its temperature is proportional but non-linear
- for accurate temperature measurements, the resistance/temperature curve of the thermistor must be described
- someone already solved that: Steinhart-Hart equation
- the coefficients necessary for the Steinhart-Hart equation are usually provided in the thermistor's data sheet.

Unfortunately, the **module came with no documentation at all**. The thermistor itself just said 4k7, which means it has a resistance of 4,700 ohms at 25°C. A bit frustrated, I de-soldered the thermistor and decided to make my own circuit and calibration data.

## Half-bridge

I searched the web a bit for thermistor temperature sensor schematics. Then w0z pointed me to the course material of her electrical engineering studies, namely 6.121J at MIT. Not quite able to find it on the website of MIT, I found her course material on a Chinese mirror. After reading it, I decided to use a half-bridge for my schematics. The thermistor would be part of a voltage divider. I would have a micro controller measure the voltage drop across the thermistor and determine the thermistor's current resistance, ultimately computing the current temperature.

Given the above schematic, the thermistor's resistance equals Rntc = { 4k7 ohms / (Vcc - Vntc) } * Vntc. Vcc is known. Vntc is determined by measurement. Thus Rntc can be determined.

## Steinhart-Hart

The simplified Steinhart-Hart equation is a model of the resistance of e.g. thermistors at different temperatures. It uses three coefficients that are specific to the thermistor at hand. Knowing the three coefficients, I can use the thermistor's measured resistance to get its current temperature. The three coefficients unknown (no data sheet), I can expose the thermistor to three known temperatures and measure the according resistance. That would leave me with a set of three linear equations with three unknowns, i.e. the coefficients. The thermistor says 4k7 for 25°C, so I already had one equation. I had to take two more measurements at known temperatures. Not having a thermometer at hand, I chose:

- 0°C (water freezing at sea level) and
- at 100°C (water boiling at sea level).

## Water-resistant sensor

I intended to submerge the thermistor in water. Tap water is usually not salt-free. In an effort to make my sensor insensitive to water conducting between the two pins of the thermistor while submerged, I encased it in shrinking tube. I used pliers to clamp the open end shut while the shrinking tube was hot. At the other end, I added a three-pin connector. The pull-up resistor of the above circuit is encased in the shrinking tube around the connector.

## Calibration Method

I hooked the sensor up to an Arduino for measurement. A simple ADC measurement would suffice. We'd put the sensor into water and wait for the measured value to rise/sink to the temperature of the surrounding medium. The value was noted down when the measurement was stable for at least five seconds.

We used a slush (finely crushed ice with a few tablespoons of water) to measure at 0°C. We used boiling water (roiling boil, cut off heat, let settle for roil to stop) to measure at 100°C.

## Self-heating

While doing the measurement in slush, self-heating of the thermistor became a problem. Since its resistance reduces proportionally to decreasing temperature, the thermistor would let more current pass and thus self-heat. The measured voltage-drop at the thermistor would vary by about 2% while being inside the slush. This problem can easily be overcome by not constantly applying Vcc to the thermistor, but only for the short time of measurement. Thus we connected the Vcc pin of the sensor to a digital output pin of the micro controller. We chose a period of 5ms for measurement and a period of 100ms pause. That was sufficient to get a stable measurement.

## Gaussian elimination

The results of our measurements were:

- for Tntc = 0°C, Rntc = 14457 ohms
- for Tntc = 25°C, Rntc = 4700 ohms
- for Tntc = 100°C, Rntc = 384 ohms

The above figures - each put into the Steinhart-Hart equation - left me with a set of three linear equations with three unknowns. There's a neat mathematical method to solve this this and, of course, there is a Wikipedia article on it: Gaussian elimination. Really neat: Gaussian elimination computes a matrix decomposition. You could use pen and paper to do it manually, or simply use your computer. If appropriate math software is unavailable, use this online calculator to solve linear equation systems. I found a few on the web, the one I linked to was the only one providing proper results. I ended up with the following coefficients:

- A: 0.0011657006
- B: 0.0002508247
- C: 0.0000001077

## Result

The above coefficients, set into the Steinhart-Hart equation, let me compute a look-up table to put into the micro controller. For each value the micro controller could get from the ADC, I provided an according temperature value inside the boundaries from -40°C upto 120°C.

## Links

- Resource about
*NTC thermistor calculations*on Sourceforge: http://thermistor.sourceforge.net/ - http://mathworld.wolfram.com/GaussianElimination.html
- http://easycalculation.com/matrix/gaussian-elimination.php
- http://www.sosmath.com/matrix/system1/system1.html

wasteJanuary 13th, 2012 - 21:15

while segor is really what you described -a candystore- and i cannot resist buying more than whats on my list when i go there, it is quite expensive if you want to buy much stuff.

i have recently found http://www.reichelt.de which is quite cheaper (but its online, so only electronic candies

PS nice touch on the torrent meter

skyteeJanuary 13th, 2012 - 23:51

Yes, that is true! Yet, they do not have a brick-and-mortar store around the corner Thanks for the heads-up

Wire WoundApril 14th, 2013 - 01:38

Very nice blog post. I absolutely appreciate this website.

Keep writing!

_KaszpiR_September 8th, 2013 - 23:16

Great article. Going to do something similiar, but I’m thinking in a a bit diffferent method of getting data calibration. I have fan controller (Scythe Kaze Master), which can be used to connect sensor diodes. I have about 6 diodes, and have noticed that their reading vary (for example up to 2C), but I have chosen the pairs that has the least error between each other. I’m going to use a water as a heated medium (actually water cooling in computer), which makes the temperatures even in whole loop. Heat will be increased by using computer itself – I have noticed the unused GPU reads temperatures very well – so I can also use the readings from computer.

Your article is very helpful, especially section about self heating and understanding why the readings under higher temperatures vary so much.