# Thermistor or Temperature Sensor With Arduino

**Thermistor or Temperature Sensor**:

A thermistor or temperature sensor is a resistor that changes its resistance with temperature. Technically, all resistors are thermistors since their resistance always changes slightly with temperature, but this change is usually very small and difficult to measure. Thermistors(temperature sensor) are made of so their resistance changes drastically, such that they can change 100 ohms or more per degree centigrade.

There are two types of thermistors(temperature sensor), called NTC (from the English “negative temperature coefficient ”) and PTC (for“ positive temperature coefficient ”). In the First, as the temperature increases, its resistance decreases; in the seconds, as the temperature increases, its resistance increases. Our projects will normally use NTCs to measure temperature; the PTCs are usually used more inside resettable fuses (where if the temperature rises, increase their resistance to “choke” the current and thus protect from a possible overheating to circuits).

Thermistor or Temperature Sensor are much cheaper than other types of temperature sensors. temperature; In addition, they are resistant to water (they are only resistors after all) and they work at any voltage. They are difficult to spoil due to their simplicity and are incredibly accurate in measurements. For example, a 10 KΩ thermistor (value nominal, taken at 25 ° C as a standard reference) can measure temperature with a margin of error of ± 0.25 ° C (assuming that the analog-digital converter is accurate enough too). However, they do not usually withstand temperatures beyond 100 and a few degrees, and its time constant (that is, the seconds that the thermistor needs to reduce the difference between its temperature by 63% initial and final) is normally longer than ten seconds.

To measure the resistance of a thermistor or temperature sensor you can use a multimeter, such as any other resistance. The value we obtain will depend on the temperature of where we are.

If what we want is to measure the temperature itself with a plate Arduino, we must first measure with it the resistance of the thermistor, and from she deduce the corresponding temperature. But our Arduino board doesn’t have a built-in resistance meter, so, as we already did with the photoresistors, we will have to use the analog inputs of the board to detect voltage variations and deduce from these the desired value of the voltage-current resistance. Thus, the connection diagram is identical to the one we already use with photoresistors (and photodiodes): we must connect one terminal of the thermistor to the power (for example, the 5V pin of the Arduino board) and the other connect it to a series to a terminal of a fixed value resistor (which will act as a “pulldown” resistor); the other terminal of this “pull-down” resistor must be connected to ground. In addition, we must connect an analog input from our Arduino board to an intermediate point between both resistors to obtain a reading of the drop in potential between that point and ground.

By means of the circuit just described, when we detect that this voltage measured is increasing, we can deduce, by pure Ohm’s Law, that the resistance of the NTC thermistor(temperature sensor) is decreasing and therefore the temperature is increasing (and vice versa: if the voltage decreases, the resistance increases and the temperature decreases as well). The exact relationship between the measured voltage and the resistance of the thermistor can be calculated in the same way that we already saw when we study photoresistors, using the formula

**V _{med} = (R_{pull} / (R_{pull }+ R_{termistor})) · V_{source}**

We also know that, in reality, Vmed is not the voltage with which we work on our Arduino board, because it always uses a converter analog-digital with which it performs a “mapping”. This mapping converts the values analogs read (which can oscillate between 0 V and 5V if we assume that the voltage supplied by the source is 5V) to digital values (ranging between 0 and 1023). These digital values are what the Arduino board actually understands and with those that we will work on in our sketches. Converting from analog values to digital can be expressed by the same rule of proportionality that we saw with the photoresistors:

**V _{converted} = V_{med}x1023/5**

From here, just as we did with them, if we substitute this expression in the formula of the previous paragraph, and we clear from there R_{termistor }we arrive at the following expression:

** R _{termistor }= (R_{pull}1023 / V_{converted}) – R_{pull}**

This allows us to finally know what is the current value of the thermistor resistance starting from the digitized voltage obtained by the Arduino board. The above expression shows, as we already knew, that R_{termistor} is inversely proportional to V_{converted}.

But what value does R_{pull} have to have? The most commonly used value for the pull-down resistance that accompanies our thermistor is 10 KΩ, although sometimes 1KΩ is also used. Both are widely used values, but if we want to have greater control of the sensitivity of the thermistor, we would have to choose its value with a little more discretion. To do this, the procedure would be to substitute in the same already known formula V_{med} = (R_{pull} / (R_{pull} + R_{termistor})) V_{source }different values concrete R-thermistor numerical values corresponding to known temperatures (this is you can check in the datasheet equivalency table) and choose a value determined of R_{pull}: observing what values of V_{med} we are obtaining we can choose the R_{pull} value that allows us to have a wider range of V_{med} without saturating it.

The next natural step, once the resistance value of the thermistor, would be to find out what temperature it corresponds to. The easiest way to achieve this is to consult the equivalence table that always comes in the datasheet, where for certain values of Rtermistor it is already specified directly the corresponding temperature.

This system will be good for us if all we want is to design a circuit that makes quick comparisons like “if the temperature is below such do this and if it is superior to such do the other ”. If what we want, however, is to obtain the values accurate and real temperature values, we are fortunate to have equation mathematics that does this to a very good approximation (in fact, it achieves errors of only ± 0.02 centigrade in a range of 100 centigrade).

**Steinhart-Hart equation: **

1/T= A + B · ln(R) + C · (ln(R)^{3}, where R is the value in ohms of the thermistor in a given moment, T is the temperature measured in degrees Kelvin (one degree Kelvin is equal to one centigrade + 273.15) and A, B and C are coefficients that are different depending on the type and model of the thermistor (and that they are valid only for a certain temperature range, specified in the datasheet).

However, as this formula is somewhat complex and requires knowledge of the value of various coefficients that we may not know, in general, we can use a simplified equation:

**1/T = 1/T _{0} + 1/B x ln(R/R_{0})**

where T_{0} is the call nominal temperature (almost always 25 ° C = 298.15 K), R_{0} is the resistance of the thermistor at that temperature (the so-called “nominal resistance”, data available in the datasheet) and B is the only coefficient we need to know, which can be consulted in the datasheet always.

**thermistor or Temperature sensor** **with Arduino:**

I connected one terminal of the thermistor with 5V and the other terminal of the thermistor I connected with pull-down resistor and the other terminal of the resistor I connected to the ground. For analog value receiving, I take a wire from the middle of the thermistor and pull-down resistor and connect with Arduino A0 as you can see in below circuit diagram.

**Thermistor Sensor circuit diagram**

**Thermistor Sensor** **Programming****:**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <math.h> float A = 1.009249522e-03, B = 2.378405444e-04, C = 2.019202697e-07; float T,logRt,Tf,Tc; float Thermistor(int Vo) { logRt = log(10000.0*((1024.0/Vo-1))); T = (1.0 / (A + B*logRt + C*logRt*logRt*logRt)); // Stein-Hart equation Tc = T - 273.15; // Kelvin to Celcius Tf = (Tc * 1.8) + 32.0; // Kelvin to Fahrenheit return T; } void setup(){ Serial.begin(9600); } void loop() { Serial.print("Temperature: "); Serial.print((Thermistor(analogRead(0)))); Serial.println("Kelvin to Celcius: "); Serial.print((Tc)); Serial.print(" C ;"); Serial.println("Kelvin to Fahrenheit: "); Serial.print((Tf)); Serial.print(" F"); delay(1000); } |