ESP8266+blinker制作功能强大带温度保护的热风机
设计制作一个小房间使用的热风机,要求可以远程监控并且安全可靠,用ESP8266 D1 MINI+blinker制作,成本低,功能强大,自动温度控制,自动定时控制,远程手机控制,手机显示工作状态,为提高安全性给热风机加了多种温度保护,该保护可以在热风机因任何原因温度高,如风机转速下降、停转、进出风口遮挡,可立即自动断开电源停止加热,大大提高热风机的安全性。元件:https://www.arduino.cn/forum.php?mod=image&aid=81619&size=300x300&key=36f3955976a4e804&nocache=yes&type=fixnone热风机:热敏电阻:https://www.arduino.cn/forum.php?mod=image&aid=81620&size=300x300&key=7756cdfb96b1344c&nocache=yes&type=fixnone热敏电阻安装:连接元件:用一个小盒装上:接线示意图:源程序:
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_SENSOR
#include <Blinker.h>
#include <DHT.h>
char auth[] = "41b7axxxxxxxx";//Blinker号
char ssid[] = "www";
char pswd[] = "0123456789";
/*新建数据类型组件对象*/
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
BlinkerNumber TEMPBH("tempbh");//温度保护
BlinkerNumber QDCS("qdcs");//启动次数
BlinkerButton Button1("btn-qt");//启动停止
BlinkerButton Button2("btn-bh");//保护恢复
BlinkerText TEXT1("tex-qt");//显示状态
BlinkerText TEXT2("tex-fs");//显示风扇状态
BlinkerText TEXT3("tex-jr");//显示加热状态
BlinkerText TEXT4("tex-bh");//显示保护状态
BlinkerSlider SliderWD("ran-wd");//设定温度
BlinkerSlider SliderWDHC("ran-wdhc");//设定温度回差
//定义PIN
#define BH_TEMIPIN A0//温度保护传感器
#define DHTPIN D7 //DHT 11传感器
#define RELAY1 D5//继电器1信号引脚-风扇
#define RELAY2 D6//继电器2信号引脚-加热器
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22(AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
//定义变量
float humi_read = 0, temp_read = 0;
String B,QT,FS,JR;
int ZDQT=0,XTQD=0,qdcs=0;//选择开关,系统启动标记,启动次数
int WD=16,WDHC=1,WDBH=0,WDBH_JS=0,WDBH_DZ=0,WDBH_DZ1=0;
void SliderWD_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
WD = value;
}
void SliderWDHC_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
WDHC = value;
}
void heartbeat()//心跳
{
HUMI.print(humi_read);
TEMP.print(temp_read);
QDCS.print(qdcs);
TEMPBH.print(WDBH);
SliderWD.print(WD);
SliderWDHC.print(WDHC);
TEXT1.print(QT);
TEXT2.print(FS);
TEXT3.print(JR);
TEXT4.print(WDBH_DZ);
}
void dataStorage()//存数据
{
Blinker.dataStorage("temp", temp_read);
Blinker.dataStorage("humi", humi_read);
Blinker.dataStorage("tempbh", WDBH);
}
// 按下按键即会执行该函数
void button1_callback(const String & state) //启停,显示选择开关状态(系统指示灯)
{
BLINKER_LOG("get button state: ", state);
Blinker.vibrate(); //振动
if (state == "on") {
digitalWrite(LED_BUILTIN,HIGH );//灭
// 反馈开关状态
Button1.color("#6666ff");
Button1.print("on");
ZDQT=1;//运行
QT="运行";
TEXT1.print(QT);
} if (state == "off") {
digitalWrite(LED_BUILTIN, LOW);//亮
// 反馈开关状态
Button1.color("#708090");
Button1.print("off");
ZDQT=0;//停
QT="停止";
TEXT1.print(QT);
XTQD=0;//停止
TZJR();
}
Blinker.delay(300);
}
void button2_callback(const String & state)//保护复位
{
Blinker.vibrate(); //振动
BLINKER_LOG("get button state: ", state);
if (state == "press")
{
WDBH_JS=0;WDBH_DZ=0;WDBH_DZ1=0;
}
Blinker.delay(300);
}
void QDJR()//启动加热
{
digitalWrite(RELAY1, LOW);//开风扇
FS="运行";TEXT2.print(FS);
Blinker.delay(1000);
digitalWrite(RELAY2, LOW);//开加热
JR="运行";TEXT3.print(JR);
qdcs++;
Blinker.delay(300);
}
void TZJR()//停止加热
{
digitalWrite(RELAY2,HIGH);//停加热
JR="停止";TEXT3.print(JR);
Blinker.delay(10000);
digitalWrite(RELAY1, HIGH);//停风扇
FS="停止";TEXT2.print(FS);
Blinker.delay(300);
}
void setup()
{ // 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();//开启调试
//系统指示灯
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);//亮
QT="停止";
TEXT1.print(QT);
Button1.color("#708090");
Button1.print("off");
//Relay
pinMode(RELAY1, OUTPUT);
digitalWrite(RELAY1, HIGH);
FS="停止";TEXT2.print(FS);
pinMode(RELAY2, OUTPUT);
digitalWrite(RELAY2,HIGH );
JR="停止";TEXT3.print(JR);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);//运行心跳函数
Blinker.attachDataStorage(dataStorage);//开启历史数据
Button1.attach(button1_callback);//回调
Button2.attach(button2_callback);
SliderWD.attach(SliderWD_callback);
SliderWDHC.attach(SliderWDHC_callback);
dht.begin();
}
void loop()
{
Blinker.run();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
BLINKER_LOG("Failed to read from DHT sensor!");
}
else
{
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
humi_read = h;
temp_read = t;
}
//if(WDBH_DZ==0){ WDBH=analogRead(BH_TEMIPIN);}
WDBH=analogRead(BH_TEMIPIN);
if(WDBH>950||WDBH<150){if(WDBH_JS++>1){WDBH_DZ=1;}TEMPBH.print(WDBH);}//WDBH>950保护值,可调整
else{WDBH_JS=0;}
if(WDBH_DZ==1&&WDBH_DZ1==0){ WDBH_DZ1=1;digitalWrite(RELAY2,HIGH ); digitalWrite(RELAY1, HIGH);TEXT4.print(WDBH_DZ);TZJR();}
if(ZDQT==1&&XTQD==0&&WDBH_DZ==0&&temp_read<WD)//启动一次
{XTQD=1;QDJR();
// if(temp_read<WD){QDJR();}
}
if(temp_read>(WD+WDHC)&&XTQD==1)
{TZJR();XTQD=0; }
Blinker.delay(2000);
}手机上的设置:定时设置:选择“动作配置”再选“自动生成”
过热保护值根据调试实际情况更改。
页:
[1]