Thermistors are simple, inexpensive, and accurate components that make it easy to get temperature readings for your projects. Remote weather stations, home environment monitoring systems, and equipment control and protection circuits are applications where a thermistor would be ideal. They are analog sensors, so the code is really simple compared to digital temperature sensors which require special libraries and lots of code. In this article, I’ll explain how thermistors work, then I’ll show you how to set up a basic thermistor circuit with an Arduino that will output temperature readings to the serial monitor or to an LCD.

How a Thermistor Works

Thermistors are variable resistors that change their resistance with temperature. They are classified by the way their resistance responds to temperature changes. In Negative Temperature Coefficient (NTC) thermistors, the resistance decreases with an increase in temperature. In Positive Temperature Coefficient (PTC) thermistors, the resistance increases with an increase in temperature.

NTC thermistors are the most common, and the type we will be using in this tutorial. NTC thermistors are made from a semiconducting material (such as a metal oxide or ceramic) that has been heated and compressed to form a conducting material that is sensitive to temperature. The semiconducting material contains charge carriers that allow current to flow through it. High temperatures cause the semiconducting material to release more charge carriers. In NTC thermistors made from ferric oxide, electrons are the charge carriers. In nickel oxide NTC thermistors, the charge carriers are electron holes.

Arduino Thermistor Temperature Sensor Voltage Divider Circuit

A Basic Thermistor Circuit

Let’s begin with a very basic thermistor circuit just to see its fundamental operation, so you can apply it to other projects later.

We need to measure the resistance of the thermistor to calculate the temperature. However, the Arduino can’t measure resistance directly, it can only measure voltage. The basic thermistor circuit uses a voltage divider to read a voltage at a point between two known resistors. This voltage reading is converted to resistance using Ohm’s law, I = V / R; or R = V / I, where I is current, V is voltage, and R is resistance. The analog to digital converter on the Arduino then takes that voltage reading and converts it to a number between 0 and 1023:

Analog to Digital Converter (ADC) reading = (Voltage at Pin / 5V) * 1023

Therefore, a zero voltage reading at an analog input pin is converted to the number 0, and a 5V reading at an analog input pin is converted to the number 1023. We use this number in the program to calculate the temperature. Connect the thermistor and resistor to your Arduino like this:

Arduino Thermistor Basic Set Up Diagram

The value of the resistor should be equal to the magnitude of resistance of your thermistor. In this case, the resistance of the thermistor is 100K Ohms, so the resistance of the resistor is also 100K Ohms. The manufacturer of the thermistor may give you this information, but if not, you can use a multimeter to find out. If you don’t have a multimeter, you can make an Ohm meter with your Arduino by following our Arduino Ohm Meter tutorial. You will want to take the magnitude of the Ohm meter readings. For example, if your thermistor resistance is 34,000 Ohms, it is a 10K thermistor. If your thermistor resistance is 340,000 Ohms, it is a 100K thermsitor.

Code for Serial Monitor Output of Temperature Readings

After connecting the circuit above, upload this code to your Arduino to output the temperature readings to the serial monitor:

#include <math.h>

double Thermistor(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1))); 
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;          
 Temp = (Temp * 9.0)/ 5.0 + 32.0; 
 return Temp;
}

void setup() {
 Serial.begin(9600);
}

void loop() {             
  int val;                
  double temp;            
  val=analogRead(0);      
  temp=Thermistor(val);   
  Serial.print("Temperature = ");
  Serial.print(temp);   
  Serial.println(" F");
  delay(1000);            
}

This program uses the Steinhart-Hart equation to convert the linear ADC voltage readings to temperature.

To display the temperature in degrees Celsius, just comment out line 8 by inserting two forward slashes (“//”) at the beginning of the line.

This program will display Celsius and Fahrenheit at the same time:

#include <math.h>

double ThermistorF(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1))); 
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;          
 Temp = (Temp * 9.0)/ 5.0 + 32.0; 
 return Temp;
}

double ThermistorC(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1))); 
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;          
 return Temp;
}

void setup() {
 Serial.begin(9600);
}

void loop() {             
  int valF, valC;                
  double tempF, tempC;            
  valF=analogRead(0);      
  tempF=ThermistorF(valF);   
  valC=analogRead(0);      
  tempC=ThermistorC(valC); 
  
  Serial.print("Temperature = ");
  Serial.print(tempF);   
  Serial.print(" F; ");
  Serial.print(tempC);   
  Serial.println(" C");
  delay(1000);            
}

Code for LCD Output of Temperature Readings

To output the temperature readings to a 16X2 LCD, follow our tutorial, How to Set Up an LCD Display on an Arduino, then upload this code to the board:

#include <math.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

double Thermistor(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1))); 
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;          
 Temp = (Temp * 9.0)/ 5.0 + 32.0; 
 return Temp;
}

void setup() {
 lcd.begin(16, 2);
}

void loop() {             
  int val;                
  double temp;            
  val=analogRead(0);      
  temp=Thermistor(val);   
  lcd.print("Temp = ");
  lcd.print(temp);   
  lcd.print(" F");
  delay(1000);            
  lcd.clear();
}

Here is the video tutorial for this project:

Well, that’s about it. Just leave a comment below if you have any questions about these projects. And if you like our articles here at Circuit Basics, leave your email address at the top of this post and we will let you know when we publish new articles. Also, feel free to share this if you know anyone that would find it helpful!

Need an easy-to-use way to design circuits and layout PCBs?