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
|
|
|---|---|
Thermistor x1 |
|
ADC module x1
|
|
Jumper Wire M/M x14 |
|
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.
The relationship between resistance value and temperature of a thermistor is:
- 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:
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:
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
|
Hardware connection. If you need any support,please feel free to contact us via:
|
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
|
Hardware connection. If you need any support,please feel free to contact us via:
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
Use
cdcommand to enter 11.1.1_Thermometer directory of C code.
$ cd ~/Freenove_Kit/Code/C_Code/11.1.1_Thermometer
Use following command to compile
Thermometer.cppand generate executable fileThermometer.
$ g++ Thermometer.cpp -o Thermometer -lwiringPi -lADCDevice
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.
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.







