-
Notifications
You must be signed in to change notification settings - Fork 0
/
fire_detection.ino
181 lines (147 loc) · 3.96 KB
/
fire_detection.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "LiquidCrystal_I2C/LiquidCrystal_I2C.h"
#include "LiquidCrystal_I2C/LiquidCrystal_I2C.cpp"
#include "MQ135/MQ135.h"
#include "MQ135/MQ135.cpp"
#include "DHT11/src/DHT11.h"
#include "DHT11/src/DHT11.cpp"
#include <Servo.h>
#include "Pitches/pitches.h"
Servo myservo;
int Buzz = 13;
int IR_Left = 12;
DHT11 dht11(11);
int FlameLeftGreen = 10;
int Servo = 9;
int FlameLeftRed = 3;
int IR_Right = 8;
int FlameRightRed = 7;
int FlameRightGreen = 6;
int Pump = 5;
int IR_Mid = 4;
#define FlameMidGreen A0
#define FlameMidRed A1
#define PIN_MQ135 A2
MQ135 mq135_sensor(PIN_MQ135);
int FlameLeft=0;
int FlameRight=0;
int FlameMid=0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(Buzz,OUTPUT);
pinMode(Pump,OUTPUT);
pinMode(IR_Left,INPUT);
pinMode(IR_Right,INPUT);
pinMode(IR_Mid,INPUT);
pinMode(FlameRightRed,OUTPUT);
pinMode(FlameRightGreen,OUTPUT);
pinMode(FlameMidGreen,OUTPUT);
pinMode(FlameMidRed,OUTPUT);
pinMode(FlameLeftRed,OUTPUT);
pinMode(FlameLeftGreen,OUTPUT);
myservo.attach(9);
dht11.setDelay(500);
PEACE();
}
void loop() {
int temperature = 0;
int humidity = 0;
int result = dht11.readTemperatureHumidity(temperature, humidity);
float rzero = mq135_sensor.getRZero();
float correctedRZero = mq135_sensor.getCorrectedRZero(temperature, humidity);
float resistance = mq135_sensor.getResistance();
float ppm = mq135_sensor.getPPM();
float correctedPPM = mq135_sensor.getCorrectedPPM(temperature, humidity);
int FlameLeft=(digitalRead(IR_Left));
FlameLeft=!FlameLeft; //Flame is inversed.
int FlameRight=(digitalRead(IR_Right));
FlameRight=!FlameRight; //Flame is inversed.
int FlameMid=(digitalRead(IR_Mid));
FlameMid=!FlameMid; //Flame is inversed.
if (result == 0) {
Serial.print("\tTemperature: ");
Serial.print(temperature);
Serial.print(" °C\tHumidity: ");
Serial.print(humidity);
Serial.print(" %");
Serial.print("\tFlameLeft = ");
Serial.print(FlameLeft);
Serial.print("\tFlameRight = ");
Serial.print(FlameRight);
Serial.print("\tMQ135 RZero: ");
Serial.print(rzero);
Serial.print("\tCorrected RZero: ");
Serial.print(correctedRZero);
Serial.print("\tResistance: ");
Serial.print(resistance);
Serial.print(" PPM: ");
Serial.print(ppm);
Serial.print("\tCorrected PPM: ");
Serial.print(correctedPPM);
Serial.println("ppm");
Serial.println(".");
lcd.setCursor(0,1);
lcd.print("Temp ");
lcd.print(temperature);
lcd.print("C Hum ");
lcd.print(humidity);
lcd.print("%");
}
if(FlameLeft || FlameRight|| FlameMid){
if(FlameLeft) AAGLeft();
if(FlameMid) AAGMid();
if(FlameRight) AAGRight();
// direction(FlameLeft, FlameMid, FlameRight);
}
else PEACE();
}
void direction(int l, int m, int r){
if (l || m || r) myservo.write(90);
else if (l || m) myservo.write(68);
else if (r || m) myservo.write(113);
else if (l) myservo.write(45);
else if (m) myservo.write(90);
else if (r) myservo.write(135);
}
void AAGLeft(){
myservo.write(45);
digitalWrite(FlameLeftGreen,0);
digitalWrite(FlameLeftRed,1);
digitalWrite(Pump,1);
digitalWrite(Buzz,1);
lcd.setCursor(3,0);
lcd.print(" Fire ! ");
}
void AAGMid(){
myservo.write(90);
analogWrite(FlameMidGreen,0);
analogWrite(FlameMidRed,1020);
digitalWrite(Pump,1);
digitalWrite(Buzz,1);
lcd.setCursor(3,0);
lcd.print(" Fire ! ");
}
void AAGRight(){
myservo.write(135);
digitalWrite(FlameRightGreen,0);
digitalWrite(FlameRightRed,1);
digitalWrite(Pump,1);
digitalWrite(Buzz,1);
lcd.setCursor(3,0);
lcd.print(" Fire ! ");
}
void PEACE(){
myservo.write(90);
digitalWrite(FlameLeftGreen,1);
digitalWrite(FlameLeftRed,0);
digitalWrite(FlameRightGreen,1);
digitalWrite(FlameRightRed,0);
analogWrite(FlameMidGreen,1020);
analogWrite(FlameMidRed,0);
digitalWrite(Pump,0);
digitalWrite(Buzz,0);
lcd.setCursor(3,0);
lcd.print("Peace Hai !");
}