# Thermistor

A thermistor is a thermal resistor - a resistor that changes its resistance with temperature. Technically, all resistors are thermistors - their resistance changes slightly with temperature - but the change is usually very small and difficult to measure. Thermistors are made so that the resistance changes drastically with temperature so that it can be 100 ohms or more of change per degree!

There are two kinds of thermistors, NTC (negative temperature coefficient) and PTC (positive temperature coefficient). In general, you will see NTC sensors used for temperature measurement. PTC's are often used as resettable fuses - an increase in temperature increases the resistance which means that as more current passes thru them, they heat up and 'choke back' the current, quite handy for protectingcircuits!

from the ELEGOO superkit documentation A resistor that has a strong change of resistance with temperature.  This one goes down with increasing temperature.  It is a non directional device like a resistor so it does not matter which lead is + or - The thermistor is an analog device.  We will set up a voltage divider to measure the change in resistance of the thermistor.  We will be measuring the voltage on a 10K ohm resistor.  When the resistance of the thermistor decreases the total current in the circuit will increase, increasing the voltage measured on the 10K resistor.  In this arrangement the voltage we measure will increase with increasing temperature.

### Calculating the Temperature

From the Elegoo instructions we are given this relationship for voltage to temperature calculation:

double tempK = log(10000.0 * ((1024.0 / tempReading -1)));  //convert using the log scale
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK ))  //convert to temperature in K

* tempK );
float tempC = tempK - 273.15;   //conversion to C
float tempF = (tempC * 9.0)/ 5.0 + 32.0;// conversion to F

We will implement this in Arduino code

#### Arduino Code

```void setup() {
// put your setup code here, to run once:

Serial.begin(9600);
Serial.print ("hello");
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println ("loop");

int tempPin = A0;

double tempK = log(10000.0 * ((1024.0 / tempReading - 1))); //convert using the log scale
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK ))  //convert to temperature in K

* tempK );
float tempC = tempK - 273.15;   //conversion to C
float tempF = (tempC * 9.0) / 5.0 + 32.0; // conversion to F
Serial.print ("temperature =  ");
Serial.print (tempF);
Serial.println ("  degrees  F");

delay(200);
}```
Back to the course