Arduino Thermistor Tutorial

Thermistors are used to measure temperature. They are compensated with a formula which needs some constants from the manufacturer's data sheet to convert the resistance into a temperature. They can be very accurate - more accurate by magnitudes than an IC temperature sensor - if used according to the data sheet.

A thermistor is a resistor

Almost all resistors show a shift with temperature. Most lower their resistance as the temperature increases. That is called a negative temperature coefficient or NTC. Themistors are designed to bring out the worst of this behavior. And they do it in a very predictable way. Because they are predictable, you can expect the same reading at the same temperature each time.

The circuit consists of a thermistor, a sense resistor, and the Arduino Uno. There is a capacitor added across the sense resistor that helps steady the readings. The thermistor is not insulated, and not particularly waterproof, so don't get it wet or in contact with other parts. A thin coat of epoxy will solve that, but will slow the response time of the thermistor a little.

Curves and coefficients

Typical thermistor temperature vs. resistance curve.
Typical Thermistor Curve

Thermistors generally come with a datasheet and response curves. If you have that datasheet for your thermistor, you can plug those curves into an equation along with the resistance of the thermistor to get very accurate temperature readings.

As you may see from the curve, the thermistor is very linear between about 0°C and 50°C, and that may be good enough for an indoor thermostat, where the temperature varies by less than 10 degrees all year long. If you are doing something like controlling a critical process it is just not accurate enough. You must work the data to get the most accurate temperature you can from the thermistor.

Our thermistor is a Vishay NTCLE100E3104JB0, available on ebay or at mouser.com for a few cents each. A datasheet is available on Mouser.com, or at Rice University. The values we want from it are A1, B1, C1 and D1. They plug into the program as constants.


// Steinhart-Hart data:
const double A1_const = 0.003354016;
const double B1_const = 0.0002460382;
const double C1_const = 0.000003405377;
const double D1_const = 0.000000103424;

// Thermistor's 25 degree resistance.
double Rt = 100000;

// Sense resistor resistance.
double resistance = 50000;

// Thermistor on pin A0.
int thermistor = A0;

double getCalculatedTemperature(int value)
{
  // Determine the voltages.
  double r_volts = 5.0 * value / 1024;
  double t_volts = 5.0 - r_volts;
  
  // Determine the resistance of the thermistor.
  double R = resistance * (t_volts / r_volts);

  // Steinhart-Hart equation.
  double log_r = log(R / Rt);
  double b_val = B1_const*log_r;
  double c_val = C1_const*log_r*log_r;
  double d_val = D1_const*log_r*log_r*log_r;
  double K = 1 / (A1_const + b_val + c_val + d_val);
  return K - 273.15;
}

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

  // Throw away one analog value. Things may have changed.
  analogRead(thermistor);
}

void loop() {

  // Read the real value and convert it to a temperature.
  int value = analogRead(thermistor);
  double temp = getCalculatedTemperature(value);
  Serial.print(temp);
  temp = (temp * 1.8)+32;
  Serial.print(" C	");
  Serial.print(temp);
  Serial.println(" F");
  
  delay(5000);
}
    

Different Thermistors

You can use any NTC thermistor you would like, as long as you adjust the 'A1_const' through 'D1_const' and the thermistor's 'Rt' (25°C resistance). If you use a different sense resistor, change the 'resistance' constant accordingly. Better resolution is had from a resistor of around 50k to 75k. It should be at least 1% and even 0.1% if you are going to use the temperature for something important, like process control.

Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.