数字温度计(显示温度+高温报警)
#include <U8glib.h>
#define INTERVAL_LCD 20
unsigned long lcd_time = millis();
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
#define setFont_L u8g.setFont(u8g_font_7x13)
#define setFont_M u8g.setFont(u8g_font_fixed_v0r)
#define setFont_S u8g.setFont(u8g_font_fixed_v0r)
#define setFont_SS u8g.setFont(u8g_font_fub25n)
unsigned int tempMin=24;
unsigned int tempMax=27;
void setup() {
Serial.begin(115200);
analogReference(INTERNAL);
pinMode(11,OUTPUT);
digitalWrite(11,LOW);
}
void loop() {
double analogVotage=1.1*(double)analogRead(A3)/1023;
double temp=100*analogVotage;
unsigned int dutyCycle;
u8g.firstPage();
do {
setFont_L;
u8g.setPrintPos(0,10);
u8g.print(temp);
}while (u8g.nextPage());
if(temp<=tempMin){
dutyCycle=0;
digitalWrite(11,LOW);
}
else if(temp<tempMax){
dutyCycle=(temp-tempMin)*255/(tempMax-tempMin);
digitalWrite(11,LOW);
}
else{
dutyCycle=255;
digitalWrite(11,HIGH);
}
analogWrite(10,dutyCycle);
Serial.print("Temp:");
Serial.print(temp);
Serial.print("Degress Duty cycle:");
Serial.print(dutyCycle);
delay(100);
}

小白还没学过电路,如果图画得有问题请指出
这个博客介绍了一个使用Arduino的数字温度计项目,能够显示实时温度并设置高温报警阈值。通过读取A3引脚的模拟信号,转换为温度值,并用U8glib库在LCD屏幕上显示。当温度低于或等于最小设定值(24℃)或超过最大设定值(27℃)时,系统会调整PWM输出以控制加热或冷却设备。同时,通过串口打印温度和占空比信息。

被折叠的 条评论
为什么被折叠?



