In this article I will explain how to use a thermistor. what is it a Thermistor? A thermistor is a type of resistor whose resistance is dependent on temperature. There are two types of thermistor:

1. PTC (Positve Temperature Coefficent), resistance increases as temperature rises
2. NTC (Negative Temperature Coefficent), resistance decreases as temperature rises
In this case I use NTC.

Since the thermistor is a variable resistor, we’ll need to measure the resistance before we can calculate the temperature. However, the Arduino can’t measure resistance directly, it can only measure voltage.
The Arduino will measure the voltage at a point between the thermistor and a known resistor. This is known as a voltage divider. The equation for a voltage divider is: $V_{out}=V_{in} \times (\frac{R2}{R1+R2})$

In terms of the voltage divider in a thermistor circuit, the variables in the equation above are: $V_{out}: \ Voltage \ between \ thermistor \ and \ known \ resistor\\ V_{in}: \ V_{cc}, \ i.e. \ 5V\\ R1: \ Known \ resistor \ value \\ R2: \ Resistance \ of \ thermistor$

This equation can be rearranged and simplified to solve for R2, the resistance of the thermistor: $R2= R1 \times (\frac{V_{in}}{V_{out}} - 1)$

Finally, the Steinhart-Hart equation is used to convert the resistance of the thermistor to a temperature reading.


#include <LiquidCrystal_I2C.h>

int ThermistorPin = A0;

int Vo;

float R1 = 10000;

float logR2, R2, T, Tc, Tf;

float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

LiquidCrystal_I2C lcd(0x3F, 20, 4);

void setup() {

//Serial.begin(115200);

lcd.begin();

lcd.backlight();

lcd.clear();

}

void loop() {

R2 = R1 * (1023.0 / (float)Vo - 1.0);

logR2 = log(R2);

T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));

Tc = T - 273.15;

Tf = (Tc * 9.0)/ 5.0 + 32.0;

/*Serial.print("Temperature: ");

Serial.print(Tf);

Serial.print(" F; ");

Serial.print(Tc);

Serial.println(" C");*/

lcd.setCursor(0,0);

lcd.print("Temp: ");

lcd.print(Tf);

lcd.print("\337F");

lcd.setCursor(0,1);

lcd.print("Temp: ");

lcd.print(Tc);

lcd.print("\337C");

delay(500);

}

Output: