-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fire_Alarm_System.ino
65 lines (54 loc) · 1.7 KB
/
Fire_Alarm_System.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
#include <WiFi.h>
#include <FirebaseESP32.h>
// Firebase configuration
#define FIREBASE_HOST "fire-alarm-system-a8a2e-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "AIzaSyCzpL74YEKFP-xSHCyXMZE9YgeO7UW7Gnk"
// WiFi credentials
const char* ssid = "xyz";
const char* password = "9708061457";
// Define sensor and buzzer pins
#define FLAME_SENSOR_PIN 13
#define BUZZER_PIN 14
FirebaseData firebaseData;
FirebaseConfig firebaseConfig;
FirebaseAuth firebaseAuth;
void setup() {
Serial.begin(115200);
pinMode(FLAME_SENSOR_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Set Firebase host and authentication
firebaseConfig.host = FIREBASE_HOST;
firebaseConfig.signer.tokens.legacy_token = FIREBASE_AUTH;
// Initialize Firebase
Firebase.begin(&firebaseConfig, &firebaseAuth);
Firebase.reconnectWiFi(true);
}
void loop() {
int flameDetected = digitalRead(FLAME_SENSOR_PIN);
if (flameDetected == LOW) {
Serial.println("Flame detected!");
digitalWrite(BUZZER_PIN, HIGH);
if (Firebase.setBool(firebaseData, "/fireDetected", true)) {
Serial.println("Firebase updated: fireDetected = true");
} else {
Serial.println("Failed to update Firebase");
}
} else {
Serial.println("No flame detected.");
digitalWrite(BUZZER_PIN, LOW);
if (Firebase.setBool(firebaseData, "/fireDetected", false)) {
Serial.println("Firebase updated: fireDetected = false");
} else {
Serial.println("Failed to update Firebase");
}
}
delay(2000);
}