-
Notifications
You must be signed in to change notification settings - Fork 0
/
blynk cpp
81 lines (68 loc) · 1.79 KB
/
blynk cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define BLYNK_TEMPLATE_ID "TMPLTMAl97d4"
#define BLYNK_DEVICE_NAME "FireAlarm"
#define BLYNK_AUTH_TOKEN "NUIFzhzgfEwNfXkvMbAOvYYYXG2_NttS"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "ssa"; // type your wifi name
char pass[] = "SLProject"; // type your wifi password
BlynkTimer timer;
#define DHTPIN 4 //Connect Out pin to D2 in NODE MCU
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int mq2 = A0;// smoke sensor is connected with the analog pin A0
int data = 0;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
data = analogRead(mq2);
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V1, t);
Blynk.virtualWrite(V2, h);
Blynk.virtualWrite(V3,data);
Serial.print("Smoke: ");
Serial.print(data);
Serial.println();
// You can send any value at any time.
// Please don't send more that 10 values per second.
Serial.print("Temperature : ");
Serial.print(t);
Serial.println();
Serial.print("Humidity : ");
Serial.println(h);
delay(1000);
digitalWrite(D3,LOW);
if(t>40||data>650)
{
digitalWrite(D3,HIGH);
Blynk.logEvent("fire","FIRE!!!!");
delay(5000);
}
}
void setup()
{
Serial.begin(115200);
pinMode(D3,OUTPUT);
Blynk.begin(auth, ssid, pass);//,"blynk-cloud.com",8080);
while(WiFi.status() != WL_CONNECTED)
{
Serial.print("..");
delay(200);
}
Serial.println();
Serial.println("NodeMCU is Connected!");
Serial.println(WiFi.localIP());
dht.begin();
timer.setInterval(100L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}