-
Notifications
You must be signed in to change notification settings - Fork 0
/
fire_security_node.cpp
97 lines (73 loc) · 1.88 KB
/
fire_security_node.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <Arduino.h>
#include <WiFi.h>
#include <ThingSpeak.h>
#include <LittleFS.h>
#include <SD.h>
#include <Update.h>
#include <ETH.h>
#define irpin 14
#define flamepin 13
#define smokepin 33
#define ledpin1 18
#define ledpin2 16
const char* ssid = "";
const char* password = "";
WiFiClient client;
unsigned long myChannelNumber = ;
const char* myWriteAPIKey = "";
const char* server = "api.thingspeak.com";
void Connect_to_Wifi();
void flame_check();
int smoke_conc = 0;
void setup() {
Serial.begin(115200);
Connect_to_Wifi();
pinMode(flamepin, INPUT);
pinMode(smokepin, INPUT);
}
void loop() {
flame_check();
}
void Connect_to_Wifi() {
WiFi.begin(ssid, password);
WiFi.mode(WIFI_STA);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\nConnection to ThingSpeak Server Established!!!\n");
}
ThingSpeak.begin(client);
}
void flame_check() {
int flamestate = digitalRead(flamepin);
int smoke_conc = analogRead(smokepin);
int f_s = ThingSpeak.setField(3, flamestate);
int s_s = ThingSpeak.setField(4, smoke_conc);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if (flamestate == 0)
{
Serial.println("Fire Detected");
}
/* if (flamestate == 1 && irstate == 1 && smoke_conc < 650) {
Serial.println("No fire No Motion No smoke safe safe!");
}
else if (flamestate == 0 && irstate == 0) {
Serial.println("Fire Detected at living place!");
}
else if (flamestate == 1 && irstate == 0) {
Serial.println("Motion Detected!, safely no fire");
}
else if (flamestate == 0 && irstate == 1) {
Serial.println("Fire detected!, No motion :)");
}
if (smoke_conc > 800) {
Serial.print(smoke_conc);
Serial.println("SOmke detected");
}
else {
Serial.print(smoke_conc);
Serial.println("No smoke");
} */
}