-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.ino
More file actions
193 lines (172 loc) · 3.62 KB
/
Copy pathcode.ino
File metadata and controls
193 lines (172 loc) · 3.62 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <SoftwareSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
SoftwareSerial mySerial(9, 10);
SoftwareSerial bt(0,1); /* (Rx,Tx) */
/*str variable for storing input from controling devics like:mobile*/
String str;
//variables Decleration
int Fan = 8;
int Light = 9;
int Computer = 10;
int Music = 11;
int Buzzer = 13; // Use buzzer for alert
int sensor=A1;
float temp_read,Temp_alert_val,Temp_shut_val;
int sms_count=0,Fire_Set;
const int stop_button = 2;
int buttonState = 0; //reading stop alarm button state
void setup()
{
bt.begin(9600);
Serial.begin(9600);
pinMode(sensor,INPUT);
mySerial.begin(9600);
lcd.begin(16,2);
delay(500);
pinMode(Fan,OUTPUT);
pinMode(Light,OUTPUT);
pinMode(Computer,OUTPUT);
pinMode(Music,OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(stop_button, INPUT);
}
void loop()
{
//GSM firealarm alerting system
CheckFire();
automation();
buttonState = digitalRead(stop_button);
if (buttonState == HIGH)
{
// alarm on
Fire_Set=1;
}
CheckShutDown();
}
void automation()
{
//wireless bluetooth room applience controling system
if (bt.available())
{
str = bt.read();
Serial.println(str);
//Fan
if(str==”Fan on”)
{
digitalWrite(Fan,HIGH);
Serial.println(“Fan ON”);
}
else if(str=="Fan off”)
{
digitalWrite(Fan,LOW);
Serial.println(“Fan OFF”);
}
else
{
digitalWrite(Fan,LOW);
}
//Light
if(str==”Light on”)
{
digitalWrite(Light,HIGH);
Serial.println(“Light ON”);
}
else if(str==”Light off”)
{
digitalWrite(Light,LOW);
Serial.println(“Light OFF”);
}
else
{
digitalWrite(Light,LOW);
}
//Computer
if(str==”Computer on”)
{
digitalWrite(Computer,HIGH);
Serial.println(“Computer ON”);
}
else if(str==”Computer off”)
{
digitalWrite(Computer,LOW);
Serial.println(“Computer is OFF”);
}
else
{
digitalWrite(Computer,LOW);
}
//Music
if(str==”Music on”)
{
digitalWrite(Music,HIGH);
Serial.println(“Music ON”);
}
else if(str==”Music off”)
{
digitalWrite(Music,LOW);
Serial.println(“Music OFF”);
}
else
{
digitalWrite(Music,LOW);
}
}
}
//function that detect the fire
void CheckFire()
{
Temp_alert_val=CheckTemp();
if(Temp_alert_val>45)
{
SetAlert(); // Function to send SMS Alerts
}
}
float CheckTemp()
{
temp_read=analogRead(sensor); // reads the sensor output (Vout of LM35)
temp_read=temp_read*5; // converts the sensor reading to temperature
temp_read=temp_read/10; // adds the decimal point
return temp_read; // returns temperature value in degree celsius
}
void SetAlert()
{
while(sms_count<3) //Number of SMS Alerts to be sent
{
SendTextMessage(); // Function to send AT Commands to GSM module
}
//sounds the alarms
digitalWrite(Buzzer, HIGH);
}
void CheckShutDown()
{
if(Fire_Set==1)
{
Temp_shut_val=CheckTemp();
if(Temp_shut_val<28)
{
digitalWrite(Buzzer, LOW);
sms_count=0;
Fire_Set=0;
}
}
}
void SendTextMessage()
{
mySerial.println("AT+CMGF=1"); //To send SMS in Text Mode
delay(2000);
mySerial.println("AT+CMGS=\"+919544xxxxxx\"\r"); // change to the phone number you using
delay(2000);
mySerial.println("Fire in HOUSE!");//the content of the message
delay(200);
mySerial.println((char)26);//the stopping character
delay(5000);
mySerial.println("AT+CMGS=\"+919847xxxxxx\"\r"); // change to the phone number you using
delay(2000);
mySerial.println("Fire in HOUSE!");//the content of the message
delay(200);
mySerial.println((char)26);//the message stopping character
delay(5000);
sms_count++;
}