How to Make a Temperature Instrument with Thermistor?
1.Introduction
Thermistor is a kind of resistor whose resistance depends on temperature changes. Therefore, we can use this feature to make a temperature instrument.
2.Components Required
|
|
|
|
---|---|---|---|
Keyestudio Plus Mainboard*1 |
Thermistor*1 |
LCD_128X32_DOT*1 |
4.7KΩ Resistor*1 |
|
|
|
|
M-M Dupont Wires |
USB Cable*1 |
Breadboard*1 |
Jumper Wires |
3.Component Knowledge
Thermistor:
A thermistor is a temperature sensitive resistor. When it senses a change in temperature, the thermistor’s resistance changes. We can use this feature to detect temperature intensity with thermistor. This is widely used in gardening, home alarm systems and other devices.
①The NTC-MF52AT 10K thermistor is used here, where B is 3950 and it is connected in series with RS (RS=Rbalance=4.7KΩ resistor). The resistance value of the thermistor changes as the temperature changes.
②Calculation of NTC thermistor:
Calculation formula: Rt = R*EXP[B*(1/T1-1/T2)]
Among them, T1 and T2 refer to K degrees, that is, Kelvin temperature.
Rt is the resistance of the thermistor at T1 temperature.
R is the nominal resistance value of the thermistor at T2 room temperature. The value of the 10K thermistor at 25℃ is 10K (R=10K). T2 = (273.15 + 25).
EXP[n] is the nth power of e.
B is an important parameter of thermistor, B equals 3950.
We can use the value measured by the ADC converter to get the resistance value of the thermistor, and then use the formula to get the temperature value. t=((T1*B)/(B+T1*ln(Rt/R1)))-273.15,“ln”can be converted to “log”, that is: $$ t ((T1B)/(B+T1log(Rt/R1)))-273.15 $$ Error is ±0.5.
4.Read the Values
First we learned how to use the serial monitor to print the thermistor values. Please connect the wires according to the following wiring diagram.
/*
Read_the_thermistor_analog_value
http//www.keyestudio.com
*/
#include<math.h>
const float voltagePower=5.0;
const float Rs=4.7;//sample resistance is 4.7KΩ
const int B=3950;
const double T1=273.15+25;//ordinary temperature
const double R1=10;//ordinary temperature corresponds the resistance value, unit is KΩ
void setup() {
Serial.begin(9600);
}
void loop() {
//Attain the voltage value at A1
double digitalValue=analogRead(1);
double voltageValue=(digitalValue/1023)*5;
Serial.print("Current voltage value=");
Serial.println(voltageValue);
//Obtain the resistance of the thermistor through the voltage divider ratio
double Rt=((voltagePower-voltageValue)*Rs)/voltageValue;
Serial.print("Current registor value=");
Serial.println(Rt);
//Converted to get the temperature value
Serial.print("Current temperature value=");
Serial.println(((T1*B)/(B+T1*log(Rt/R1)))-273.15);//
Serial.println();
//output for each 3 second, change the frequency
delay(3000);
}
Upload the code to the Plus Mainboard, connect the wires and power on first. Then open the serial monitor, the voltage value at thermistor pin A1 can be read, and the resistance value and temperature value of the thermistor can be obtained through the voltage division ratio. As shown below.
5.Circuit Diagram and Wiring Diagram
6.Code
Note: The “LCD_128X32”library file needs to be installed in the code. If the library file has been added, ignore the process of adding the library file below.
Project 16 contains the library files of I2C 128×32 LCD. Decompress the library files in the folder, that is, put the decompressed “LCD_128X32” folder into “Arduino libraries” under the compiler installation directory.
After successful placement, you need to restart the compiler, otherwise the compilation will not work.
e.g:C: \Program Files\Arduino\libraries
/*
Temperature_Instrument
http//www.keyestudio.com
*/
#include <math.h>
#include <lcd.h> //add library files
lcd Lcd; //define a Lcd class instance
const float voltagePower=5.0;
const float Rs_val=4.7;//sample resistance is 4.7KΩ
const int B=3950;
const double T1=273.15+25;//normal temperature
const double R1=10;//ordinary temperature corresponds the resistance value, unit is KΩ
char string[10];
void setup(){
Serial.begin(9600);
Lcd.Init(); //initialize
Lcd.Clear(); //clear
}
void loop(){
// attain the voltage value at A1
double digitalValue=analogRead(1);
double voltageValue=(digitalValue/1023)*5;
//Obtain the resistance of the thermistor through the voltage divider ratio
double Rt=((voltagePower-voltageValue)*Rs_val)/voltageValue;
//Converted to get the temperature value
const float t=((T1*B)/(B+T1*log(Rt/R1)))-273.15;
if(t>-100.0) //If the temperature is greater than -100°C, the LCD display voltage value,obtains the resistance value of the thermistor through the voltage division ratio and temperature value
{
Lcd.Cursor(0,0);
Lcd.Display("C v v=");
Lcd.Cursor(0,7);
Lcd.DisplayNum(voltageValue);
Lcd.Cursor(0, 10);
Lcd.Display("V");
Lcd.Cursor(1,0);
Lcd.Display("C r v=");
Lcd.Cursor(1,7);
Lcd.DisplayNum(Rt);
Lcd.Cursor(1, 10);
Lcd.Display("R");
Lcd.Cursor(2, 0);
Lcd.Display("C t v=");
Lcd.Cursor(2, 7);
Lcd.DisplayNum(t);
Lcd.Cursor(2, 10);
Lcd.Display("C");
}
delay(300);
}
7.Result
After uploading the code to the Plus Mainboard, connecting the wires and powering on, the LCD_128X32_DOT displays the voltage value of the corresponding A1 pin, obtain the resistance value of the thermistor through the voltage division ratio and the temperature value in the current environment .(Only integers can be displayed, not decimals on the LCD_128X32_DOT)