-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHOME_SECURITY_SYS.ino
213 lines (172 loc) · 3.68 KB
/
HOME_SECURITY_SYS.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#define Password_Length 5
Servo myservo;
LiquidCrystal lcd(13, 12, A2, A3, A4, A5);
int pos = 0;
char Data[Password_Length];
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
bool door = false;
char customKey;
#define temppin A1
#define gaspin A0
#define buzzerpin 11
/*---preparing keypad---*/
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {8,2,3,4};
byte colPins[COLS] = {5, 6, 7};
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
/*--- Main Action ---*/
void setup()
{
myservo.attach(9, 2000, 2400);
ServoClose();
lcd.begin(16, 2);
lcd.print(" SMART DOOR");
delay(1500);
lcd.clear();
lcd.print("system activated");
delay(1000);
lcd.clear();
loading(" Loading");
lcd.clear();
Serial.begin(9600);
}
void loop()
{
//Door lock begin
if (door == true)
{
customKey = customKeypad.getKey();
if (customKey == '#')
{
lcd.clear();
ServoClose();
lcd.print("Door is closed");
delay(3000);
door = false;
}
}
else
Open();
//door lock complete
//beginning gas alarm
int gasval;
gasval = analogRead(gaspin);
gasval = map(gasval, 85, 370,0,100);
Serial.print("GAS VAL : ");
Serial.println(gasval);
if(gasval> 5 && gasval<30){
tone(11,200,1000);
}
else if(gasval>30 && gasval<70){
tone(11, 1800,1000);
}
else if (gasval > 70)
{ tone (11 , 5000,1000);
}
//gas alarm setup complete
//begginng fire alarm
double tempval = analogRead(temppin);
tempval = tempval * 5/1024;
tempval = tempval -0.5;
tempval = tempval *100;
Serial.print("TEMP : ");
Serial.println(tempval);
if(tempval> 50 && tempval<60){
tone(11,200,1000);
}
else if(tempval>60 && tempval<90){
tone(11, 1800,1000);
}
else if(tempval>90){
tone (11 , 5000,1000);
}
//fire alarm complete
}
void loading (char msg[]) {
lcd.setCursor(0, 1);
lcd.print(msg);
for (int i = 0; i <5;i++) {
delay(300);
lcd.print(".");
}
}
void clearData()
{
while (data_count != 0)
{
Data[data_count--] = 0;
}
return;
}
void ServoClose()
{
for (pos = 180; pos >= 0; pos -= 10) {
myservo.write(pos);
}
}
void ServoOpen()
{
for (pos = 0; pos <= 180; pos += 10) {
myservo.write(pos);
}
}
void Open()
{
lcd.setCursor(0, 0);
lcd.print("Enter Password");
customKey = customKeypad.getKey();
if (customKey)
{
Data[data_count] = customKey;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
data_count++;
}
if (data_count == Password_Length - 1)
{
if (!strcmp(Data, Master))
{
lcd.clear();
ServoOpen();
lcd.print(" Door is Open ");
door = true;
delay(2000);
lcd.clear();
// loading("Closing in ");
for(int i=15;i>0;i--){
lcd.setCursor(0,0);
lcd.print("Closing in ");
lcd.setCursor(12,0);
lcd.print(i);
// loading("Closing in ");
delay(1000);
lcd.clear();
}
delay(1000);
lcd.print(" Closing Door ");
delay(1000);
ServoClose();
door = false;
}
else
{
lcd.clear();
lcd.print(" Wrong Password ");
door = false;
}
delay(1000);
lcd.clear();
clearData();
}}