How to Use Temperature Sensors on the Arduino - Ultimate Guide to the Arduino #37

### How to Set Up and Program a Thermistor with Arduino: A Step-by-Step Guide

Thermistors are versatile components that can measure temperature or control devices based on temperature changes. In this guide, we’ll walk you through how to set up and program a thermistor using an Arduino board. We'll also show you how to use the readings from the thermistor to control an LED.

---

#### What Is a Thermistor?

A thermistor is a type of resistor whose resistance changes with temperature. Unlike fixed resistors, thermistors are variable, meaning their resistance decreases (for Negative Temperature Coefficient, NTC) or increases (for Positive Temperature Coefficient, PTC) as the temperature rises. For most Arduino projects, we use NTC thermistors.

The resistance of a thermistor at 25°C is specified by its R25 value. The thermistor used in this guide has an R25 value of 10 kilo ohms and a beta value of 3435.

---

#### Setting Up the Circuit

To measure the temperature using a thermistor, we need to create a voltage divider circuit. Here's how:

1. **Components Needed**:

- Thermistor (10kΩ NTC)

- Resistor (10kΩ, same as R25 value of your thermistor)

- Arduino board

- Breadboard and jumper wires

2. **Circuit Connection**:

- Connect one lead of the thermistor to 5V.

- Connect the other lead of the thermistor to a resistor (10kΩ).

- The free end of the resistor connects to ground (GND).

- The middle point of the voltage divider (between the thermistor and resistor) connects to an analog input pin (A0) on your Arduino board.

**Note**: Ensure that the resistor value matches the R25 value of your thermistor for accurate readings.

---

#### Understanding the Steinhardt-Hart Equation

The relationship between resistance and temperature for a thermistor is not linear—it’s logarithmic. To calculate the exact temperature from the thermistor's resistance, we use the Steinhardt-Hart equation:

\[

\frac{1}{T} = a \ln(R) + b (\ln(R))^3 + c

\]

Where:

- \( R \) is the resistance of the thermistor.

- \( T \) is the temperature in Kelvin.

- \( a, b, c \) are constants specific to the thermistor.

To find these constants, we need three resistance values at different temperatures. These can be obtained from your thermistor's datasheet or measured using a multimeter. For our 10kΩ NTC thermistor:

- At -40°C: \( R = 190,953 \Omega \)

- At 25°C: \( R = 10,000 \Omega \)

- At 105°C: \( R = 858.33 \Omega \)

Using an online calculator, we find the constants:

- \( a = 0.00749146 \)

- \( b = 0.0203924 \)

- \( c = -0.0031217 \)

---

#### Writing the Arduino Sketch

Here’s the complete code for reading temperature from the thermistor and displaying it on the serial monitor:

```cpp

int thermistorPin = A0;

float R1 = 10000; // Value of resistor in voltage divider (same as R25)

float a = 0.00749146; // Steinhardt-Hart coefficient

float b = 0.0203924; // Steinhardt-Hart coefficient

float c = -0.0031217; // Steinhardt-Hart coefficient

void setup() {

Serial.begin(9600);

pinMode(5, OUTPUT); // LED control pin

}

void loop() {

int val = analogRead(thermistorPin); // Read voltage drop across thermistor

float R2 = (R1 * 1023) / (val - 1); // Calculate resistance of thermistor

// Apply Steinhart-Hart equation

float logR2 = log(R2);

float logR2Cube = pow(logR2, 3);

float TK = 1 / (a + b * logR2 + c * logR2Cube);

// Convert Kelvin to Celsius and Fahrenheit

float TC = TK - 273.15;

float TF = (TC * 9) / 5 + 32;

// Print temperature readings

Serial.print("Temperature: ");

Serial.println(TC);

Serial.println('C');

delay(500); // Wait for 500ms before next reading

// Control LED based on temperature

if (TC > 29) {

digitalWrite(5, LOW); // Turn off LED when temperature is above 29°C

} else {

digitalWrite(5, HIGH); // Turn on LED when temperature is below 29°C

}

}

```

---

#### Testing the Circuit

1. **Reading Temperature**:

- Open the serial monitor in Arduino IDE.

- The temperature reading should match your ambient temperature.

- Hold the thermistor to increase its temperature and observe the readings.

2. **Controlling the LED**:

- The LED will turn on when the temperature drops below 29°C and off when it exceeds 29°C.

- Test by heating or cooling the thermistor.

---

#### Applications of Thermistors

Thermistors are widely used in various applications, including:

- Over-temperature protection for motors and electronics.

- Temperature control in incubators, ovens, and plant monitors.

- Humidity and temperature sensing in IoT devices.

---

#### Next Steps

In the next video, we’ll explore another method to measure temperature using a digital sensor. If you’re interested in learning more about Arduino and electronics, check out the [3-in-1 Smart Car and IoT Learning Kit](#) from SunFounder, which includes everything you need to build projects like a remote-controlled car or a plant monitor.

---

By following this guide, you’ll be able to measure temperature using a thermistor and control devices based on temperature readings. Happy experimenting!

"WEBVTTKind: captionsLanguage: enforeign how to set up and program a thermistor thermistors are perfect for any project that needs to measure temperature or control things based on temperature we'll output temperature readings to the stereo monitor then make a temperature switch that controls an LED this is what a thermistor looks like it's pretty small and it kind of looks like a tantalum capacitor there are two leads but thermistors are non-polarized so there isn't a positive or negative lead they can be connected either way around thermistors are variable resistors to change their resistance when the temperature changes they're specified with a resistance value called the r25 value the r25 value is the resistance of the thermistor at 25 degrees Celsius it's a 10 kilo ohm thermistor so its resistance at 25 degrees Celsius is 10 kilo ohms thermistors are also specified by their temperature coefficient the coefficient can be either positive or negative in positive temperature coefficient thermistors the resistance increases with increasing temperature in negative temperature coefficient thermistors the resistance decreases with increasing temperature most thermistors use for Arduino projects are negative temperature coefficient thermistors so that's what I'll be discussing here since thermistors are variable resistors we can use a voltage divider circuit to measure the voltage drop across the thermistor as the temperature changes once we know the voltage drop across the thermistor we can use the voltage divider equation to calculate the resistance of the thermistor at each temperature here's how that will look when it's wired up to the Arduino here's the thermistor and here's the resistor one tricky thing about this circuit though is that you have to be sure that the resistor here is the same resistance as the r25 value of your thermistor for example if you have a 10 kilo ohm thermistor this resistor needs to be 10 kilo ohms if you have a 100 kilo ohm thermistor the resistor needs to be 100 kilo ohms as well the middle of the voltage divider is connected to analog pin a0 on the Arduino the other lead of the thermistor is connected to 5 volts and the other side of the resistor is connected to ground before we jump into the sketch you need a little background information about how a thermistor's resistance is related to temperature unfortunately it's not a simple linear relationship it's logarithmic the precise relationship is best modeled by a formula called the steinhardt heart equation the steinhardt heart equation describes the temperature resistance relationship with about 0.02 percent accuracy equation looks like this the formula solves for the inverse of temperature but we can rearrange it to solve for temperature R is the resistance of the thermistor at a particular temperature t a B and C are consonants that depend on the resistance tolerance and construction of the thermistor the math to calculate the constants is pretty Advanced but luckily there are online calculators that will do it for you the thermistor I'm going to use for this video is an mf52103 10 kilo ohm NTC thermistor with the plus or minus one percent tolerance if you're using the same type of thermistor that I am you can use the constant values I'm using but if yours is different I'm going to show you how to calculate them I found a good online calculator for the steinhardt heart coefficients all you need to do is input the resistance of the thermistor at three different temperatures if you don't have a data sheet for your thermistor you can use a Multimeter to measure its resistance at three different temperatures but I have the data sheet for my thermistor and it has a table of the resistances for a range of temperatures just need to know the beta value and the r25 value the beta value is something you need to get from the manufacturer the thermistor I'm using has an r25 value of 10 kilo ohms and a beta value of 3435 so let me scroll down here and find the resistance table here it is the First Column shows the temperature and the second column shows the resistance at that temperature it's best to use the lowest highest and middle temperatures the thermistor is rated for example if your thermistor is rated from -40 to 105 degrees Celsius you would use the resistances at -40 25 and 105 degrees the resistance of my thermistor at minus 40 degrees Celsius is 190 953 ohms I'm going to input that into the calculator at 25 degrees Celsius the resistance is 10 000 ohms so I'm going to input that in the calculator too it's actually already set at 25 degrees and 10 kilo ohms the resistance of my thermistor is 858.33 ohms at 105 degrees Celsius so input that too to run the calculator press the enter key now if you look at the graph over here this is plotting resistance on the y-axis and temperature on the x-axis the curve is logarithmic over here are the calculated steinhardt heart coefficients a b and c so now let's look at the sketch and we'll come back for these numbers later the center of the voltage divider is connected to Arduino pin a0 so I have an INT variable called thermistor pin to store that PIN number then we need a variable to store the value of the resistor in the voltage divider let's store it in the float variable called R1 I'm using a 10 kilo ohm thermistor so my R1 is 10 000 ohms if you're using 100 kilo ohm thermistor your R1 would be 100 kilo ohms now we declare some float variables for the calculations we're going to do R2 will hold the resistance of the thermistor after we calculate it with the voltage divider formula then we have log R2 which holds the natural log of R2 log R2 Cube holds the natural log of R2 raised to the third power TK will hold the current temperature in Kelvins TC will hold the current temperature in Celsius and TF which will hold the current temperature in Fahrenheit then we Define the values of the steinhardt coefficients and store them in fluid variables a b and c these numbers are taken from the steinhardt heart calculator I showed you earlier here's the a coefficient so that goes here here's the B value that goes here 's the C value and that goes here now down in the setup section we just need to initialize the serial monitor in the loop section we take an analog read of the thermistor pin and store the result in a local int variable called V out remember that analog read returns a value between 0 and 10 23. 0 corresponds to zero volts and 1023 corresponds to 5 volts this corresponds to the voltage drop across the thermistor so now we can convert that to the resistance of the thermistor so we use the voltage divider equation which has been rearranged to solve for R2 instead of V out we have R2 equals R1 times 1023 divided by V out minus 1. R2 is the resistance of the thermistor and R1 is the other resistor in the voltage divider 1023 is the input voltage of the voltage divider which is 5 volts and V out is the voltage drop across the thermistor the steinhardt equation uses the natural log of R2 to get the natural log of R2 we can use the log function with the name of the variable as the argument we start the result in the global float variable log R2 then we have to calculate the natural log of R2 raised to the third power to do that we can use the pow function the pal function takes two parameters the first parameter is the base and the second parameter is the exponent since we want to raise log R2 to the third power we have log R2 as the first argument and three is the second argument this is stored in the log R2 Cube variable here's where we do the steinhard heart equation math the steinhardt equation gives the temperature of the thermistor in degrees Kelvin so we store the result in the variable TK the equation is 1 divided by the a coefficient plus the B coefficient times the natural log of R2 plus the C coefficient times the natural log of R2 raised to the third power so this will give us the temperature of the thermistor in Kelvins but kelvins aren't very useful unless you're building a sensor for a physics or chemistry project so let's convert kelvins to degrees Celsius to do that we just subtract 273.15 from the temperature in Kelvins the result will be stored in the TC variable let's go a step further and convert the temperature in celsius to a temperature in Fahrenheit to do that we just multiply the temperature in celsius by 9. then divide by 5. and add 32. the result is stored in the TF variable now we just need to print the values to the serial monitor here I'm printing the word temperature equals than the TC variable which holds the temperature in Celsius replace this with TK or tkf if you want the temperature in kelvins or Fahrenheit then I use serial print line to print a letter C to show that the temperature is in Celsius lastly I added a delay of 500 milliseconds to slow the output down a bit okay so let's see what this looks like so here's my thermistor I have a glass thermometer here as a reference the temperature from the thermistor is reading about 26 degrees Celsius if you look at the glass thermometer you can see it's reading 27. so that's pretty close to the reading from the thermistor when I hold the thermistor you can see the temperature go up foreign to the ambient temperature when I Let Go alright so this is great if all you need to do is measure temperature but thermistors can also be used to control other devices for example you could place a thermistor near a motor to shut it off when it gets too hot or you could monitor the temperature inside of an incubator and turn on a heat lamp when the temperature gets too cold so now let's see how to control the arduino's output with the readings from a thermistor I'm going to demonstrate with an LED but any device that's controlled by a 5 volt signal can be used here the thermistor is connected the same way as in the last example the center of the voltage divider connects to analog pin a0 the other side of the thermostat connects to 5 volts and the other side of the resistor connects to ground the LED's anode is connected to digital pin 5 by a current limiting resistor and the LED's cathode is connected to ground to make the diagram simpler I have the LED and the resistor in the voltage divider sharing the same ground now let's look at the sketch in this sketch we're going to make the LED turn off when the temperature passes above a certain threshold the LED will turn on when the temperature drops back below the threshold most of the sketch is the same as before but now we need a variable to store the LED pin number which is pin 5. all of these variables for the temperature calculations remain the same in the setup we're still going to send the temperature readings to the serial monitor but we're also going to switch digital pin 5 on and off so we need to initialize it as an output with the pinwood function in the loop section all of this is the same we take a voltage reading from the thermistor pin convert it to a resistance and use the steinhardt equation to give us the temperature of the thermistor then we convert the temperature in kelvins to Celsius and Fahrenheit and that gets printed to the serial monitor once we have the temperature data to work with we can use it to control the LED pin a simple if-else statement is enough to do that we can use the condition to determine what happens when the temperature rises above a certain temperature here if the temperature in Celsius is greater than 29 degrees the program will enter this block where we digital write the LED pin low else in other words if the temperature is not greater than 29 we enter this block and write the LED pin High so the LED will be on when the temperature is below 29 degrees Celsius and will be off when the temperature goes above 29 degrees Celsius let's check this out so initially the LED is on you can see the temperature on the stereo monitor is reading about 25 degrees Celsius when I hold on to the thermistor to warm it up you can see the temperature increases quickly and once we pass 29 degrees the LED turns off when the thermistor cools down below 29 degrees the LED turns back on in the next video we're going to learn about another way to measure temperature but this time with the digital humidity and temperature sensor foreign the three in one smart car and iot learning kit from Sun founder is a Hands-On all included Electronics kit that is perfect for anyone who wants to learn how to master the Arduino the kit comes with an Arduino 22 different sensors and modules breadboards jumper wires and everything else you need to build a bunch of fun and interesting projects learn about robotics by building a remote controlled smart car that can be controlled with an infrared remote controller or drive on its own and avoid obstacles or fall on the line learn about the internet of things with a project that lets you monitor the temperature humidity and light level of a room from an app on your smartphone and build a plant monitor that tracks the temperature humidity light intensity and soil moisture and displays it on your smartphone so you can keep your plants water remotely it's a super cool kit and I have lots of fun building all the projects in it so click the link in the description below to order the kit from Sun founderforeign how to set up and program a thermistor thermistors are perfect for any project that needs to measure temperature or control things based on temperature we'll output temperature readings to the stereo monitor then make a temperature switch that controls an LED this is what a thermistor looks like it's pretty small and it kind of looks like a tantalum capacitor there are two leads but thermistors are non-polarized so there isn't a positive or negative lead they can be connected either way around thermistors are variable resistors to change their resistance when the temperature changes they're specified with a resistance value called the r25 value the r25 value is the resistance of the thermistor at 25 degrees Celsius it's a 10 kilo ohm thermistor so its resistance at 25 degrees Celsius is 10 kilo ohms thermistors are also specified by their temperature coefficient the coefficient can be either positive or negative in positive temperature coefficient thermistors the resistance increases with increasing temperature in negative temperature coefficient thermistors the resistance decreases with increasing temperature most thermistors use for Arduino projects are negative temperature coefficient thermistors so that's what I'll be discussing here since thermistors are variable resistors we can use a voltage divider circuit to measure the voltage drop across the thermistor as the temperature changes once we know the voltage drop across the thermistor we can use the voltage divider equation to calculate the resistance of the thermistor at each temperature here's how that will look when it's wired up to the Arduino here's the thermistor and here's the resistor one tricky thing about this circuit though is that you have to be sure that the resistor here is the same resistance as the r25 value of your thermistor for example if you have a 10 kilo ohm thermistor this resistor needs to be 10 kilo ohms if you have a 100 kilo ohm thermistor the resistor needs to be 100 kilo ohms as well the middle of the voltage divider is connected to analog pin a0 on the Arduino the other lead of the thermistor is connected to 5 volts and the other side of the resistor is connected to ground before we jump into the sketch you need a little background information about how a thermistor's resistance is related to temperature unfortunately it's not a simple linear relationship it's logarithmic the precise relationship is best modeled by a formula called the steinhardt heart equation the steinhardt heart equation describes the temperature resistance relationship with about 0.02 percent accuracy equation looks like this the formula solves for the inverse of temperature but we can rearrange it to solve for temperature R is the resistance of the thermistor at a particular temperature t a B and C are consonants that depend on the resistance tolerance and construction of the thermistor the math to calculate the constants is pretty Advanced but luckily there are online calculators that will do it for you the thermistor I'm going to use for this video is an mf52103 10 kilo ohm NTC thermistor with the plus or minus one percent tolerance if you're using the same type of thermistor that I am you can use the constant values I'm using but if yours is different I'm going to show you how to calculate them I found a good online calculator for the steinhardt heart coefficients all you need to do is input the resistance of the thermistor at three different temperatures if you don't have a data sheet for your thermistor you can use a Multimeter to measure its resistance at three different temperatures but I have the data sheet for my thermistor and it has a table of the resistances for a range of temperatures just need to know the beta value and the r25 value the beta value is something you need to get from the manufacturer the thermistor I'm using has an r25 value of 10 kilo ohms and a beta value of 3435 so let me scroll down here and find the resistance table here it is the First Column shows the temperature and the second column shows the resistance at that temperature it's best to use the lowest highest and middle temperatures the thermistor is rated for example if your thermistor is rated from -40 to 105 degrees Celsius you would use the resistances at -40 25 and 105 degrees the resistance of my thermistor at minus 40 degrees Celsius is 190 953 ohms I'm going to input that into the calculator at 25 degrees Celsius the resistance is 10 000 ohms so I'm going to input that in the calculator too it's actually already set at 25 degrees and 10 kilo ohms the resistance of my thermistor is 858.33 ohms at 105 degrees Celsius so input that too to run the calculator press the enter key now if you look at the graph over here this is plotting resistance on the y-axis and temperature on the x-axis the curve is logarithmic over here are the calculated steinhardt heart coefficients a b and c so now let's look at the sketch and we'll come back for these numbers later the center of the voltage divider is connected to Arduino pin a0 so I have an INT variable called thermistor pin to store that PIN number then we need a variable to store the value of the resistor in the voltage divider let's store it in the float variable called R1 I'm using a 10 kilo ohm thermistor so my R1 is 10 000 ohms if you're using 100 kilo ohm thermistor your R1 would be 100 kilo ohms now we declare some float variables for the calculations we're going to do R2 will hold the resistance of the thermistor after we calculate it with the voltage divider formula then we have log R2 which holds the natural log of R2 log R2 Cube holds the natural log of R2 raised to the third power TK will hold the current temperature in Kelvins TC will hold the current temperature in Celsius and TF which will hold the current temperature in Fahrenheit then we Define the values of the steinhardt coefficients and store them in fluid variables a b and c these numbers are taken from the steinhardt heart calculator I showed you earlier here's the a coefficient so that goes here here's the B value that goes here 's the C value and that goes here now down in the setup section we just need to initialize the serial monitor in the loop section we take an analog read of the thermistor pin and store the result in a local int variable called V out remember that analog read returns a value between 0 and 10 23. 0 corresponds to zero volts and 1023 corresponds to 5 volts this corresponds to the voltage drop across the thermistor so now we can convert that to the resistance of the thermistor so we use the voltage divider equation which has been rearranged to solve for R2 instead of V out we have R2 equals R1 times 1023 divided by V out minus 1. R2 is the resistance of the thermistor and R1 is the other resistor in the voltage divider 1023 is the input voltage of the voltage divider which is 5 volts and V out is the voltage drop across the thermistor the steinhardt equation uses the natural log of R2 to get the natural log of R2 we can use the log function with the name of the variable as the argument we start the result in the global float variable log R2 then we have to calculate the natural log of R2 raised to the third power to do that we can use the pow function the pal function takes two parameters the first parameter is the base and the second parameter is the exponent since we want to raise log R2 to the third power we have log R2 as the first argument and three is the second argument this is stored in the log R2 Cube variable here's where we do the steinhard heart equation math the steinhardt equation gives the temperature of the thermistor in degrees Kelvin so we store the result in the variable TK the equation is 1 divided by the a coefficient plus the B coefficient times the natural log of R2 plus the C coefficient times the natural log of R2 raised to the third power so this will give us the temperature of the thermistor in Kelvins but kelvins aren't very useful unless you're building a sensor for a physics or chemistry project so let's convert kelvins to degrees Celsius to do that we just subtract 273.15 from the temperature in Kelvins the result will be stored in the TC variable let's go a step further and convert the temperature in celsius to a temperature in Fahrenheit to do that we just multiply the temperature in celsius by 9. then divide by 5. and add 32. the result is stored in the TF variable now we just need to print the values to the serial monitor here I'm printing the word temperature equals than the TC variable which holds the temperature in Celsius replace this with TK or tkf if you want the temperature in kelvins or Fahrenheit then I use serial print line to print a letter C to show that the temperature is in Celsius lastly I added a delay of 500 milliseconds to slow the output down a bit okay so let's see what this looks like so here's my thermistor I have a glass thermometer here as a reference the temperature from the thermistor is reading about 26 degrees Celsius if you look at the glass thermometer you can see it's reading 27. so that's pretty close to the reading from the thermistor when I hold the thermistor you can see the temperature go up foreign to the ambient temperature when I Let Go alright so this is great if all you need to do is measure temperature but thermistors can also be used to control other devices for example you could place a thermistor near a motor to shut it off when it gets too hot or you could monitor the temperature inside of an incubator and turn on a heat lamp when the temperature gets too cold so now let's see how to control the arduino's output with the readings from a thermistor I'm going to demonstrate with an LED but any device that's controlled by a 5 volt signal can be used here the thermistor is connected the same way as in the last example the center of the voltage divider connects to analog pin a0 the other side of the thermostat connects to 5 volts and the other side of the resistor connects to ground the LED's anode is connected to digital pin 5 by a current limiting resistor and the LED's cathode is connected to ground to make the diagram simpler I have the LED and the resistor in the voltage divider sharing the same ground now let's look at the sketch in this sketch we're going to make the LED turn off when the temperature passes above a certain threshold the LED will turn on when the temperature drops back below the threshold most of the sketch is the same as before but now we need a variable to store the LED pin number which is pin 5. all of these variables for the temperature calculations remain the same in the setup we're still going to send the temperature readings to the serial monitor but we're also going to switch digital pin 5 on and off so we need to initialize it as an output with the pinwood function in the loop section all of this is the same we take a voltage reading from the thermistor pin convert it to a resistance and use the steinhardt equation to give us the temperature of the thermistor then we convert the temperature in kelvins to Celsius and Fahrenheit and that gets printed to the serial monitor once we have the temperature data to work with we can use it to control the LED pin a simple if-else statement is enough to do that we can use the condition to determine what happens when the temperature rises above a certain temperature here if the temperature in Celsius is greater than 29 degrees the program will enter this block where we digital write the LED pin low else in other words if the temperature is not greater than 29 we enter this block and write the LED pin High so the LED will be on when the temperature is below 29 degrees Celsius and will be off when the temperature goes above 29 degrees Celsius let's check this out so initially the LED is on you can see the temperature on the stereo monitor is reading about 25 degrees Celsius when I hold on to the thermistor to warm it up you can see the temperature increases quickly and once we pass 29 degrees the LED turns off when the thermistor cools down below 29 degrees the LED turns back on in the next video we're going to learn about another way to measure temperature but this time with the digital humidity and temperature sensor foreign the three in one smart car and iot learning kit from Sun founder is a Hands-On all included Electronics kit that is perfect for anyone who wants to learn how to master the Arduino the kit comes with an Arduino 22 different sensors and modules breadboards jumper wires and everything else you need to build a bunch of fun and interesting projects learn about robotics by building a remote controlled smart car that can be controlled with an infrared remote controller or drive on its own and avoid obstacles or fall on the line learn about the internet of things with a project that lets you monitor the temperature humidity and light level of a room from an app on your smartphone and build a plant monitor that tracks the temperature humidity light intensity and soil moisture and displays it on your smartphone so you can keep your plants water remotely it's a super cool kit and I have lots of fun building all the projects in it so click the link in the description below to order the kit from Sun founderforeign how to set up and program a thermistor thermistors are perfect for any project that needs to measure temperature or control things based on temperature we'll output temperature readings to the stereo monitor then make a temperature switch that controls an LED this is what a thermistor looks like it's pretty small and it kind of looks like a tantalum capacitor there are two leads but thermistors are non-polarized so there isn't a positive or negative lead they can be connected either way around thermistors are variable resistors to change their resistance when the temperature changes they're specified with a resistance value called the r25 value the r25 value is the resistance of the thermistor at 25 degrees Celsius it's a 10 kilo ohm thermistor so its resistance at 25 degrees Celsius is 10 kilo ohms thermistors are also specified by their temperature coefficient the coefficient can be either positive or negative in positive temperature coefficient thermistors the resistance increases with increasing temperature in negative temperature coefficient thermistors the resistance decreases with increasing temperature most thermistors use for Arduino projects are negative temperature coefficient thermistors so that's what I'll be discussing here since thermistors are variable resistors we can use a voltage divider circuit to measure the voltage drop across the thermistor as the temperature changes once we know the voltage drop across the thermistor we can use the voltage divider equation to calculate the resistance of the thermistor at each temperature here's how that will look when it's wired up to the Arduino here's the thermistor and here's the resistor one tricky thing about this circuit though is that you have to be sure that the resistor here is the same resistance as the r25 value of your thermistor for example if you have a 10 kilo ohm thermistor this resistor needs to be 10 kilo ohms if you have a 100 kilo ohm thermistor the resistor needs to be 100 kilo ohms as well the middle of the voltage divider is connected to analog pin a0 on the Arduino the other lead of the thermistor is connected to 5 volts and the other side of the resistor is connected to ground before we jump into the sketch you need a little background information about how a thermistor's resistance is related to temperature unfortunately it's not a simple linear relationship it's logarithmic the precise relationship is best modeled by a formula called the steinhardt heart equation the steinhardt heart equation describes the temperature resistance relationship with about 0.02 percent accuracy equation looks like this the formula solves for the inverse of temperature but we can rearrange it to solve for temperature R is the resistance of the thermistor at a particular temperature t a B and C are consonants that depend on the resistance tolerance and construction of the thermistor the math to calculate the constants is pretty Advanced but luckily there are online calculators that will do it for you the thermistor I'm going to use for this video is an mf52103 10 kilo ohm NTC thermistor with the plus or minus one percent tolerance if you're using the same type of thermistor that I am you can use the constant values I'm using but if yours is different I'm going to show you how to calculate them I found a good online calculator for the steinhardt heart coefficients all you need to do is input the resistance of the thermistor at three different temperatures if you don't have a data sheet for your thermistor you can use a Multimeter to measure its resistance at three different temperatures but I have the data sheet for my thermistor and it has a table of the resistances for a range of temperatures just need to know the beta value and the r25 value the beta value is something you need to get from the manufacturer the thermistor I'm using has an r25 value of 10 kilo ohms and a beta value of 3435 so let me scroll down here and find the resistance table here it is the First Column shows the temperature and the second column shows the resistance at that temperature it's best to use the lowest highest and middle temperatures the thermistor is rated for example if your thermistor is rated from -40 to 105 degrees Celsius you would use the resistances at -40 25 and 105 degrees the resistance of my thermistor at minus 40 degrees Celsius is 190 953 ohms I'm going to input that into the calculator at 25 degrees Celsius the resistance is 10 000 ohms so I'm going to input that in the calculator too it's actually already set at 25 degrees and 10 kilo ohms the resistance of my thermistor is 858.33 ohms at 105 degrees Celsius so input that too to run the calculator press the enter key now if you look at the graph over here this is plotting resistance on the y-axis and temperature on the x-axis the curve is logarithmic over here are the calculated steinhardt heart coefficients a b and c so now let's look at the sketch and we'll come back for these numbers later the center of the voltage divider is connected to Arduino pin a0 so I have an INT variable called thermistor pin to store that PIN number then we need a variable to store the value of the resistor in the voltage divider let's store it in the float variable called R1 I'm using a 10 kilo ohm thermistor so my R1 is 10 000 ohms if you're using 100 kilo ohm thermistor your R1 would be 100 kilo ohms now we declare some float variables for the calculations we're going to do R2 will hold the resistance of the thermistor after we calculate it with the voltage divider formula then we have log R2 which holds the natural log of R2 log R2 Cube holds the natural log of R2 raised to the third power TK will hold the current temperature in Kelvins TC will hold the current temperature in Celsius and TF which will hold the current temperature in Fahrenheit then we Define the values of the steinhardt coefficients and store them in fluid variables a b and c these numbers are taken from the steinhardt heart calculator I showed you earlier here's the a coefficient so that goes here here's the B value that goes here 's the C value and that goes here now down in the setup section we just need to initialize the serial monitor in the loop section we take an analog read of the thermistor pin and store the result in a local int variable called V out remember that analog read returns a value between 0 and 10 23. 0 corresponds to zero volts and 1023 corresponds to 5 volts this corresponds to the voltage drop across the thermistor so now we can convert that to the resistance of the thermistor so we use the voltage divider equation which has been rearranged to solve for R2 instead of V out we have R2 equals R1 times 1023 divided by V out minus 1. R2 is the resistance of the thermistor and R1 is the other resistor in the voltage divider 1023 is the input voltage of the voltage divider which is 5 volts and V out is the voltage drop across the thermistor the steinhardt equation uses the natural log of R2 to get the natural log of R2 we can use the log function with the name of the variable as the argument we start the result in the global float variable log R2 then we have to calculate the natural log of R2 raised to the third power to do that we can use the pow function the pal function takes two parameters the first parameter is the base and the second parameter is the exponent since we want to raise log R2 to the third power we have log R2 as the first argument and three is the second argument this is stored in the log R2 Cube variable here's where we do the steinhard heart equation math the steinhardt equation gives the temperature of the thermistor in degrees Kelvin so we store the result in the variable TK the equation is 1 divided by the a coefficient plus the B coefficient times the natural log of R2 plus the C coefficient times the natural log of R2 raised to the third power so this will give us the temperature of the thermistor in Kelvins but kelvins aren't very useful unless you're building a sensor for a physics or chemistry project so let's convert kelvins to degrees Celsius to do that we just subtract 273.15 from the temperature in Kelvins the result will be stored in the TC variable let's go a step further and convert the temperature in celsius to a temperature in Fahrenheit to do that we just multiply the temperature in celsius by 9. then divide by 5. and add 32. the result is stored in the TF variable now we just need to print the values to the serial monitor here I'm printing the word temperature equals than the TC variable which holds the temperature in Celsius replace this with TK or tkf if you want the temperature in kelvins or Fahrenheit then I use serial print line to print a letter C to show that the temperature is in Celsius lastly I added a delay of 500 milliseconds to slow the output down a bit okay so let's see what this looks like so here's my thermistor I have a glass thermometer here as a reference the temperature from the thermistor is reading about 26 degrees Celsius if you look at the glass thermometer you can see it's reading 27. so that's pretty close to the reading from the thermistor when I hold the thermistor you can see the temperature go up foreign to the ambient temperature when I Let Go alright so this is great if all you need to do is measure temperature but thermistors can also be used to control other devices for example you could place a thermistor near a motor to shut it off when it gets too hot or you could monitor the temperature inside of an incubator and turn on a heat lamp when the temperature gets too cold so now let's see how to control the arduino's output with the readings from a thermistor I'm going to demonstrate with an LED but any device that's controlled by a 5 volt signal can be used here the thermistor is connected the same way as in the last example the center of the voltage divider connects to analog pin a0 the other side of the thermostat connects to 5 volts and the other side of the resistor connects to ground the LED's anode is connected to digital pin 5 by a current limiting resistor and the LED's cathode is connected to ground to make the diagram simpler I have the LED and the resistor in the voltage divider sharing the same ground now let's look at the sketch in this sketch we're going to make the LED turn off when the temperature passes above a certain threshold the LED will turn on when the temperature drops back below the threshold most of the sketch is the same as before but now we need a variable to store the LED pin number which is pin 5. all of these variables for the temperature calculations remain the same in the setup we're still going to send the temperature readings to the serial monitor but we're also going to switch digital pin 5 on and off so we need to initialize it as an output with the pinwood function in the loop section all of this is the same we take a voltage reading from the thermistor pin convert it to a resistance and use the steinhardt equation to give us the temperature of the thermistor then we convert the temperature in kelvins to Celsius and Fahrenheit and that gets printed to the serial monitor once we have the temperature data to work with we can use it to control the LED pin a simple if-else statement is enough to do that we can use the condition to determine what happens when the temperature rises above a certain temperature here if the temperature in Celsius is greater than 29 degrees the program will enter this block where we digital write the LED pin low else in other words if the temperature is not greater than 29 we enter this block and write the LED pin High so the LED will be on when the temperature is below 29 degrees Celsius and will be off when the temperature goes above 29 degrees Celsius let's check this out so initially the LED is on you can see the temperature on the stereo monitor is reading about 25 degrees Celsius when I hold on to the thermistor to warm it up you can see the temperature increases quickly and once we pass 29 degrees the LED turns off when the thermistor cools down below 29 degrees the LED turns back on in the next video we're going to learn about another way to measure temperature but this time with the digital humidity and temperature sensor foreign the three in one smart car and iot learning kit from Sun founder is a Hands-On all included Electronics kit that is perfect for anyone who wants to learn how to master the Arduino the kit comes with an Arduino 22 different sensors and modules breadboards jumper wires and everything else you need to build a bunch of fun and interesting projects learn about robotics by building a remote controlled smart car that can be controlled with an infrared remote controller or drive on its own and avoid obstacles or fall on the line learn about the internet of things with a project that lets you monitor the temperature humidity and light level of a room from an app on your smartphone and build a plant monitor that tracks the temperature humidity light intensity and soil moisture and displays it on your smartphone so you can keep your plants water remotely it's a super cool kit and I have lots of fun building all the projects in it so click the link in the description below to order the kit from Sun founder\n"