-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeShh.ino
294 lines (232 loc) · 5.26 KB
/
HomeShh.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// HomeShh - IoT Specialization Capstone Project
// Smart home for deaf people
// Apache License
// Copyright 2017 Niam Moltta
// Simulator "Заткнись дом": https://www.tinkercad.com/things/afNAJcOk2rS-sim-zatknis-dom-/editel?sharecode=b4-hxomIlO_lSzW6PpGuVMrkRsW0HRKllROT_KIAYx4=
// Copy the circuit from the simulator above and use the code below to perform the simulation.
/*
The simulation includes a house (drawn as cables), you can see the reference at the README.md file in this repository.
Once you are running the simulation, you can activate/deactivate the sensors manually and see how the HomeShh works.
There are gif files at the README.md where you can see a couple of demostrations.
*/
// Light settings:
const int G =12; // green
const int B =11; // blue
const int R =13; // red
const int S = 10; // buzzer
const int A = 8; // red
const int C = 7; // green
const int D = 6; // blue
const int K = 5; // PIR kitchen and garage
const int M = 9; // fan
const int E = 4; // PIR garage light
const int F = 3; // relay outside lights
const int L = 2; // relay garage light
const int Y = A3; // phone
const int P = A2; // doorbell
const int V = A0; // fire in the kitchen
const int W = A1; // fire in the garage
int s = 0;
int c = 0;
int ms = 0;
int db = 0;
void setup()
{
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
pinMode(R, OUTPUT);
pinMode(S, OUTPUT);
pinMode(M, OUTPUT);
pinMode(A, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(F, OUTPUT);
pinMode(L, OUTPUT);
Serial.begin(9600);
pinMode(K, INPUT);
pinMode(V, INPUT);
pinMode(E, INPUT);
pinMode(W, INPUT);
pinMode(Y, INPUT);
pinMode(P, INPUT);
Nothing();
OffS();
digitalWrite(M, LOW);
digitalWrite(L, LOW);
digitalWrite(F, LOW);
digitalWrite(S, LOW);
noTone(S);
}
void loop() {
// Car in the garage (when motion sensor is activated in simulator)
long car = digitalRead(E);
if(car == HIGH) {
digitalWrite(L, HIGH);
delay(5000); //time for simulation purposes
}
else
{
digitalWrite(L, LOW);
}
//Fire simulation (smoke detector is activated in the simulator)
s = analogRead(V);
Serial.println("Smoke Signal K");
Serial.println(s);
if (s > 100) {
Fire();
FireS();
tone(S, 1000);
delay(2000);
analogWrite(M, 255);
}
else {
noTone(S);
Nothing();
OffS();
}
ms = analogRead(W);
Serial.println("Smoke Signal G");
Serial.println(ms);
if (ms > 100) {
Fire();
FireS();
tone(S, 1000);
delay(2000);
analogWrite(M, 255);
}
else {
noTone(S);
Nothing();
OffS();
}
// Phone simulation (pushbutton is pressed in the simulator)
c = analogRead(Y);
Serial.println("call");
Serial.println(c);
if (c == 1023) {
Phone();
PhoneS();
tone(S, 700);
delay(1000);
analogWrite(M, 255);
}
else {
noTone(S);
Nothing();
OffS();
}
// Doorbell simulation (pushbutton is pressed in the simulator)
db = analogRead(P);
Serial.println("Signal");
Serial.println(db);
if (db == 1023) {
Doorbell();
DoorbellS();
tone(S, 330);
delay(350);
tone(S, 261);
delay(350);
analogWrite(M, 255);
}
else {
noTone(S);
Nothing();
OffS();
}
// Burglar Simulation (one or both of the motion sensors at the house entrances are activated in the simulator)
long b = digitalRead(K);
if(b == HIGH) {
Robbery();
RobberyS();
tone(S, 440, 5000);
digitalWrite(F, HIGH);
Serial.println(b);
delay(200);
analogWrite(M, 255);
}
else
{
OffS();
noTone(S);
}
}
// Functions for RGB lights:
void Fire() {
//RED!
digitalWrite(R, HIGH);
digitalWrite(B, LOW);
digitalWrite(G, LOW);
}
void Doorbell() {
//GREEN
digitalWrite(R, LOW);
digitalWrite(B, LOW);
digitalWrite(G, HIGH);
}
void Robbery() {
//BLUE
digitalWrite(R, LOW);
digitalWrite(B, HIGH);
digitalWrite(G, LOW);
}
void Noise() { //ABOVE 120db!!!
//MAGENTA
digitalWrite(R, HIGH);
digitalWrite(B, HIGH);
digitalWrite(G, LOW);
}
void Phone() {
//CYAN
digitalWrite(R, LOW);
digitalWrite(B, HIGH);
digitalWrite(G, HIGH);
}
void Nothing() {
//YELLOW
digitalWrite(R, HIGH);
digitalWrite(B, LOW);
digitalWrite(G, HIGH);
}
// BEDROOM FAN ALARM RGB (In real life this would have a reset button next to the bed so the fan could be reset by user after waking up)
void FireS() {
//RED!
digitalWrite(A, HIGH);
digitalWrite(D, LOW);
digitalWrite(C, LOW);
}
void DoorbellS() {
//GREEN
digitalWrite(A, LOW);
digitalWrite(D, LOW);
digitalWrite(C, HIGH);
}
void RobberyS() {
//BLUE
digitalWrite(A, LOW);
digitalWrite(D, HIGH);
digitalWrite(C, LOW);
}
void NoiseS() { //ABOVE 120db!!!
//MAGENTA (the simulator doesn't have microphones)
digitalWrite(A, HIGH);
digitalWrite(D, HIGH);
digitalWrite(C, LOW);
}
void PhoneS() {
//CYAN
digitalWrite(A, LOW);
digitalWrite(D, HIGH);
digitalWrite(C, HIGH);
}
void NothingS() {
//YELLOW
digitalWrite(A, HIGH);
digitalWrite(D, LOW);
digitalWrite(C, HIGH);
}
void OffS() {
digitalWrite(A, LOW);
digitalWrite(D, LOW);
digitalWrite(C, LOW);
}
// END of functions