1 Abstract

The project offers support for NTC thermistor calculations. The Steinhart-Hart equation is a mathematical model for these thermistors that seems to fit for a wide range of temperatures with high precision. Software to calculate the characteristic Steinhart-Hart coefficients based on temperature-resistance tables for given thermistors as well as functions allowing conversion of temperature values to resistance and vice versa is provided.

2 Description

A model for the resistivity of a semiconductor as a function of the temperature was found by Steinhart and Hart 1968 ([1]). The Steinhart-Hart law describes the absolute temperature T (in Kelvins) as a function of the NTC thermistor's resistivity (in Ω) according to the formula

Steinhart-Hart polynom
1/T = a0 + a1 · ln r + a3 · (ln r)3

The figure below shows the typical graph of an NTC thermistors characteristic, giving the reciprocal temperature (in 1 / K) over the natural logarithm of the resistance (in Ω).

The constants a0, a1 and a3, also called Steinhart-Hart coefficients, vary depending on the type of thermistor. To support developer when creating temperature measurement applications, thermistor manufacturer often supply these constants for their products. They also publicate tables where resistivity of thermistor products for a wider range of temperature values are listed.

This project provides software to

Apart from the standard Steinhart-Hart equation other forms have been found. For application with lower CPU power a simplified form of the Steinhart-Hart equation can be used.

Simplified Steinhart-Hart polynom
1T = a0 + a1 · ln r

On the other hand a quadratic term can be inserted into the formula to increase accuracy giving the extended Steinhart-Hart equation

Extended Steinhart-Hart polynom
1/T = a0 + a1 · ln r + a2· (ln r)2 + a3 · (ln r)3

An introduction to thermistors and the Steinhart-Hart polynom can be found at Wikipedia [2].

3 Software

Software is provided by this project for the calculations given in section algorithms. The classes / modules can be used for

The latter can be done for standard, simplified or extended Steinhart-Hart polynom.

Download the archives for C or Java here.

3.1 Java-Classes

For Java the following classes are available

Class Description
NtcException Exception used in this thermistor framework

Represents an T-R table for an NTC thermistor.
Provides methods to get name and description of the NTC thermistor as well as methods to add entries and to lookup the resistance for a given temperature value.

NtcThermistorModel Represents an NTC thermistor modelled using the Steinhart-Hart polynom 1/T = a0 + a1 · ln r + a3 · (ln r)3.
The model will be created using a NtcTable object. It provider methods to read the themistor name, get the NtcTable object, get the Steinhart-Hart coefficients as well as methods for conversion from temperature to resistance and vice versa.

Represents an NTC thermistor modelled using the extended Steinhart-Hart polynom 1/T = a0 + a1 · ln r + a2· (ln r)2 + a3 · (ln r)3.
Derived from NtcThermistorModel thus providing the same methods.

NtcThermistorSimplifiedModel Represents an NTC thermistor modelled using the simplified Steinhart-Hart polynom 1T = a0 + a1 · ln r.
Derived from NtcThermistorModel, provides the same methods.

Note: Generics are used in the project so Java 5 or higher is required according to that.

A small test class NtcTest is part of the package together with an example text file containing an T-R table of a theoretical NTC (simu.txt). To make developers life easy the whole application is deployed as an (executable) jar file containing all sources, classes and a manifest file with main class NtcTest.

After download the test application can be invoked by

java -jar thermistor.0.1.jar

The output produced can be seen here.

3.2 C Modules

Three C modules are available

Module Description
coeff.c Program used to calculate Steinhart-Hart coefficients from an NTC table (given as text file).

Temperature to resistance calculation.

rtot.c Resistance to temperature calculation.

For usage under Windows they have been compiled (using Cygwin's C compiler). For other OS please compile them with your system C-compiler. An example text file containing an T-R table of a theoretical NTC (simu.txt) is also provided for testing purposes.

Example outout of the "coeff" program is given here.

4 Algorithms

4.1 Conversion from resistance to temperature

Based on a measured resistance value of an NTC thermistor the extended Steinhart-Hart equations allows a simple calculation of the temperature

1/T = a0 + a1 · ln r + a2· (ln r)2 + a3 · (ln r)3

Here r is the resistance in Ω and T the absolute temperature in K (K = Kelvin). With absolute zero Tabs= -273.15 ° C, the formula for the temperature t in °C finally leads to

t = 273,15 ° C + [ a0 + a1 · ln r + a2· (ln r)2 + a3 · (ln r)3 ]-1

By setting appropriate coefficients to zero, the calculation according to the simplified or standard Steinhart-Hart equation can be done as well.

4.2 Conversion from temperature to resistance

To calculate resistance values in Ω from temperature in °C the root r of the extended Steinhart-Hart equation must be found (for the standard polynom simply set a2=0 in the formulas below)

1/T = a0 + a1 · ln r + a2· (ln r)2 + a3 · (ln r)3

with y = ln r, we get

1/T = a0 + a1 · y + a2 · y 2 + a3 · y 3

We introduce the substitutions

T = t + Tabs

b = a2 / a3

c = a1 / a3

d = (a0 - 1 ⁄ T) / a3

p = c - ⅓· b2

q = 2/27 · b3 - 1/3 · b · c + d

u = [ -q/2 + ( q2/4 + p3/27 )½ ]

v = [ -q/2 - ( q2/4 + p3/27 )½ ]


r = eu + v - b/3

for the resistance r (in Ω) of a given temperature t (in ° C).

4.3 Calculation of Steinhart-Hart coefficients

Sometimes calculation of coefficients is done using special temperature values. Inserting four value pairs in the range of interest into the extended Steinhart-Hart poylonm leads to a system of linear algebraic equations (Three value pairs for the standard Steinhart-Hart polynom). Temperatures typically used are for example 0° C, 15° C, 25° C and 70° C. By solving this system the values for a0, a1, a2 and a3 can be determined.

A better approach is the mathematical optimization technique called ordinary least squares (OLS), that was introduced by Carl Friederich Gauß in 1801. Details about the theory of OLS are given at Wikipedia [3] or MathPlanet [4].

If the function that is approximated is a polynom, theory of vector spaces, scalar products and orthonormal bases eases the calculation. Given a list with n temperature-resistance pairs

(r0, t0), (r1, t1), ..., (rn-1, tn-1)

(where n should be at least 3), the question for best fitting of the Steinhart-Hart coefficients leads to the minimization of

sum := Σ [ t(ri) -ti

where ti is the i-th temperature value and t(ri) is the calculated temperature according to the polynom.

This optimization requires a small mathematical excursion. For a positive integer n and given abscissa values x0, x1, ..., xn-1 the polynoms with degree ≤ n build a vector space V. On V a scalar product can be defined by

[ p, q ] := Σ p(xi) · q(xi )


|p| := [ p, p ]½

the scalar products makes V a normed space. For a function f with ordinate values

yi := f(xi)

for i = 0, .., n-1 there is exactly one polynom pf in V that matches the function in the coordinates (x0, y0), (x1, y1), ..., (xn-1, yn-1).

If a poisitve integer m, with m ≤ n, is given, all polynms of degree m build a sub space U of V. The question for the best approximation of f by polynoms from U is equivalent to the best approximation of pf by polynom from U in respect to | |.

   n-1      n-1      
s =  Σ [ uf(xi) -yi  =  Σ [ uf(xi) -pf(xi)]²  =  |uf -pf|
  i=0     i=0      

Answering the last question turns out to be very easy, if an orthonormal base { u1, u2, ..., um } of U is given. For pf the best approximation uf  evaluates as

uf = Σ [ ui, pf ] ·u i

If for example an R-T table with value pairs from 0° C up to 100° C in steps of 1° C is given, the polynom pf has degree 101 (!). Fortunately it must not be found, in order to find the Steinhart-Hart coefficicents and thus finding uf. Starting with the canonical base { v1=1, v2=x, v3=x², v4=x³ } of U, an orthonormal base { u1, u2,u3, u4 } can be evaluated. After that, the coefficients of uf are calculated by the sum stated above.

The coordinates

(x0, y0), (x1, y1), ..., (xn-1, yn-1)

are calculated from the temperature-resistance pairs as

xi = ln ri

yi = 1/(ti - T abs)

for i = 0, .., n-1.

The orthonormal base of U is evaluated recursively. We set



wi = vi - Σ [ uj, ui ] ·ui

ui=wi / |wi|1/2

for i = 2, ..., m = 4.

With this base we can calculate uf as

uf = Σ [ ui, pf ] ·ui

and determine the Steinhart-Hart coefficients from this equation. (Note that the scalar product can be calculated without knowing pf as stated above).

5 License

The software of this project is published under the GNU Lesser General Public License.

6 References

[1] J.S. Steinhart and S.R. Hart, “Calibration Curves for Thermistors,” Deep Sea Research, Vol. 15, 497-503, 1968.

[2] Thermistors, NTCs and Steinhart-Hart equation on Wikipedia

[3] Least squares on Wikipedia

[4] Least square on PlanetMath