-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparking_spot_finder.ino
53 lines (45 loc) · 1.26 KB
/
parking_spot_finder.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
#define trigPin 13
#define echoPin 12
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(5, OUTPUT); //pin of motor-A
pinMode(6, OUTPUT); //pin of motor-A
pinMode(9, OUTPUT); //pin of motor-B
pinMode(10, OUTPUT); //pin of motor-B
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2); // wait for 2 seconds.
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1; //calculating the distance
if (distance < 7) { // This is where the LED On/Off happens
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
}else { //we are performing the parking when the car finds at least 7 cm space.
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
analogWrite(6, 110);
analogWrite(5, LOW);
delay(50);
digitalWrite(10,LOW);
digitalWrite(9,HIGH);
analogWrite(5, 110);
analogWrite(6, LOW);
delay(100);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
analogWrite(5, 110);
analogWrite(6, LOW);
delay(100);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
analogWrite(5, LOW);
analogWrite(6, LOW);
delay(1000);
}
}