-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDOUBLE_ULTRA.ino
167 lines (135 loc) · 3.1 KB
/
DOUBLE_ULTRA.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
#include <ESP8266WiFi.h>
#define trigPin D2
#define echoPin D3
#define trigPin1 D5
#define echoPin1 D6
const char* ssid="Bangladesh";
const char* password="yash1234";
const char* host="espnodewebsite.000webhostapp.com";
String ultrastatus = "SAFE";
String ultrastatus1 = "SAFE";
int buzz = D8;
int motor = D1;
void setup()
{
Serial.begin(115200);
delay(100);
Serial.println();
Serial.println();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(motor, OUTPUT);
pinMode(buzz,OUTPUT);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
}
void loop()
{
long duration, inches, cm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(5);
digitalWrite(trigPin, LOW);
// Take reading on echo pin
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
// Now adding all the code
//Ultrasonic Sensor Code
Serial.println("DATA OF ULTRA1");
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
if(inches<10 && inches>=7)
{
Serial.println("SAFE");
ultrastatus = "SAFE";
noTone(buzz);
digitalWrite(motor,LOW);
}
else if(inches<7 && inches>=5)
{
Serial.print("ALERT");
ultrastatus="ALERT";
noTone(buzz);
}
else if(inches<5 && inches>0)
{
Serial.print("DANGER");
ultrastatus="DANGER";
tone(buzz,1000,500);
digitalWrite(motor,HIGH);
}
long duration1, inches1, cm1;
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(5);
digitalWrite(trigPin1, LOW);
// Take reading on echo pin
duration1 = pulseIn(echoPin1, HIGH);
// convert the time into a distance
inches1 = microsecondsToInches1(duration1);
cm1 = microsecondsToCentimeters1(duration1);
// Now adding all the code
//Ultrasonic Sensor Code
Serial.println("DATA OF ULTRA 2");
Serial.print(inches1);
Serial.print("in, ");
Serial.print(cm1);
Serial.print("cm");
Serial.println();
if(inches1<10 && inches1>=7)
{
Serial.println("SAFE");
ultrastatus1 = "SAFE";
noTone(buzz);
}
else if(inches1<7 && inches1>=5)
{
Serial.print("ALERT");
ultrastatus1="ALERT";
noTone(buzz);
}
else if(inches1<5 && inches1>0)
{
Serial.print("DANGER");
ultrastatus1="DANGER";
tone(buzz,1000,500);
}
}
long microsecondsToInches(long microseconds)
{
return microseconds/74/2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds /29/2;
}
long microsecondsToInches1(long microseconds)
{
return microseconds/74/2;
}
long microsecondsToCentimeters1(long microseconds)
{
return microseconds /29/2;
}