11. Chapter Thermistor

In this chapter, we will learn about Thermistors which are another kind of Resistor.

11.1. Project Thermometer

A Thermistor is a type of Resistor whose resistance value is dependent on temperature and changes in temperature. Therefore, we can take advantage of this characteristic to make a Thermometer.

11.1.1. Component List

  1. Raspberry Pi (with 40 GPIO) x1

  2. GPIO Extension Board & Ribbon Cable x1

  3. Breadboard x1

Thermistor x1

Thermistor

Resistor 10kΩ x3

Resistor-10kΩ

ADC module x1

ADC-module-1 or ADC-module-2

Jumper Wire M/M x14

jumper-wire

11.1.2. Component knowledge

11.1.2.1. Thermistor

Thermistor is a temperature sensitive resistor. When it senses a change in temperature, the resistance of the Thermistor will change. We can take advantage of this characteristic by using a Thermistor to detect temperature intensity. A Thermistor and its electronic symbol are shown below.

../../../_images/11_00.png

The relationship between resistance value and temperature of a thermistor is:

\[\boldsymbol{ R_t = R \cdot EXP \left[ B \left( \frac{1}{T_2} - \frac{1}{T_1} \right) \right] }\]
  • Where:
    • Rt is the thermistor resistance under T2 temperature;

    • R is in the nominal resistance of thermistor under T1 temperature;

    • EXP[n] is nth power of e;

    • B is for thermal index;

    • T1, T2 is Kelvin temperature (absolute temperature). Kelvin temperature=273.15 + Celsius temperature.

For the parameters of the Thermistor, we use: B=3950, R=10k, T1=25.

The circuit connection method of the Thermistor is similar to photoresistor, as the following:

../../../_images/Thermistor-3.png

We can use the value measured by the ADC converter to obtain the resistance value of Thermistor, and then we can use the formula to obtain the temperature value.

Therefore, the temperature formula can be derived as:

\[\boldsymbol{ T_2 = \dfrac{1}{\left( \dfrac{1}{T_1} + \dfrac{\ln(R_t / R)}{B} \right)} }\]

11.1.3. Circuit with ADS7830

The circuit of this project is similar to the one in last chapter. The only difference is that the Photoresistor is replaced by the Thermistor.

Schematic diagram

ADS7830-Schematic-5

Hardware connection. If you need any support,please feel free to contact us via:

support@freenove.com

ADS7830-fritizing-6

Thermistor has longer pins than the one shown in circuit.

11.1.4. Circuit with PCF8591

The circuit of this project is similar to the one in the last chapter. The only difference is that the Photoresistor is replaced by the Thermistor.

Schematic diagram

PCF8591-Schematic-5

Hardware connection. If you need any support,please feel free to contact us via:

support@freenove.com

PCF8591-fritizing-5

Thermistor has longer pins than the one shown in circuit.

11.1.5. Code

In this project code, the ADC value still needs to be read, but the difference here is that a specific formula is used to calculate the temperature value.

11.1.5.1. C Code Thermometer

If you did not configure I2C, please refer to Chapter 7. If you did, please continue.

First, observe the project result, and then learn about the code in detail.

Hint

If you have any concerns, please contact us via: support@freenove.com

  1. Use cd command to enter 11.1.1_Thermometer directory of C code.

$ cd ~/Freenove_Kit/Code/C_Code/11.1.1_Thermometer
  1. Use following command to compile Thermometer.cpp and generate executable file Thermometer.

$ g++ Thermometer.cpp -o Thermometer -lwiringPi -lADCDevice
  1. Then run the generated file Thermometer.

$ sudo ./Thermometer

After the program is executed, the Terminal window will display the current ADC value, voltage value and temperature value. Try to “pinch” the thermistor (without touching the leads) with your index finger and thumb for a brief time, you should see that the temperature value increases.

../../../_images/ADC-value-2.png

The following is the code:

 1/**********************************************************************
 2* Filename    : Thermometer.cpp
 3* Description : DIY Thermometer
 4* Author      : www.freenove.com
 5* modification: 2020/03/09
 6**********************************************************************/
 7#include <wiringPi.h>
 8#include <stdio.h>
 9#include <math.h>
10#include <ADCDevice.hpp>
11
12ADCDevice *adc;  // Define an ADC Device class object
13
14int main(void){
15    adc = new ADCDevice();
16    printf("Program is starting ... \n");
17
18    if(adc->detectI2C(0x48)){    // Detect the pcf8591.
19        delete adc;                // Free previously pointed memory
20        adc = new PCF8591();    // If detected, create an instance of PCF8591.
21    }
22    else if(adc->detectI2C(0x4b)){// Detect the ads7830
23        delete adc;               // Free previously pointed memory
24        adc = new ADS7830();      // If detected, create an instance of ADS7830.
25    }
26    else{
27        printf("No correct I2C address found, \n"
28        "Please use command 'i2cdetect -y 1' to check the I2C address! \n"
29        "Program Exit. \n");
30        return -1;
31    }
32    printf("Program is starting ... \n");
33    while(1){
34        int adcValue = adc->analogRead(0);  //read analog value A0 pin    
35        float voltage = (float)adcValue / 255.0 * 3.3;    // calculate voltage    
36        float Rt = 10 * voltage / (3.3 - voltage);        //calculate resistance value of thermistor
37        float tempK = 1/(1/(273.15 + 25) + log(Rt/10)/3950.0); //calculate temperature (Kelvin)
38        float tempC = tempK -273.15;        //calculate temperature (Celsius)
39        printf("ADC value : %d  ,\tVoltage : %.2fV, \tTemperature : %.2fC\n",adcValue,voltage,tempC);
40        delay(100);
41    }
42    return 0;
43}

In the code, the ADC value of ADC module A0 port is read, and then calculates the voltage and the resistance of Thermistor according to Ohms Law. Finally, it calculates the temperature sensed by the Thermistor, according to the formula.