
In this project we will simulate an automated parking barrier with Arduino. This model resumes the general operation of automated systems that allow access to public parks that can be found in stations, airports, cinemas, supermarkets, etc.
Our barrier opens with a servo motor when the HC-sound sensorSR04 detects a vehicle and closes automatically if not.
To make the assembly, we can connect:
For first HC-SR04 sensor:
For second HC-SR04 sensor:
For motor servo
For Module LED RGB:
Here is the program for the automated parking system:
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 |
#include <HCSR04.h> #include <Servo.h> Servo monServomoteur; const int servoPin=2; const int trig1Pin = 3; const int echo1Pin = 4; const int trig2Pin = 5; const int echo2Pin = 6; const int LEDrouge=7; const int LEDvert=8; int position = 180; UltraSonicDistanceSensor distanceSensor1(trig1Pin, echo1Pin); UltraSonicDistanceSensor distanceSensor2(trig2Pin, echo2Pin); void setup(){ monServomoteur.attach(servoPin); pinMode(LEDrouge,OUTPUT); pinMode(LEDvert,OUTPUT); } void loop(){ if(((((distanceSensor1.measureDistanceCm()+1)<6)&&(distanceSensor1.measureDistanceCm()+1)>0))||((distanceSensor2.measureDistanceCm()+1<6)&&(distanceSensor2.measureDistanceCm()+1)>0)) {// If one of the two HC-SR04 sensors detects a vehicle monServomoteur.write(90); // the barrier open digitalWrite(LEDrouge,LOW); digitalWrite(LEDvert,HIGH); // The LED lights up in green delay(5000); }else { monServomoteur.write(180); digitalWrite(LEDrouge,HIGH); // The LED lights up in red digitalWrite(LEDvert,LOW); // the barrier closes } delay(100); } |