Vernier Software and Technology
Vernier Software & Technology
Arduino and Vernier Sensors

Calibrating Thermistor Temperature Sensors

Two of the most popular standard Vernier analog (BTA) sensors are the Stainless Steel Temperature Probe and the Surface Temperature Sensor. These sensors are electrically the same, but packaged differently. The thermistor on the Stainless Steel Temperature Probe is housed in a rugged stainless steel body, while the thermistor in the Surface Temperature Sensor is left exposed to give a faster response time. Both sensors use thermistors in series with a fixed resistor in a voltage divider situation. The voltage at the point between the fixed resistor and the thermistor can be measured by the Arduino and used to determine temperature.

The relationship between voltage and temperature is nonlinear, but it can be approximated within one degree Celsius using the Steinhart-Hart equation – a third order polynomial involving logarithmic calculations.

Temperature in Celsius = 1 / {A + B[ln(R)] + C[ln(R)]^3} – 273.15

where A =0.00102119, B = 0.000222468, C = 1.33342E-7, and R = the resistance of the thermistor. You can calculate the resistance of the thermistor using the equation:

{R_{T}} = ({\frac{V_{out}R_{1}}{V_{in}-V_{out}}})

Since both the Vernier Arduino Interface Shield and the Analog Protoboard Adapter were built with 15K precision resistors and the Arduino delivers a maximum voltage of 1024, the equation becomes:

Resistance = (Count*15000 / (1024-Count))

The sample sketch, VernierTutorialThermistor, uses this technique. This sketch assumes the temperature sensor is plugged into the Analog 2 port on the Vernier Arduino Interface Shield or connected to an Analog Protoboard Adapter wired to Arduino pin A2 as explained in the Connecting Vernier Sensors to the Arduino Using a Breadboard section. Note that the Steinhart-Hart equations have been put into a separate function called thermistor(). You will need to include the math.h library at the beginning of your sketch in order to access the natural log function.

/* VernierTutorialThermistor (v2017)
 * This sketch reads the temperature from a Vernier Stainless
 * Steel Temperature Probe or a Surface Temperature Sensor once
 * every half second.
 * We use the Steinhart-Hart equation (in the function
 * Thermistor) to calculate temperature from the raw voltage
 * reading. Because of the use of log functions in the
 * Steinhart-Hart equation, this sketch requires the math.h
 * library.
 * Plug the temperature sensor into the Analog 2 port on the 
 * Vernier Arduino Interface Shield or into an Analog 
 * Protoboard Adapter wired to Arduino pin A2.

#include <math.h> //include library for log function

float rawCount; //create global variable for reading from A/D converter (0-1023)
float temperature; //create global variable for temperature in Celsius

void setup() {
  Serial.begin(9600); //setup communication to display

void loop() {
  rawCount=analogRead(A2); //read one data value (0-1023)
  temperature=thermistor(rawCount); //calculate temperature
  Serial.println(temperature,1); // display temperature to one decimal)                               
  delay(500); //wait half second

//This function calculates temperature from raw count
float thermistor(int raw) {
  float resistor=15000; //initialize value of fixed resistor in Vernier shield
  float resistance; //create local variable for resistance
  float temp; //create local variable for temperature

  resistance=log(resistor*raw/(1024-raw)); //calculate resistance
  temp = 1 / (0.00102119 + (0.000222468 * resistance) + (0.000000133342 * resistance * resistance * resistance)); //calculate temperature using the Steinhart-Hart equation
  temp = temp - 273.15; //Convert Kelvin to Celsius                      
  return temp; //return the temperature

If you want to try building your own temperature sensor, see our STEM project Temperature Sensor.



Vernier Engineering Contest

Vernier recognizes instructors for creative uses of Vernier sensors to introduce engineering concepts and/or practices. Vernier Engineering Award »

Go to top