-
Notifications
You must be signed in to change notification settings - Fork 2
/
radar.ino
74 lines (65 loc) · 1.04 KB
/
radar.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
#include <Servo.h>
#include <NewPing.h>
int trig=A0;
int echo=A1;
int trig1= A2;
int echo1=A3;
NewPing sonar(trig,echo);
NewPing sonar1(trig1,echo1);
Servo abc;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
abc.attach(9);
abc.write(0);
}
void loop() {
// put your main code here, to run repeatedly:
if(sonar1.ping_cm()<15)
{
Serial.println(" Object detected");
if(radar());
{
Serial.println("car Confirmed");
while(sonar1.ping_cm()<20)
{
delay (30);
}
Serial.println("Car Removed");
}
}
}
boolean radar()
{
int flag =0, flag1=0;
for(int i =90;i<150;i=i+2)
{
abc.write(i);
int d= sonar.ping_cm();
if(d>50&&d<70)
{
flag=-1;
}
else
flag=1;
delay(30);
}
for(int i=90;i>30;i=i-2)
{
abc.write(i);
int d= sonar.ping_cm();
if(d>50&&d<70)
{
flag1=-1;
}
else
flag1=1;
delay(30);
}
if (flag==-1&&flag1==-1)
{
return true;
}
else
return false;
}