-
Notifications
You must be signed in to change notification settings - Fork 1
/
Fall detetction system arduino.ino
174 lines (138 loc) · 3.04 KB
/
Fall detetction system arduino.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
#include <LiquidCrystal.h>
#include<Blynk.h>
#include <BlynkSimpleStream.h>
//Your app authentication token (can be fetched from your blynk app
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXX";//Enter blynk auth token
BlynkTimer timer;
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
const int lm1 = 2;
const int lm2 = 3;
const int rm1 = 4;
const int rm2 = 5;
long duration, inches, cm;
const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
const int buzzer=A0;
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor
void sendSensor()
{
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
if(cm < 390)
{
buzzer_func();
stop();
delay(100);
go_back();
delay(100);
stop_again();
delay(100);
go_right();
delay(100);
}
else
{
go_straight();
delay(100);
}
Blynk.virtualWrite(V5, cm);
if(cm<380)
{
Blynk.email("[email protected]", "OBSTACLE ALERT!", "FALL DETECTED");
}
}
void setup() {
// put your setup code here, to run once:
pinMode(lm1, OUTPUT);
pinMode(lm2, OUTPUT);
pinMode(rm1, OUTPUT);
pinMode(rm2, OUTPUT);
pinMode(buzzer,OUTPUT);
lcd.begin(16, 2);
Serial.begin(9600);
Blynk.begin(auth, Serial);
timer.setInterval(2000L, sendSensor);
}
void loop() {
Blynk.run();
timer.run();
Blynk.notify("Device started");
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
void go_straight()
{
lcd.setCursor(0,0);
lcd.print("NOTHING AHEAD");
lcd.setCursor(0,1);
lcd.print("SAFE TO MOVE FORWARD");
digitalWrite(lm1,HIGH);
digitalWrite(lm2,LOW);
digitalWrite(rm1,HIGH);
digitalWrite(rm2,LOW);
}
void go_back()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("TAKING REVERSE");
lcd.setCursor(0,1);
lcd.print(cm);
digitalWrite(lm2,HIGH);
digitalWrite(lm1,LOW);
digitalWrite(rm2,HIGH);
digitalWrite(rm1,LOW);
}
void stop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SOMETHING AHEAD");
lcd.setCursor(0,1);
lcd.print("STOP!!");
digitalWrite(lm1,LOW);
digitalWrite(lm2,LOW);
digitalWrite(rm1,LOW);
digitalWrite(rm2,LOW);
}
void stop_again()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("STOP FOR TURN");
digitalWrite(lm1,LOW);
digitalWrite(lm2,LOW);
digitalWrite(rm1,LOW);
digitalWrite(rm2,LOW);
}
void go_right()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("TURNING RIGHT");
lcd.setCursor(0,1);
lcd.print(cm);
digitalWrite(lm1,HIGH);
digitalWrite(lm2,LOW);
digitalWrite(rm1,LOW);
digitalWrite(rm2,LOW);
}
void buzzer_func()
{
tone(buzzer,1000);
delay(200);
noTone(buzzer);
}