其原理是用一个热敏电阻分得的电压来计算当前的温度值。
计算方法如下:
a=analogRead(0); resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor; temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
先计算热敏电阻的阻值,再根据热敏电阻的温度曲线计算当前温度。
接线方法如下:
效果如下:
参考代码如下:
#include
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 255;
const int colorB = 255;
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.print("temp:");
lcd.setCursor(6, 1);
lcd.print("panpan2333");
delay(1000);
}
int a;
float temperature;
int B=3975; //B value of the thermistor
float resistance;
void loop()
{
lcd.setCursor(6, 0);
a=analogRead(0);
resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ;