-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeMCU code.ino
70 lines (59 loc) · 1.58 KB
/
NodeMCU code.ino
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
// Chage These Credentials with your Blynk Template credentials
// Chage These Credentials with your Blynk Template credentials
#define BLYNK_TEMPLATE_ID "TMPL3-4QvYPqj"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "4aJm1lR_YygVyuMJy_aIvq_ZlNKK6oFw"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "4aJm1lR_YygVyuMJy_aIvq_ZlNKK6oFw";
char ssid[] = "ADVANCEDTECH"; // Change your Wifi/ Hotspot Name
char pass[] = ""; // Change your Wifi/ Hotspot Password
BlynkTimer timer;
#define fire D2
#define GREEN D5
#define RED D6
#define buzzer D7
int fire_Val = 0;
WidgetLED led(V1);
void setup() //Setup function - only function that is run in deep sleep mode
{
Serial.begin(9600); //Start the serial output at 9600 baud
pinMode(GREEN, OUTPUT);
pinMode(fire, INPUT);
pinMode(RED, OUTPUT);
pinMode(buzzer, OUTPUT);
Blynk.begin(auth, ssid, pass);//Splash screen delay
delay(2000);
timer.setInterval(500L, mySensor);
}
void loop() //Loop function
{
Blynk.run();
timer.run();
}
void mySensor()
{
fire_Val = digitalRead(fire);
if (fire_Val == LOW)
{
Blynk.logEvent("fire_alert");
digitalWrite(GREEN, LOW);
digitalWrite(RED, HIGH);
digitalWrite(buzzer, HIGH);
Blynk.virtualWrite(V0, 1);
Serial.print("fIRE Level: ");
Serial.println(fire_Val);
led.on();
}
else
{
digitalWrite(GREEN, HIGH);
digitalWrite(RED, LOW);
digitalWrite(buzzer, LOW);
Blynk.virtualWrite(V0, 0);
Serial.print("fIRE Level: ");
Serial.println(fire_Val);
led.off();
}
}