-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nodemcu.ino
121 lines (88 loc) · 2.38 KB
/
Nodemcu.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#include <Servo.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial
#define FIREBASE_HOST "esp8-14574-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "74DB2qvMVBNoYrjGePyWarWXUQjokiRsa7HfxR04"
char auth[] = "e_1aCyS7khnyhZtUAZIwIqQaMZJTNi5p";
char ssid[] = "Sharadindu" ;
char pass[] = "Themelware4321beast" ;
#define WIFI_SSID "Sharadindu"
#define WIFI_PASSWORD "Themelware4321beast"
#define TRIGGER 5 //D1
#define ECHO 4 //D2
FirebaseData firebaseData;
String fireStatus ="";
long duration;
int distance;
Servo myservo;
int n = 0;
void setup() {
Serial.begin(9600);
pinMode(D3, OUTPUT);
pinMode(D7,OUTPUT);
pinMode(D4, OUTPUT);
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
digitalWrite(D7, HIGH);
myservo.attach(13);
Blynk.begin(auth, ssid, pass);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
delay(1000);
//Firebase.setString("LED_STATUS", "OFF");
Firebase.setInt(firebaseData,"LOCK_STATUS",0);
}
void loop() {
Blynk.run();
Firebase.getInt(firebaseData,"LOCK_STATUS");
n = firebaseData.intData();
long duration, distance;
digitalWrite(TRIGGER, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance = (duration/2) / 29.1;
Serial.print(distance);
Serial.println("Centimeter:");
delay(1000);
if(distance > 7)
{
Blynk.email("[email protected]", "Subject:Dhaka School Of Science And Technology", "The Lock has been Broken");
digitalWrite(D3,HIGH);
Firebase.setInt(firebaseData,"ALERT",1);
}
else{
Firebase.setInt(firebaseData,"ALERT",0);
}
if (n==1) {
Serial.println("LED ON");
digitalWrite(D4,HIGH);
myservo.write(60);
return;
delay(10);
}
else {
Serial.println("LED OFF");
digitalWrite(D3,LOW);
myservo.write(8);
digitalWrite(D4,LOW);
return;
}
}