I have been working on precise temperature measurement for 3D printers for a while. Not only correct measurement is enough but you must also keep the desired temperature constant in order to get great 3D Printing results. Let's talk first about the correct and precise measurement. There are couple of sensors that you can use to measure your extruder or heated bed temperature. As you know most of the extruders are working between 180C and 350C. There are also high temp thermoplastics like peek that you need to go further. But if we talk about the common usage, thermistors are the favourite sensors in 3D printing community.

## How to measure temperature with Thermistors?

Thermistors are sensors whose electrical resistance change by the temperature. How can we measure the resistance and how can we calculate the relation between resistance and the temperature?

The electrical resistance of a thermistor cannot be measured directly. A simple technique for converting the resistance of the thermistor to a voltage is to use the thermistor in a voltage divider.

With a voltage divider we can measure the voltage which is correlated with the resistance.

We will talk more on the calculations. I also want to briefly tell you the thermistor types:

There are couple of thermistor types and some types increase their resistance with increasing temperature, while others shows a fall in resistance.

It is possible to use a very simplified equation for the curve of a thermistor:

ΔR = k x ΔT

Where
ΔR = change in resistance
ΔT = change in temperature.
k = first-order temperature coefficient of resistance.


In most cases the relationship between temperature and resistance is nonlinear and for some thermistors the value of k is positive, whereas for others it is negative.

So we can talk about two general types as:

Negative temperature coefficient (NTC thermistor) This type of thermistor has the property where the resistance decreases with increasing temperature, i.e. k is negative.

Positive temperature coefficient (PTC thermistor) This type has the property where the resistance increases with increasing temperature, i.e. the value of k is positive.

In addition to the nature of the resistance change, thermistors can also be categorised according to the type of material used. Typically they use one of two materials:

• Metallic compounds including oxides etc.
• Single-crystal semiconductors

The most important second question is: How can we calculate the nonlinear behavior of the resistance of the thermistors? We have limited computation power mostly with our microcontrollers.

The first approach is to use a temperature resistance table. These are the given values for the thermistors by the manufacturer. If you have the table for your thermistor here is the code that you can use to measure the temperature.

#define NUMTEMPS 20
short temptable[NUMTEMPS][2] = {
{1, 841},
{54, 255},
{107, 209},
{160, 184},
{213, 166},
{266, 153},
{319, 142},
{372, 132},
{425, 124},
{478, 116},
{531, 108},
{584, 101},
{637, 93},
{690, 86},
{743, 78},
{796, 70},
{849, 61},
{902, 50},
{955, 34},
{1008, 3}
};

int current_celsius = 0;

byte i;
for (i=1; i<NUMTEMPS; i++)
{
if (temptable[i][0] > rawtemp){
int realtemp  = temptable[i-1][1] + (rawtemp - temptable[i-1][0]) * (temptable[i][1] - temptable[i-1][1]) / (temptable[i][0] - temptable[i-1][0]);

if (realtemp > 255)
realtemp = 255;

current_celsius = realtemp;

break;
}
}

// Overflow: We just clamp to 0 degrees celsius
if (i == NUMTEMPS)
current_celsius = 0;

return current_celsius;
}


If you do not have the temperature table, There are temperature table generator codes for thermistors. These table generators use some specific values from the thermistor datasheet and generate the table for you. You can use the below links to take a look at the popular generators.

Another approach for measuring thermistor nonlinearity is Steinhart-Hart equation

Thermistor resistance is related to temperature in degrees Kelvin by the following formula:

1/T= A + B*ln(R/Rt) + C*ln(R/Rt)2 + D*ln(R/Rt)3

In the standard Steinhart-Hart equation the C parameter is set to zero. However, some manufacturers use all 4 coefficients.

Subtract 273.15 to convert Kelvin to Celsius.

You can use the below function for Steinhart-Hart methot

float thermistorRead(int THERMISTOR_PIN) {
int Vo;
float logRt,Rt,T;
float R = 9870; // fixed resistance, measured with multimeter
// c1, c2, c3 are calibration coefficients for a particular   thermistor
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
Rt = R*( 1024.0 / float(Vo) - 1.0 );
logRt = log(Rt);
T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 273.15;
return T;
}


## How Precise is the Reading?

When most people have a requirement to measure a temperature, their first reaction is to purchase the highest specification, most expensive sensor and measuring instrument they can afford. Speaking as a manufacturer, this is a reaction we applaud as it sells a lot of equipment. It is however the wrong way to set about making accurate measurements.

The temperature reading like 128.11°C does not mean we get 0.01°C precision. There are two reasons of error here;

One is the thermistor error and the second is analog reading circuitry error.

Thermistor's error range can be between (0.1 to 1.5 °C). It is important to chose right thermistor for precision.

Second is the error of the ADC, for every bit that it is wrong the resistance (around 25°C) can be off by about 50 ohms. This isn't too bad, and is a smaller error than the thermistor error itself +-(0.1°C) but there is no way to calibrate it 'away' - a higher precision ADC (12-16 bits instead of 10) will give you more precise readings.

As a conclusion for this part thermistors are Cost effective and accurate solution for measuring temperature for your 3d printer.