系统功能:
1. 连接blinker云平台,通过手机控制。
2. 手机界面text,number控件。
3. 通过DHT11采集温湿度。
4. 通过MQ2采集可燃气体。
系统功能框图:
主要功能模块原理图
资料获取地址
https://shop272529339.taobao.com
部分代码:
unsigned char humiVal = 50;
unsigned char tempVal = 28;
String sensorStr;
uint32_t dht11Time = 0;
uint32_t mq2Time = 0;
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
//心跳包函数
void heartbeat()
{
HUMI.print(humiVal);
TEMP.print(tempVal);
SENSOR.print(sensorStr);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_OFF);
pinMode(BUZPIN, OUTPUT);
digitalWrite(BUZPIN, BUZZER_OFF);
pinMode(MQ2PIN, INPUT_PULLUP);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
dht.begin();
}
void loop()
{
Blinker.run();
if((dht11Time==0)||(millis()-dht11Time>=3000))
{
dht11Time = millis();
float humiTemp = dht.readHumidity();
float tempTemp = dht.readTemperature();
if (isnan(humiTemp) || isnan(tempTemp))
{
BLINKER_LOG("Failed to read from DHT sensor!");
}
else
{
BLINKER_LOG("Humidity: ", humiTemp, " %");
BLINKER_LOG("Temperature: ", tempTemp, " *C");
humiVal = (unsigned char)humiTemp;
tempVal = (unsigned char)tempTemp;
}
}
if((mq2Time==0)||(millis()-mq2Time>=2000))
{
mq2Time = millis();
if(digitalRead(MQ2PIN)==0)
{
sensorStr = "烟感状态危险";
SENSOR.color("#ff0000");
BLINKER_LOG("Dange");
digitalWrite(BUZPIN, BUZZER_ON);
}
else
{
sensorStr = "烟感状态安全";
SENSOR.color("#666666");
BLINKER_LOG("Safe");
digitalWrite(BUZPIN, BUZZER_OFF);
}
}
}
此设计提供的资料包含原理图PCB(包含PDF,AD,立创EDA三个版本),源代码,系统框图,主程序流程图,物料清单(包含使用到的器件手册),功能操作说明等。