Blinker家用多功能报警器-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3096|回复: 4

[分享] Blinker家用多功能报警器

[复制链接]
发表于 2020-3-12 20:16 | 显示全部楼层 |阅读模式
  Blinker家用多功能报警器以WeMos D1为核核心,外接DCWL-0516微波雷达人体感应模块,DHT11温湿度传感器,GP2Y1014AU粉尘传感器,MQ2可燃气体传感器,和报警
蜂鸣器组成.当室内温度达到到50度或空气质量超过500时,报警器就会给手机发出火警"fire alarm"通知信息.并且报警器的蜂鸣器也会发出报警声.当燃气如果发
生泄漏而触发MQ2时报警器就会给手机发出燃气报警"gas alarm"通知信息.同时报警器的蜂鸣器也会发出报警声.移动侦测报警靠DCWL-0516在其5米范围内被移动
物体触发后即刻向手机发出向移动警"move alarm"通知信息.在手机Blinker app界面上的开关按键可开关移动侦测报警功能.如果家中有人可以关闭它,外出时就可
打开移动侦测报警功能. 报警时不仅可得到通知而且APP上按键的图标也会由绿色的和平鸽变为红色的太阳以示警告.同时右边还有报警次数记录(关闭按键可清零).
  程序中空气质量的监测是以前30秒中15次采样的平均值为准的,是可以防止误触发而因起错误报警.再有编程中对WeMos D1的外接端口都采用ESP 8266的GPIO号
来编程的.这样做的目的是使该程序也适合把其它ESP 8266开发板.程序如下:



#define BLINKER_WIFI
#include <Blinker.h>
#include <Ticker.h>
Ticker flipper;
char auth[] = "3242adea6eea";
char ssid[] = "TP-LINK_935D";
char pswd[] = "lwq19470810";
#include <modules/dht/DHT.h>
BlinkerButton Button1("onal");
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
BlinkerNumber COUT("cout");
BlinkerNumber Kong("kong");
#define DHTPIN 16  
#define DHTTYPE DHT11  
DHT dht(DHTPIN,DHTTYPE);
int dustPin=A0;
float dustVal=0;
int ledPower=0;
int delayTime=280;
int delayTime2=40;
float offTime=9680;
int c=0,e=1,i=0,k=0;
float t,h,humi_read=0,temp_read=0,cout_read=0,kong_read=0;
float sum,ds1,ds2,ds3,ds4,ds5,ds6,ds7,ds8,ds9,ds10,ds11,ds12,ds13,ds14,ds15;
void flip() {
  e=e*(-1);
i++;
if(i>29) {
   if((t>50)||(k>500))  Blinker.notify("fire alarm");
else if(digitalRead(5)==HIGH)  Blinker.notify("gas alarm");
  i=0;
}
}
void buttonTick(){  
   c++;
    COUT.print(cout_read);
    cout_read = c;
      COUT.print(cout_read);
    cout_read = c;
Button1.icon("fas fa-sun fa-spin");
   Button1.color("#FF0000");
    Button1.text("报警");
   Button1.print();
  Blinker.notify("move alarm");
}
void button1_callback(const String & state)   
{
  BLINKER_LOG("get button state: ", state);
  if (state=="on")
   {
     Button1.icon("fas fa-dove fa-spin");//fa-lightbulb
        Button1.color("#00FF00");
        Button1.text("开");
    digitalWrite(2, HIGH);
     Button1.print("on");
    }
    else if(state=="off")
    {
       Button1.icon("fal fa-dove");
        Button1.color("#00FF00");
        Button1.text("关");
      digitalWrite(2, LOW);
      c=0;
     COUT.print(cout_read);
    cout_read = c;
    c=0;
      COUT.print(cout_read);
    cout_read = c;
      Button1.print("off");
     }
}

void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);

    Blinker.vibrate();
   
    uint32_t BlinkerTime = millis();
    Blinker.print(BlinkerTime);
    Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
  HUMI.print(humi_read);
  TEMP.print(temp_read);
  Kong.print(kong_read);
}

void setup()
{
     Serial.begin(115200);
  BLINKER_DEBUG.stream(Serial);
  attachInterrupt(14, buttonTick, RISING);
  BLINKER_DEBUG.debugAll();
   flipper.attach(1, flip);
   pinMode(2, OUTPUT);
   pinMode(12, OUTPUT);
   pinMode(5, INPUT);
   pinMode(ledPower, OUTPUT);
   digitalWrite(12, LOW);
  digitalWrite(2, LOW);
  pinMode(A0,INPUT);
  Blinker.begin(auth,ssid,pswd);
  Blinker.attachHeartbeat(heartbeat);
  Button1.attach(button1_callback);
  dht.begin();
   Blinker.attachData(dataRead);
    digitalWrite(ledPower,LOW);
delayMicroseconds(delayTime);
dustVal=analogRead(dustPin);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH);
delayMicroseconds(offTime);
ds1=ds2=ds3=ds4=ds5=ds6=ds7=ds8=ds9=ds10=ds11=ds12=ds13=ds14=ds15=dustVal;
}
void loop()
{
    Blinker.run();
   
digitalWrite(ledPower,LOW);
delayMicroseconds(delayTime);
dustVal=analogRead(dustPin);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH);
delayMicroseconds(offTime);
ds1=ds2;
ds2=ds3;
ds3=ds4;
ds4=ds5;
ds5=ds6;
ds6=ds7;
ds7=ds8;
ds8=ds9;
ds9=ds10;
ds10=ds11;
ds11=ds12;
ds12=ds13;
ds13=ds14;
ds14=ds15;
ds15=dustVal;
sum=((ds1+ds2+ds3+ds4+ds5+ds6+ds7+ds8+ds9+ds10+ds11+ds12+ds13+ds14+ds15)/15/1024-0.0356)*120000*0.035/6;

    h=dht.readHumidity();
    t=dht.readTemperature();   
    k =(int)sum;
  if(((t>50)||(k>500)||(digitalRead(5)==HIGH))&&(e>0)) digitalWrite(12, HIGH);
  else
   digitalWrite(12, LOW);  
  
  if(isnan(h)||isnan(t))
   {
    BLINKER_LOG("Failed to read from DHT sensor!");
   }
   else
   {
    BLINKER_LOG("Humidity:",h,"%");
    BLINKER_LOG("Temperature:",t,"*C");
    BLINKER_LOG("Kong Qi: ", k, " /1024");

    humi_read=h;
    temp_read=t;
    kong_read=k;
    Blinker.delay(2000);
  }  
}

APP界面

APP界面

电路图

电路图
发表于 2020-3-13 18:09 | 显示全部楼层
不错,有点实用。
发表于 2020-3-16 21:21 | 显示全部楼层






sketch_mar09a:8:29: fatal error: modules/dht/DHT.h: No such file or directory

#include <modules/dht/DHT.h>

                             ^

compilation terminated.

exit status 1
modules/dht/DHT.h: No such file or directory
  **************谁有DHT文件
 楼主| 发表于 2020-3-17 07:23 | 显示全部楼层
火马电竞T1 发表于 2020-3-16 21:21
sketch_mar09a:8:29: fatal error: modules/dht/DHT.h: No such file or directory

#include

DHT温湿度传感器库.


DHT.rar

5.39 KB, 下载次数: 7

DHT

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 11:41 , Processed in 0.083360 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表