仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
arduino源码:
- /*********************************************************
- * Rt= 10K RES=4700
- * GND----/\/\/\/\----/\/\/\/\----VCC=5V
- * Rt = R *EXP(B*(1/T1-1/T2))
- * 对上面的公式解释如下:
- *
- * 1.Rt 是热敏电阻在T1温度下的阻值;
- * 2.R是热敏电阻在T2常温下的标称阻值;
- * 3.B值是热敏电阻的重要参数;
- * 4.EXP是e的n次方;
- * 5.这里T1和T2指的是K度即开尔文温度,K度=273.15(绝对温度)+摄氏度;
- *********************************************************/
- #include <math.h>
- #define RES 4700
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
- double Water_temp;
- void setup(){
- Serial.begin(9600);
- lcd.init(); // initialize the lcd
- // Print a message to the LCD.
- lcd.backlight();
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Temperature ");
- }
- void loop(){
- double AD_val=analogRead(0); //0-1023的范围
- double GetVoltage=(AD_val/1023)*5.0; //采样电压值
- // 欧姆定律 Rt/RES=GetVoltage/(5.0-GetVoltage),电流一致
- double Rt=GetVoltage*RES/(5.0-GetVoltage);
- //热力学绝对温度
- //T1=1/(ln(Rt/R) /B + 1/T2 )
- // Serial.println( 1/( log(Rt/RES) /3000 + 1/(25+273.15) ));
- Water_temp=1/(log(Rt/10000) /3950 + 1/(25+273.15))-273.15;
- if(Water_temp>-100.0)
- {
- Serial.print("RES= ");
- Serial.print(RES);
- Serial.print(" RT= :");
- Serial.println(Rt);
- Serial.print("The temperature is :");
- Serial.print(Water_temp);
- Serial.println(" ~C");
- lcd.setCursor(0, 1);
- lcd.print("T1=");
- lcd.print(Water_temp);
- lcd.print(" ");
- }
- else
- {
- Serial.println("Error! check sensor!");
- }
- delay(1000);
- }
复制代码 全部资料51hei下载地址:
NTC测温实验.rar
(37.16 KB, 下载次数: 176)
|