Automatic Parking System With 2 Lanes
by Vandan_Patel in Circuits > Arduino
125 Views, 5 Favorites, 0 Comments
Automatic Parking System With 2 Lanes
Hi, my name is Vandan Patel. For my Tech class' final project, I decided to create an automatic parking system (with 2 servos, 4 distance sensors, and a different exit and entry lane), inspired from Hannah Khairunnisa Filzah, and with my first sighting on my Instagram feed.
In this system the first distance sensor, with triple check that an object is in front of it, then the barrier will open until the sensor after the barrier clears the car entering. The barrier doesn't have a certain delay to close the barrier, its coded to ensure the barrier doesn't close on the car. Same thing for the exit logic on the other side. The LCD will display how many spots are left, and if a car trys to enter when 0 slots lefts, it will warn them that the parking is full.
This circuit operates using an Arduino Uno, 2 micro servos, 4 distance sensors, RGB LEDs, and an LCD screen.
Now that you understand how the project works, let's move on to the materials and components required to build it.
Supplies
CIrcuit Parts:
- HC-SR04 Ultrasonic Sensor (4x)
- Servo Motor (2x)
- I2C LCD Screen 0x27
- Large Solderless Breadboard (2x)
- Arduino Uno
- RGB LEDs (4x)
- Female to Male Wires (4x)
- Male to Male Wire (6x)
- 330Ω Resistor (2x)
- Jumper Wires
Note: 2 Breadboards recommended for clean and easier wiring
Design Materials:
- Cardboard
- Paint / Coloured Paper
- Thick Paper Straw
- Thin Straw
- Hot Glue Gun & Hot Glue Stick
Connect Breadboards Together and Arduino to Power Rails
I've used 2 breadboards to make my Automatic Parking System, for easier wiring, and to make it look cleaner. This will ensure that your connections are accurate and not overlapping one another, helping you limit any mistakes. Connect the 2 breadboards using the preinstalled slots on the side of the breadboard.
Along with that place Arduino on the centre of the 2 breadboards.
Wire from Arduino to:
- 5V pin → + rail
- GND → - rail
Also connect each breadboard's negative rails to one another, as shown in the visual.
Connect HC-SR04 to Breadboard and Arduino
Place the all 4 of the HC-SR04 sensors along the corners of the breadboard. Ensure that each sensor pin is on its on numbered column and that there is only 1 row behind the sensor (Check picture).
Wire each sensor's VCC and GND pins to the rails:
- VCC → 5V rail
- GND → GND rail
After wiring each sensor to the rails push the sensor forward, making it easier to wire the TRIG and ECHO pins from behind the sensor.
Now that all the sensors are getting power and they're all connected to GND, we can now connect each sensor's Trig and Echo pin to the Arduino
Wire from HC-SR04 to Arduino:
- Entry Sensor 1 (This will be first sensor that will open the entry motor):
- TRIG Pin → D2
- ECHO Pin → D3
- Entry Sensor 2 (This sensor will come after the entry motor):
- TRIG Pin → D4
- ECHO Pin → A0
- Exit Sensor 1 (This sensor will open the exit motor):
- TRIG Pin → D7
- ECHO Pin → A1
- Exit Sensor 2 (This sensor will come after the exit motor)
- TRIG Pin → D13
- ECHO Pin → A2
Check the pictures for a visual representation
Connect Micro Servos
Using the male to male wires, connect each end of the wires to one of the female pin slots on the servo. TIP: Tape the connection so that they don't fall out from the
Now connect the other end of the male according to the wire colour on the motor:
Entry Servo:
- Brown wire → GND rail
- Red wire → 5V rail
- Yellow wire → D9
Exit Servo:
- Brown wire → GND rail
- Red wire → 5V rail
- Yellow wire → D8
Then add tape to the bottom of the servo and place it in the middle of the 2 sensors for each side. Ensure that the servos are correctly placed according to their entry/exit sensor.
Connect LCD Screen
Connect the LCD using the 4 female to male wires. If you don't have female to male, and you're only limited to male to male and female to female, connect them together to create a male to female connector.
Use tape to connect the female side together, so it's easier to attach on the LCD.
Wire LCD to breadboard and Arduino:
- GND → GND rail
- VCC → 5V rail
- SDA → A4
- SDL → A5
Connect RGB LEDs
This is a special addition I added to my project to make it feel very realistic. These 4 RGB LEDs, will later be mounted on each barrier, so 2 on the entry barrier and 2 on the exit barrier. Since the LEDs will be mounted on the barrier, we need long jumper wires to connect the RGB from the barrier to the arduino. Now connect the legs of the 2 RGB together (look at picture for visual):
- + leg → + leg
- R leg → R leg
- G leg → G leg
Then strip a large chunk off the wire, to connect the 2 RGBs together as shown in the picture. Using the stripped portion of the jumper wire wrap it around each leg that was connected earlier (look at picture for reference).
Copy this for the other side's set of RGB.
Now that we have 2 sets of RGB's (2 in each set), with the long wires connect, strip the other side of the wire, so we can connect it to the breadboard and arduino.
After stripping the small portion, connect it to the arduino and breadboard:
Entry Barrier:
- + leg wire → 330Ω → 5V rail (Connect resistor to 5V rail and place the other terminal in an empty column)
- R leg wire → D10
- G leg wire → D11
Exit Barrier:
- + leg wire → 330Ω → 5V rail
- R leg wire → D5
- G leg wire → D6
There is no need for the B leg, because the only colours we're going to use is red and green. The leg it self will be useful to mount on the actual barrier.
Code
Finally, the code!
Here is an copy of the code both the ino and Automatic Parking System code which provides the exact code for this project. The ino and Automatic Parking System attached above are the same codes, just in different file formats, however, the ino code attached named Hannah_Khairunnisa_Filzah is with the original reference, which is another code I referenced for this project. Their code includes all the original functions, without any of the stuff I added, so if you plan to make just making it with 2 IR sensors, and only 1 motor, please follow that code.
For my code, the biggest changes I made was adding 4 distance sensors, 2 servos, and 4 RGB LEDs. I added 4 distance sensors because I was more familiar with that component compared to the IR sensor. Also, I added 2 servos because I didn't want the exit and entry to be in the same lane, so I added 2 separate lanes and servos for each lane. Lastly, the RGB LEDs adds a unique touch to the barrier, when it opens it turns green, and when closed the RGB changes to red. This makes the system feel more realistic and smooth. The LCD screen makes it even realistic, and displays if there are any spots left, if not then it tells the driver that parking is full
Another change I made was improving my code so that there are limited to none errors. When refining the code I was able to create variables to ensuring my code and project runs smoothly. The entryCount variable helps triple check that there is something infront of the sensor. When it passes through that only then will it open the barrier.
In general, the original code gave me the base level parking system, while my version offers greater advantages, with the LCD screen, RGB LEDs, 2 servos, and 4 sensors for accurate measuring.
Although all the code is provided, I recommend making your own code and adding different additions to this project. The reason for this is that my code is fully functional but there is one error which I will explain below
Note: Do not forget to initialize the correct pins for your project as each code has different pinouts, so please double check or edit before copy and pasting!
Here is the inspiration project: https://www.hackster.io/518759/automatic-car-parking-system-using-arduino-uno-b24-fed323
Developing the Code
When I made this code, it worked flawlessly but when I tested it, it showed me a tiny but very important error. When the slots left are 0 and another car approaches the entry sensor to enter, the LCD screen displays that it's full, which works perfectly fine. Until, the car parked inside also approaches the exit sensor. The car might have to wait for about 3 seconds to open the barrier, and when exiting the barrier doesn't close because of the car trying to enter.
When you analyze this part of the main code:
The delay(3000); makes the entire project get delayed by 3 seconds, which explains why the exit barrier doesn't open or close on time.
A suggestion to fix this is to replace the blocking delay with a non-blocking timer based on millis(). Instead of pausing execution, the function records the time the message started. A separate check, run every loop cycle, compares the current time to that timestamp and restores the normal display once 3 seconds have elapsed, without ever stopping the rest of the program.
Here is the video showcasing the error:
Downloads
Video Demonstration
Here are some videos demonstrating how the project works in real life.
Downloads
Optional: Make a Prop
Adding a prop will enhance the overall experience of the barrier opening, and the cars entering. You can make it using cardboard, paint or coloured paper. The thick straws seen on the prop will hold up the LCD screen.
You can also make the barrier using a red straw and small striped of white paper glued on top of the straw.
References / Works Cited
Inspiration Project: https://www.hackster.io/518759/automatic-car-parking-system-using-arduino-uno-b24-fed323
Instagram: https://www.instagram.com/reel/DVul4Ncoy_m/
ArduinoDOCS Library:
LCD Library: https://docs.arduino.cc/learn/electronics/lcd-displays/
Micro Servo: https://docs.arduino.cc/learn/electronics/servo-motors/
Wire Communication: https://docs.arduino.cc/learn/communication/one-wire/