-
Notifications
You must be signed in to change notification settings - Fork 0
/
HNA_v1.0.1.ino
224 lines (219 loc) · 6.13 KB
/
HNA_v1.0.1.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
// -<HNA>- v1.0.1 -<ⓇBlue Carrot Studio>-
// Helium's New Alarm, open source project, created by BCS
// You can edit the program if you want ;)
// Have fun!
#define echoPin 11
#define trigPin 12
long duration;
int distance;
int buz = 3;
int button = A1;
int led1 = 4;
int led2 = 5;
int led3 = 6;
int led4 = 9;
int led5 = 10;
int led6 = 8;
int mode = 0; //0 idle, 1 calibration, 2 armed
int distlimit;
int val_butt;
void setup() {
pinMode(buz, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led5, LOW);
delay(1000);
digitalWrite(led4, LOW);
delay(1000);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led2, LOW);
delay(1000);
digitalWrite(led1, LOW);
Serial.begin(9600);
Serial.println("Alarm ready! -<Helium's alarm>-");
}
void loop() {
val_butt = analogRead(button);
if (val_butt >= 720 and val_butt <= 725) {
delay(10);
val_butt = analogRead(button);
if (val_butt >= 720 and val_butt <= 725) {
if (mode == 0) {
Serial.println("Mode -> 1 (calibraton)");
digitalWrite(buz, HIGH);
digitalWrite(led1, HIGH);
delay(200);
digitalWrite(buz, LOW);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
distlimit = distance + 10;
if (distance < 100) {
digitalWrite(led1, HIGH);
} else if (distance < 150) {
digitalWrite(led1, HIGH);
} else if (distance < 200) {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led2, HIGH);
} else if (distance < 250) {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led3, HIGH);
} else if (distance < 300) {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led3, HIGH);
delay(500);
digitalWrite(led4, HIGH);
}
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(buz, LOW);
delay(200);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(buz, HIGH);
delay(200);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(buz, LOW);
delay(200);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(buz, HIGH);
delay(200);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(buz, LOW);
Serial.print("Distance: ");
Serial.println(distance);
Serial.print("Distance Limit: ");
Serial.println(distlimit);
mode = 1;
} else if (mode == 1) {
Serial.println("Mode -> 2 (armed)");
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(buz, LOW);
delay(800);
digitalWrite(led6, LOW);
digitalWrite(buz, HIGH);
delay(800);
digitalWrite(led6, HIGH);
digitalWrite(buz, LOW);
delay(800);
digitalWrite(led6, LOW);
digitalWrite(buz, HIGH);
delay(800);
digitalWrite(led6, HIGH);
digitalWrite(buz, LOW);
delay(800);
digitalWrite(led6, LOW);
digitalWrite(buz, HIGH);
delay(800);
digitalWrite(led6, HIGH);
digitalWrite(buz, LOW);
mode = 2;
}
}
}
if (mode == 2) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//calculating the distance
distance = duration * 0.034 / 2; //speed of sound wave divided by 2 (go and back)
if (distance > distlimit) {
Serial.print("ALARM ACTIVATED WITH DISTANCE = ");
Serial.println(distance);
digitalWrite(buz, HIGH);
delay(10000);
digitalWrite(led1, HIGH);
delay(10000);
digitalWrite(led2, HIGH);
delay(10000);
digitalWrite(led3, HIGH);
delay(10000);
digitalWrite(led4, HIGH);
delay(10000);
digitalWrite(led5, HIGH); //dopo 50 sec
delay(5000);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led2, LOW);
delay(1000);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led4, LOW);
delay(1000);
digitalWrite(led5, LOW);
delay(1000);
digitalWrite(led6, LOW);
digitalWrite(buz, LOW);
delay(1000);
digitalWrite(led6, HIGH);
}
val_butt = analogRead(button);
if (val_butt >= 720 and val_butt <= 725) {
delay(10);
val_butt = analogRead(button);
if (val_butt >= 720 and val_butt <= 725) {
Serial.println("Mode -> 0 (idle)");
mode = 0;
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(buz, LOW);
delay(500);
digitalWrite(led4, HIGH);
}
}
}
}