# Results from Modeling a Thermister

In the last blog post, I described a long winded approach about how I built a model for a thermister to relate the voltage measured from a BeagleBoneBlack (BBB) microcontroller to the temperature. This post will summarize the results from the model, and explain how to connect up the system.

## Thermal Sensor Data

The thermal sensor used is a 100k thermistor Part No. HT100K3950-1 invidually connected to a 1m cable:

**Hotend Thermistor**

100K Glass-sealed Thermistor
3950 1% thermistor 1.8mm glass head

1M long cables 2 wires

PTFE Tube 0.6*1mm to protect from the thermistor

Shrink wrap between thermistor and the cables.

The site included a weird word document with a bunch of numbers. I saved the data as a .csv file so I can use the data in python. If you want to follow along, you can you download the document here

I then made a chart which includes the expected resistance and the errors. This chart summarizes the data provided by the manufacturer:

We than then limit the data to operating temperature range which I care about:

Based on the Resistance vs Temperature Chart, we can make an assumption that the distribution follows the relationship followed by this fitness function:

where resistance is meaured in , temperature measued in degrees celcius, and the constants a, b, and c can be found (through curve fitting).

Lets define the fitness function and find the constants a, b, and c.

```
fit coefficients:
[ 2.95517151e+02 4.52495454e-02 5.12190680e+00]
a= 295.517150959
b= 0.0452495454444
c= 5.12190680215
Covariance matrix:
[[ 6.94401115e-01 1.20117237e-04 8.77447476e-02]
[ 1.20117237e-04 2.41377772e-08 2.04485474e-05]
[ 8.77447476e-02 2.04485474e-05 2.05394937e-02]]
```

Now lets plot the expected resistance, curve fit resistance and residuals to understand the error in the curve fit:

```
Residual mean (Kohm):
-8.15077359012e-09
Residual std dev (Kohm):
0.264370345418
```

As we can see, the residual error is very small compared to the range of resistance, and follows a (some what) normal distribution. That we have a model of resistance vs temperature, lets set up our microcontroller (BBB) to measure temperature. Since our sensor is a variable resistor, we can take an analog mesaurement by passing a current though the thermister and measuring the voltage accross it. Since we need to limit our input voltage to 1.8 V (according to the BBB spec, we can use a voltage divider to limit the maximum voltage accross the thermistor (as shown below)

In our case, we need to calculate the correct R1 to ensure the voltage accross the thermistor (which is read through the analog input pin of the BBB) does not exceed 1.8V based on the maximum operating range of temperature. For us this is between 0C and 100 C. Based on the plot of the resistance vs temperature for the thermistor, we know that at 0C, the resistance of the thermistor is a maximum of 327.240 Kohm. We can then use this value as R2 in a generic voltage divider, to calculate for R1.

```
Minimum value for R1 in kohms
272.716666667
```

Looking at the standard 1% resistor chart or calculator we now know we should use 274k ohm resistor for R1.

Now that we have R1 and Vin set as constants and we can measure Vo from the BBBâ€™s analog input pin, we can now write a rearrange the voltage divider equation and fitness function to relate Vo to temperature. The previous blog post goes over this, but the resulting function is here:

We can now use this function and plot for the full range of input voltages: