-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParking_sensor.ino
150 lines (139 loc) · 3.96 KB
/
Parking_sensor.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
/***** Variables to customize *****/
// Your GPIO pin number connected to trig pin
const int Trig = 1;
// Your GPIO pin number connected to echo pin
const int Echo = 3;
// Your GPIO pin number connected to first green led
const int Green_1 = 5;
// Your GPIO pin number connected to second green led
const int Green_2 = 4;
// Your GPIO pin number connected to first yellow led
const int Yellow_1 = 0;
// Your GPIO pin number connected to second yellow led
const int Yellow_2 = 15;
// Your GPIO pin number connected to first red led
const int Red_1 = 13;
// Your GPIO pin number connected to second red led
const int Red_2 = 12;
// Your GPIO pin number connected to buzzer
const int Buzzer = 14;
/**********************************/
int Value = 0;
int Measure_the_distance(){
long Time;
long Distance;
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
Time = pulseIn(Echo, HIGH);
Distance = Time / 58;
return Distance;
}
void setup() {
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
pinMode(Green_1, OUTPUT);
pinMode(Green_2, OUTPUT);
pinMode(Yellow_1, OUTPUT);
pinMode(Yellow_2, OUTPUT);
pinMode(Red_1, OUTPUT);
pinMode(Red_2, OUTPUT);
pinMode(Buzzer, OUTPUT);
digitalWrite(Green_1, LOW);
digitalWrite(Green_2, LOW);
digitalWrite(Yellow_1, LOW);
digitalWrite(Yellow_2, LOW);
digitalWrite(Red_1, LOW);
digitalWrite(Red_2, LOW);
digitalWrite(Buzzer, LOW);
}
void loop() {
Value = Measure_the_distance();
if (Value > 100){
digitalWrite(Green_1, LOW);
digitalWrite(Green_2, LOW);
digitalWrite(Yellow_1, LOW);
digitalWrite(Yellow_2, LOW);
digitalWrite(Red_1, LOW);
digitalWrite(Red_2, LOW);
digitalWrite(Buzzer, LOW);
}
if(Value <= 100 && Value > 80){
digitalWrite(Green_1, HIGH);
digitalWrite(Green_2, LOW);
digitalWrite(Yellow_1, LOW);
digitalWrite(Yellow_2, LOW);
digitalWrite(Red_1, LOW);
digitalWrite(Red_2, LOW);
digitalWrite(Buzzer, LOW);
}
if(Value <= 80 && Value > 60){
digitalWrite(Green_1, HIGH);
digitalWrite(Green_2, HIGH);
digitalWrite(Yellow_1, LOW);
digitalWrite(Yellow_2, LOW);
digitalWrite(Red_1, LOW);
digitalWrite(Red_2, LOW);
digitalWrite(Buzzer, LOW);
}
if(Value <= 60 && Value > 40){
digitalWrite(Green_1, HIGH);
digitalWrite(Green_2, HIGH);
digitalWrite(Yellow_1, HIGH);
digitalWrite(Yellow_2, LOW);
digitalWrite(Red_1, LOW);
digitalWrite(Red_2, LOW);
digitalWrite(Buzzer, LOW);
}
if(Value <= 40 && Value > 25){
digitalWrite(Green_1, HIGH);
digitalWrite(Green_2, HIGH);
digitalWrite(Yellow_1, HIGH);
digitalWrite(Yellow_2, HIGH);
digitalWrite(Red_1, LOW);
digitalWrite(Red_2, LOW);
digitalWrite(Buzzer, LOW);
}
if(Value <= 25 && Value > 10){
digitalWrite(Green_1, HIGH);
digitalWrite(Green_2, HIGH);
digitalWrite(Yellow_1, HIGH);
digitalWrite(Yellow_2, HIGH);
digitalWrite(Red_1, HIGH);
digitalWrite(Red_2, LOW);
digitalWrite(Buzzer, HIGH);
}
if(Value <= 10 && Value > 5){
digitalWrite(Green_1, HIGH);
digitalWrite(Green_2, HIGH);
digitalWrite(Yellow_1, HIGH);
digitalWrite(Yellow_2, HIGH);
digitalWrite(Red_1, HIGH);
digitalWrite(Red_2, HIGH);
digitalWrite(Buzzer, HIGH);
}
if(Value <= 5){
digitalWrite(Buzzer, HIGH);
digitalWrite(Green_1, LOW);
delay(50);
digitalWrite(Green_2, LOW);
digitalWrite(Green_1, HIGH);
delay(50);
digitalWrite(Yellow_1, LOW);
digitalWrite(Green_2, HIGH);
delay(50);
digitalWrite(Yellow_2, LOW);
digitalWrite(Yellow_1, HIGH);
delay(50);
digitalWrite(Red_1, LOW);
digitalWrite(Yellow_2, HIGH);
delay(50);
digitalWrite(Red_2, LOW);
digitalWrite(Red_1, HIGH);
delay(50);
digitalWrite(Red_2, HIGH);
delay(50);
}
}