Menu
CoddyTech

Thermistor Temperature

Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 20 of 24.

A thermistor is a resistor that changes with temperature. On this module (an NTC type) the OUT pin's voltage falls as it warms: analogRead() gives about 512 at 25 degrees C.

The reading does not fall in a straight line, so map() will not do. The beta equation turns it into degrees. BETA comes from the part's data sheet (3950 here), and log() is a maths function the board has built in. You do not need to follow the maths: copy the line as it is.

const float BETA = 3950;

float celsius = 1 / (log(1 / (1023.0 / reading - 1)) / BETA + 1.0 / 298.15) - 273.15;

Keep the .0 in 1023.0. 1023 / reading on two whole numbers drops the fraction, and the answer comes out wrong by many degrees.

challenge icon

Challenge

Medium

The thermistor module is on A0. Print the temperature:

  • turn the reading into degrees C with the beta equation
  • print it with Serial.println(), twice a second

Press Run, change the temperature on the board, then Check.

Try it yourself

const float BETA = 3950;  // the thermistor's beta value

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

void loop() {
  int reading = analogRead(A0);
  // turn the reading into degrees C and print it
  delay(500);
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Displays and Sensors

Practice on your own: Arduino playground