Arduino Thermistor Guide: Easy Circuit & Code Walkthrough

In this tutorial, we’ll guide you on how to set up a thermistor with Arduino to create a basic thermometer. The schematic, breadboard illustration, and example code provided will make it easy and straightforward to get your thermistor working.

Parts Needed

Step 1: Understand the Thermistor

Our thermistor has the following parameters:

  • T0: 25°C
  • RT0: 10,000 Ω
  • B: 3977 K

These values are found in the datasheet provided by the thermistor manufacturer. Check out this example datasheet for a thermistor from Vishay.

T0 is the reference temperature of the thermistor. For most thermistors, this is 25°C.

RT0 is the resistance of the thermistor at the reference temperature (which is commonly 25°C).

The B value, also known as the “beta value” or “B coefficient”, of the thermistor gives you insight into how the resistance changes with temperature. You’ll need this value in order to calculate the temperature of the thermistor.

Step 2: Connect the Arduino Thermistor Circuit

To connect a thermistor to an Arduino, connect it in series with a resistor between 5V and GND. Then connect the middle connection between the two to an analog input pin on the Arduino.

Arduino thermistor schematic

Here’s how you can connect a thermistor and resistor to an Arduino by using a breadboard and some cables:

Arduino thermistor circuit connected on a breadboard

Step 3: Upload the Arduino Thermistor Code

This Arduino code shows you how to read the voltage across the thermistor, convert it into resistance, and use that to calculate the temperature around the thermistor.

It then prints out the temperature value in Celcius, Kelvin, and Fahrenheit to the Serial Monitor.

Upload the complete code:

// Thermistor parameters from the datasheet
#define RT0 10000
#define B 3977

// Our series resistor value = 10 kΩ
#define R 10000 

// Variables for calculations
float RT, VR, ln, TX, T0, VRT;

void setup() {
 // Setup serial communication
 Serial.begin(9600);
 // Convert T0 from Celsius to Kelvin
 T0 = 25 + 273.15;
}

void loop() {
 // Read the voltage across the thermistor
 VRT = (5.00 / 1023.00) * analogRead(A0);
 
 // Calculate the voltage across the resistor
 VR = 5.00 - VRT;

 // Calculate resistance of the thermistor
 RT = VRT / (VR / R);
 
 // Calculate temperature from thermistor resistance
 ln = log(RT / RT0);
 TX = (1 / ((ln / B) + (1 / T0)));

 // Convert to Celsius
 TX = TX - 273.15;
 
 Serial.print("Temperature: ");
 // Display in Celsius
 Serial.print(TX); 
 Serial.print("C\t");
 
 // Convert and display in Kelvin
 Serial.print(TX + 273.15);
 Serial.print("K\t");

 // Convert and display in Fahrenheit
 Serial.print((TX * 1.8) + 32);
 Serial.println("F");
 
 delay(500);
}

Step 4: Monitor the Temperature

Open the Serial Monitor from the Arduino IDE by clicking the magnifying glass icon or using the keyboard shortcut Ctrl + Shift + M (Windows/Linux) or Cmd + Shift + M (Mac). Set the baud rate in the Serial Monitor to 9600 (or the same value as in the Serial.begin() function in the code).

In the serial monitor window, you’ll be able to see the temperature values in Celsius, Kelvin, and Fahrenheit. The values will refresh every 500 milliseconds.

Try heating the thermistor with your fingers to see the temperature change.

Example output to expect in the Serial Monitor:

Temperature: 25.00C 298.15K 77.00F
Temperature: 24.89C 298.04K 76.80F
Temperature: 26.12C 299.27K 79.02F
Temperature: 27.38C 300.53K 81.28F
Temperature: 27.50C 300.65K 81.50F
Temperature: 26.80C 299.95K 80.24F
Temperature: 25.78C 299.93K 78.40F
Temperature: 25.10C 298.25K 77.18F

Conclusion

You’ve successfully set up a thermometer using a thermistor with Arduino! This setup can be integrated into larger projects or used standalone to monitor temperature in any desired setting. Always refer to the thermistor datasheet for any component-specific information. Happy tinkering!

More Arduino Tutorials

Source