You are on page 1of 12

# Technical Report: The Thermistor as a Temperature

Controller

James Yu

March 9, 2003
Abstract

The purpose of the project is the creation of a temperature controller through the use of
a thermistor. The thermistor resistance is modelled to have an exponential relationship
with temperature, and this relationship is confirmed through measuring the resistance of
the thermistor for different temperatures. This data is then analyzed to calibrate and assess
the error (or accuracy) of the thermistor. Finally, the thermistor is successfully used with a
computer and a heater to control the temperature around the heater to ±3◦ C of a specified
temperature.

0.1 Introduction

## The temperature controller project’s goal is to produce an inexpensive scheme to maintain

the alexandrite laser rod at a given temperature with an accuracy of ±3◦ C. This is done by
using a thermistor to measure the temperature of the rod and convey that information to
the computer, which will maintain a given temperature using a heater.

The thermistor is basically a resistor, and these are cheap, abundant, and useful. By taking
advantage of the fact that the resistance of a resistor varies as an exponential function of
temperature, a computer can calculate the temperature by measuring the resistance of the
thermistor. Once this is done, the computer can judge whether or not to turn on a heater
to regulate the temperature.

It is found that the thermistor conforms to the exponential relationship well enough to
achieve a ±3◦ C accuracy when used in a temperature controller. The rest of this report
discusses the theory behind the thermistor, the apparatus and methods used, and the results
obtained from the experiments. The appendix summarizes the error analysis and contains
the computer programs that are used to control the temperature.

0.2 Theory

## The resistance R of a thermistor is related to the temperature T by the model

T0
R = R0 e T (1)

where R0 and T0 are the parameters that are unique to each thermistor. The resistances
are measured in Ohms, and the temperatures in Kelvins. This relationship says that the
resistance of the thermistor varies exponentially with the inverse of the temperature. Essen-
tially, as the temperature gets larger the resistance R approaches R0 , and as the temperature
approaches absolute zero the resistance theoretically approaches infinity.

1
Solving for T in equation (2) results in
T0
T = (2)
ln R − ln R0
and thus, the computer can obtain the temperature of the thermistor by measuring its
resistance R and calculating T in equation (2). Before that can be done, the calibrating
constants R0 and T0 must be obtained.

## By taking the natural log of equation (1), a linear relationship is obtained:

T0
ln R = ln R0 + (3)
T
Measuring the Resistance Temperature curve of the thermistor, one can obtain the values
of T0 and R0 by applying a linear least squares fit on ln R versus T1 . After an error analysis
on these quantities, we can use error propagation to obtain the uncertainty in a measured
temperature T
Tp
∆T = (∆T0 )2 + (T ∆ ln R)2 + (T ∆ ln R0 )2 (4)
T0
This ∆T represents the uncertainty of the calculated temperature when measuring values
for R of the thermistor, based on the uncertainties in R, R0 , and T0 (which are the values in
the equation with ∆’s). It is the expected range within which the measurement will lie with
a 68% probability. A summary of the error analysis can be found in Appendix 1.

## 0.3 Apparatus and Method

The temperature controller consists of three main components: the thermistor, the com-
puter, and the heater. Basically, the computer measures temperature information from the
thermistor, and regulates the heat using the heater. The following specific components are
needed for the temperature controller:

1. IBM-PC computer
2. Thermistor
3. Protoboard
4. Lab PC+ I/O Board
5. Heater
6. Thermometer
7. Resistors and Miscellaneous Wires

There are three main stages in building a functional temperature controller: connect the indi-
vidual components, calibrate the thermistor, and develop a computer program for temperature
regulation.

2
0.3.1 Connect and Calibrate the Thermistor

First the components are connected as shown in Figure 3, noting that the thermistor and
heater are physically in the space where the temperature needs to be controlled. To calibrate
the thermistor, the Resistance-Temperature curve for the thermistor must first be obtained.
To do this, note that the resistance RT can be calculated by measuring the voltage VT and
using the relationship
VT R1
RT = (5)
V0 − VT
A wire is connected from the node between R1 and the thermistor to the ADC0 pin on the Lab
PC+ board. Then a C++ program is written that asks the user to input a temperature, and
then calculates R0 by reading the voltage VT on the ADC0 pin. This is done by initializing
an analog to digital conversion on the ADC0 pin (refer to the AEP264 packet Exercise 3 for
more information). Then, the program simply uses eq. (2) to calculate R0 . This program
loops until a bogus temperature is inputted, and will then output the data into a text file.

A thermometer is now placed at the same location as the thermistor, and heat is applied in
the range of 30◦ C to 90◦ C while running the program. The temperatures are carefully read
by the thermometer every 3◦ C to 4◦ C and inputted into the program. The data is then used
in a Matlab script file that will finally calculate R0 and T0 .

The script file plots the ln RT versus T1 to obtain the relationship in eq. (2). It then performs
a linear least squares first order fit on this data to obtain the slope and “ln(R)”-intercept of
the straight line through the points. This was done using the function polyfit() with the ln R
and T1 data as the parameters. The slope of the line is then T0 and the intercept is ln R0 .
Once these values are obtained, the calibration is complete.

## 0.3.2 Develop a Program for Temperature Regulation

Now the push-button in Figure 3 is replaced with a Hexfet transistor (basically a switch) as
seen in Figure 4. By connecting the gate of the Hexfet to the PA0 output on the PC+ Lab
board, the computer can now turn on the heater by applying 5 volts on PA0 or turn it off
the heater by applying 0 volts on PA0.

The temperature regulating C++ program will first initialize ports A, B, and C on the Lab
PC+ board as outputs. It will then

## 1. Prompt the user for a desired temperature TD

2. Read the RT of the thermistor and calculate the temperature as was done in calibration
using R0 and T0 obtained from before.
3. If the temperature is greater than TD + 1 then apply 0 volts on PA0 to turn off the
heater, if it is less than TD − 1 then apply 5 volts on PA0 to turn on the heater, else
do nothing

3
4. Write the data point (time, temperature) to a file
5. Repeat steps 3 through 5 every 2 seconds until a key is pressed

Finally, the program is run for a few minutes set to maintain an arbitrary temperature, and
afterwards, the data is written to a file. Using Matlab, the temperature-time history of the
controller is plotted.

0.4 Results

## 0.4.1 Calibration Results

The resistance-temperature curve obtained from our thermistor is shown in Figure 1 along
with the first order least squares fit line. As seen in this data, there is a systematic error
between the heating and the cooling data; this is a result of the thermometer “catching up”
with the actual temperature. It will be higher than the actual temperature when cooling and
lower than the actual temperature when heating. This is most easily seen in the plot of the
residuals, or the difference between the measured data and the fitted line, as seen in Figure
2. I fitted only to the heating data to eliminate this error, and obtained the calibrating
constants (with errors)

ln R0 = −4 ± 0.1955 (6)
T0 = 3600 ± 64.4789 (7)

And from this, I have obtained an average uncertainty in a given temperature measurement
of
∆T ≈ 8.4790 (8)
This temperature uncertainty is actually related to the accuracy of the temperature controller
in reading the correct temperature; it has nothing to do with the actual precision of the
controller which is dictated by the heating and cooling properties of the material. In order to
eliminate this error in actual use, I changed T0 in response to the accuracy of the temperature
reading based on the thermometer, and, by doing so, achieved a high level of temperature
accuracy using the thermistor.

## 0.4.2 Controller Results

When plotting the temperature versus time curve for the controller, a jagged graph seen
in Figure 5 arises. This is due to the fact that V0 is not a constant 5 volts, but actually
fluctuates in time. To eliminate this error, I adjusted the resistance calculating part of the
C++ program to measure V0 using an ADC. After obtaining V0 I use it as part of eq. (5)
instead of using 5 volts: this eliminates the said fluctuations and produces Figure 6.

4
Figure 6 shows that the temperature controller is successful in maintaining a desired tem-
perature within ±3◦ C. From the graph it is estimated that the overshoot is within 2◦ C and
the undershoot is within 1◦ C. The reason the overshoots are bigger than the undershoots is
because the element is faster in heating up than it is in cooling down.

0.5 Conclusion

The design of a temperature controller using a thermistor coupled with a heater and a
computer is precise and accurate enough to fit the criteria of the requirements. However,
there are some performance limitations to this scheme. Due to the properties of the heater
and the object being heated, there may be an uneven amount of time spent above and below
the desired temperature TD . In the specific case of Figure 6, more time is spent above TD ,
and thus the mean temperature is a little higher than TD .

A possible extension to the testings would be to test the precision for different temperatures.
Testing for the range of all temperatures that the controller would still have precision ±3◦ C
would be useful in knowing the operating range of the controller. Extending the testings
to different kinds of thermistors would also be a valuable test to determine which kind of
thermistor is best suited for the job.

A more concrete test for the controller would be to actually use it to control the temperature
of an alexandrite laser rod, and use more precise temperature instruments to measure the
temperature that is maintained in the rod. This would truly determine the overall effective-
ness of the temperature controller on the rod.

5
0.6 Appendix 1: Error Analysis

Since this experiment is based on measurements in resistances, there are uncertainties and
errors in all the quantities leading up to the uncertainty in the final temperature reading
T by the thermistor. First, the rms deviation, or probably error associated with a single
measurement, may be calculated by
s
PN 2
i=1 (δyi )
∆y = (9)
N
where the δyi = yi − yt , or the differences from the measured values yi and the theoretical
yt .

Now, when a linear least squares is applied to the plot of ln R and T1 , there are some error
estimates that may be calculated. The uncertainties in ln R0 or the intercept and T0 or
the slope will contribute to the overall uncertainty. These uncertainties are calculated using
techniques of minimum least squares fit and error propagation, which are detailed in the
AEP264 packet pages 42 through 44.

## The resulting uncertainties are given by

v
u N
uX δi
∆ ln R = t (10)
i=1
N
r
N
∆T0 = ∆ ln R (11)
vD
u N
u X x2
∆ ln R0 = ∆T0 t i
(12)
i=1
N

Where N is the total number of measurements made, xi are the measured values T1i , δi is
P
the residual or deviations of measurements from theoretical values, and D = N N 2
i=1 xi −
PN
( i=1 xi )2 .

## Realizing now that T is a function of ln R, ln R0 , and T0 , as seen in equation (2), error

propagation may be used to calculate the uncertainty in T . It can be written that the
uncertainty ∆T is the square root of the sum of the squares of the partial derivatives of each
rms value: r
∂T ∂T ∂T
∆T = ( ∆T0 )2 + ( ∆ ln R)2 + ( ∆ ln R0 )2 (13)
∂T0 ∂ ln R ∂ ln R0
Solving for ∆T obtains the uncertainty
Tp
∆T = (∆T0 )2 + (T ∆ ln R)2 + (T ∆ ln R0 )2 (14)
T0
This then is the uncertainty associated with each calculated temperature from a resistance
measurement of the thermistor.

6
0.7 Appendix 2: C++ Program

This program is the temperature regulating program. It firsts asks the user to enter a desired
temperature. It then reads and calculates the resistance of the thermistor, and through that
calculates the temperature. If the temperature is greater than the desired temperature + 1
then it will turn the heater off, if it is less than the desired temperature - 1 then it will turn
on the heater. The program loops every 2 seconds until a key is pressed.

#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <math.h>

## unsigned LOBYTE, HIBYTE, V0_LO, V0_HI;

int main(void) {
initboard();
_outp(DigCtrl_Reg, 0x80); /*sets ports A,B, and C as outputs */
_outp(PortA_Reg, 0); /* sets A to 0 */

7
double VOLTAGE, VOLTAGE_V0;
float Temp, R, TempD;
int DONE, t=0;

float T0 = 3600;
float ln_R0 = -4;
i=0;

FILE *fp;
fp = fopen("output.dat", "w");

## printf("Temperature (Celsius) Desired: ");

scanf("%f", &TempD);
TempD = TempD + 273.16;

do {

## _outp(Comm_Reg_1, 0x02); /* selects ADC channel 2 */

_outp(StartCnv_Reg, 0x00); /* write to start conversion */

## /* waits for first bit of DONE to be 1 */

do
DONE=_inp(Status_Reg);
while((DONE & 0x01) != 0x01);

## LOBYTE=_inp(FIFO_Reg); /* low byte of data word comes first ( */

HIBYTE=_inp(FIFO_Reg); /* both bytes must be read to clear FIFO_Reg */

## /* Convert V0 to eliminate fluctuations */

_outp(Comm_Reg_1, 0x01); /* selects ADC channel 1 */
_outp(StartCnv_Reg, 0x00);
/* waits for first bit of DONE to be 1 */
do
DONE=_inp(Status_Reg);
while((DONE & 0x01) != 0x01);

V0_LO=_inp(FIFO_Reg);
V0_HI=_inp(FIFO_Reg);

printf("\nHIBYTE: %4d, LOBYTE: %4d", HIBYTE, LOBYTE);

8

printf("\nHIBYTE: %4d, LOBYTE: %4d", HIBYTE_V0, LOBYTE_V0);

## R = VOLTAGE * 1000 / (VOLTAGE_V0 - VOLTAGE); /* calculate R */

Temp = T0 / (log(R) - R0_ln);

## printf("RT: %5.2f\tTemp: %5.2f\tTime Elapsed: %d\n\n", R, Temp-273.16, t);

fprintf(fp, "%5.2f\t%d\n", Temp - 273.16, t);

## if(Temp < TempD - 1)

_outp(PortA_Reg, 4);
if(Temp > TempD + 1)
_outp(PortA_Reg, 0);

delay(2000);
t = t + 2;
} while(!kbhit()) _outp(PortA_Reg, 0); fclose(fp);

return(0); }

/*******************delay()*****************/
void delay(int dt)
{ unsigned long final;
final=dt + GetTickCount();
while(final > GetTickCount() );

return; }

/****************initialize board***********/
void initboard() {

_outp(Comm_Reg_1, 0x00);
_outp(Comm_Reg_2, 0x00);
_outp(Comm_Reg_3, 0x00);
_outp(Comm_Reg_4, 0x00);
_outp(Count_A, 0x34);
_outp(Count_A0, 0x0A);
_outp(Count_A0, 0x00);
_outp(DMATC, 0x00);
_outp(TI_Clear, 0x00);

9