Calibrating a thermistor (or mostly any sensor for that matter) is a two
- measure the calibration data
- devise a calibration law that fits that data
The first step is the hardest, and unfortunately the one I have the
least experience with. I will then only describe it in very general
terms. The second step is mostly math.
Measuring the calibration data
You have to fill a table with (T, R) pairs, i.e. with resistance values
measured at know temperatures. Your calibration data should cover the
whole range of temperatures that you will need in actual use. Data
points way out of this range are not very useful. Otherwise, the more
data points you have, the better.
In order to measure the resistance of the thermistor, I advise you
against using an ohmmeter. Use instead the same setup you will be
using for the actual post-calibration measurements. This way, any
systematic errors in the resistance measurement (like ADC offset and
gain errors) will be calibrated out.
For knowing the temperature, you have two options: either use fixed
temperature points (like, e.g., boiling water or melting ice) or use an
already calibrated thermometer. Fixed points are the gold standard of
temperature calibration, but it's hard to get them right, and you will
likely not find many of them within the range of temperatures you care
Using a known-good thermometer will likely be easier, but there are
still a few caveats:
- you should make sure the thermistor and the reference thermometer
are at the same temperature
- you should keep that temperature stable long enough for both to reach
Putting both close together, within an enclosure with high thermal
inertia (a fridge or oven) may help here.
Obviously, the accuracy of the reference thermometer is a very important
factor here. It should be significantly more accurate that the
requirements you have on your final measurement accuracy.
Fitting a calibration law
Now you need to find a mathematical function that fits your data. This
is called an “empirical fit”. In principle, any law can do as long as it
lies close enough to the data points. Polynomials are a favorite here,
as the fit always converges (because the function is linear relative to
its coefficients) and they are cheap to evaluate, even on a lowly
microcontroller. As a special case, a linear regression may be the
simplest law you can try.
However, unless you are interested in a very narrow range of
temperatures, the response of a NTC thermistor is highly non-linear and
not very amenable to low-degree polynomial fits. However, a strategic
change of variables can make your law almost linear and very easy to
fit. For this, we will take a diversion through some basic physics...
The electric conduction in an NTC thermistor is a thermally-activated
process. The conductance can then be modelled by an
G = G∞ exp(−Ea/(kBT))
where G∞ is called the “pre-exponential factor”,
Ea is the activation energy, kB is the
Boltzmann constant, and T is the absolute temperature.
This can be rearranged as a linear law:
1/T = A + B log(R)
where B = kB/Ea ; A = B log(G∞) ; and
log() is the natural logarithm.
If you take your calibration data and plot 1/T as a function of log(R)
(which is basically an Arrhenius plot with the axes swapped), you
will notice it is almost, but not quite, a straight line. The departure
from linearity comes mainly from the fact that the pre-exponential
factor is slightly temperature dependent. The curve is nevertheless
smooth enough to be very easily fitted by a low-degree polynomial:
1/T = c0 + c1 log(R) + c2
log(R)2 + c3 log(R)3 + ...
If the range of temperatures you are interested in is short enough, a
linear approximation may be good enough for you. You would then be using
the so-called “β model”, where the β coefficient is 1/B. If you use a
third degree polynomial, you may notice that the c2
coefficient can be neglected. If you do neglect it, you then have the
famous Steinhart–Hart equation.
In general, the higher the degree of the polynomial, the better it
should fit the data. But if the degree is too high you will end up
overfitting. In any case, the number of free parameters in the fit
should never exceed the number of data points. If these numbers are
equal, then the law will fit the data exactly, but you have no way to
assess the goodness of fit. Note that this thermistor calculator
(linked to in a comment) uses only three data points to provide three
coefficients. This is god for a preliminary approximate calibration, but
I would not rely on it if I needed accuracy.
I will not discuss here how to actually perform the fit. Software
packages for making arbitrary data fits abound.