Hi Geeks, welcome to our new project. Our new project is one of the most common issues you’ve seen in your cities. In this project, we are going to make a car parking system with automatic billing. In the entire world, there are an estimated 1.4 billion cars on the road, which is absolutely great news if we are considering the development of the Automobile industry. But the most serious issue is that the number of cars exceeds the number of available parking places, resulting in traffic congestion. Damaged cars due to this lack of space, fewer parking locations, lack of parking signage, informal parking, and overcharging for parking are just a few of the issues.
People are still choosing manual parking methods, which have a number of drawbacks, such as searching for a vacant spot in a parking lot without knowing if the lot is full or not, resulting in time and fuel waste. Vehicle safety is also a concern that may be addressed. We've all been in a position when we've spent a long time looking for parking at a location just to discover that none is available. You would think that if you knew the slots were full, you would've ended up finding another parking spot.
Based on these scenarios, we came up with the idea of a Car Parking System with Automatic Billing which will also reduce manpower such as security, booth attendants, etc., required in parking lots. Everything in the modern day is automated, and with this project, we can automate this procedure using simple electronics components and Arduino. Let's get started.
Software to install:
Instead of using real components, we'll use the Proteus Simulation tool to design this project. It's also a good habit to experiment with simulations before attempting to build everything with real components. By simulating an issue that may develop when working on actual components, we may identify the problem and avoid any damage to our components.
Proteus is an interesting software that lets you model and build electronics circuits. Despite having a huge library of electronics components, Proteus software lacks pre-installed modules such as Arduino boards, Ultrasonic sensors, RTC modules, LCD modules, and so on.
Now, we’ll start installing the libraries, which is needed for our project:
- Arduino Library for Proteus: We have to add the Arduino boards to the Proteus components list.
- LCD Module for Proteus: We have to add the LCD module to Proteus Suite.
- Ultrasonic sensor: We have to add the Ultrasonic sensor to Proteus Suite.
- RTC Module: We have to add the RTC Module to Proteus Suite.
By clicking the button below, you can download the entire project, including Proteus Simulation and Arduino Code.
These are required components for Accident Detection, which are as follows:
- Arduino Uno: Arduino Uno is a development board from the Arduino family, which is the main component of this project and acts as the brain. The Microcontroller i.e., Arduino is responsible for the decisions that are going to be processed in the project.
- 20X4 LCD display: It is used to display the information regarding parking slots and shows the amount that has to be paid by the driver at the Check out time from the parking lot.
- Ultrasonic Sensor: It is used to calculate the distance from the car to the entry gate and detects that a car has reached near the gate.
- RTC Module: Real-Time Clock Module is used to calculate the time and plays a key role in determining the total amount for the parking slot.
- Arduino Uno
- LCD Module
- Ultrasonic Sensor
- Keypad 3x4
- RTC Module
- Any Arduino development board can be used in this project, however, we'll be using Arduino UNO development boards. The Arduino UNO is a programmable, open-source microcontroller board from the Arduino series.
- It contains an ATMega328P microcontroller from Atmel, which has an 8-bit RISC processing core and 32 KB of flash memory.
- The Arduino UNO includes 14 digital I/O pins i.e., D0 - D13, with a resolution of 10 bits, including 6 PWM pins and 6 analog I/O pins (0-1024) i.e., A0 - A5.
- Only one hardware UART peripheral pin, one I2C peripheral pin, and one SPI peripheral pin are available on the Arduino UNO (however we can use other pins for UART communication using the SoftwareSerial package in Arduino).
- The Arduino UNO can be powered from a voltage range of 7 to 12 volts, the voltage regulator embedded inside the board will reduce the excess voltage. however, not more than 9 volts is suggested since it might harm the Arduino board.
- A USB-B cable (the same cable that we used to upload the sketch to Arduino UNO), a DC power jack, and the Vin pin on the board may all be used to power Arduino UNO.
- Using the Arduino IDE Software, the sketch is written and uploaded to the Arduino UNO. It is completely free, simple to comprehend, and easy to combine with a variety of electronic components.
LCD Module:In this project, an LCD display is used to present the information to the user.
- LCD stands for Liquid Crystal Display, and it is a type of display that is made using Liquid Crystal technology.
- LCDs come in a variety of sizes; in this project, we utilized a 20X4 size.
- The 20X4 indicates that it can show 80 ASCII characters at once.
- The LCD has 16 pins. In which the necessary pins are connected in the circuit.
- It contains eight data pins, one Read/Write select pin, one Register mode pin, one Enable pin, two backlight pins, two power supply pins, and one contrast control pin.
- In the LCD, there are primarily two types of registers: Command Register and Data Register.
- When the RS(Register Select) pin is set to logic high, the data register mode is selected, and when it is set to logic low, the command register mode is selected.
The RS pin will be set to logic high to display the data on the LCD.
Ultrasonic Sensor (HR-SR04):
- The HC-SR04 ultrasonic sensor employs SONAR to estimate the distance of an object.
- The ultrasonic sensor sends out a signal wave that has a frequency of about 40 kHz, with a high pitch that humans are unable to hear.
- From 2 cm to 400 cm (1" to 13 feet), it provides the detection of objects with high accuracy and the pulse will not be disturbed by sunlight or any climate conditions.
- It consists of four pins, Trig, Echo, VCC, and GND.
- The operating voltage of an Ultrasonic sensor is 5V. We can connect the VCC pin of the sensor with 5V output in Arduino and the sensor will work perfectly.
- Ultrasonic sensors work on the principle of sound wave reflection.
- The trig pin works as an ultrasound transmitter which emits the high frequency sound waves in pulses. And the echo pin works as an ultrasound receiver. It receives the reflected ultrasonic waves which are bounced back from the object.
- We calculate the distance from the object and the sensor by measuring the time taken between the transmission and the reception of the signal.
- To measure the distance of sound traveled from trig to echo,
Distance = (Time x SpeedOfSound) / 2.Speed of Sound: 340 meters per second i.e., 0.034
- The easiest way to calculate the distance in cm is using this formula,
Distance in Centimeters = (( Time taken by pulse signal (in microseconds) / 2) / 29)
- A keypad button is used for user input.
- The keypad's buttons are arranged as a matrix of 3x4. Which means it has four rows and three columns.
- They work on the principle of membrane keypads. They are very flexible and feel like a push button.
- The switch between a column and a row trace is closed when a button is pressed, allowing current to pass between a column pin and a row pin.
- A copper padding and line beneath the pad connects each switch in a row to the other switches in the row.
RTC Module (DS1307):
- The DS1307 IC is a low-cost, high-accuracy RTC that uses the I2C protocol as an interface.
- The DS1307 features a backup battery mounted on the rear of the module to maintain track of time even if the main power supply is disconnected.
- When necessary, the chip shifts between the primary and backup power sources.
- The RTC records information such as seconds, minutes, hours, days, dates, months, and years.
- This module includes a Reference clock, programmable Square wave output(SQW), SCL, SDA, VCC, and GND.
- Automatic Power-Fail Detect and Switch Circuitry
- Low Power Operation Extends Battery-Backup Run Time.
- The RTC module works on operating voltage 5V.
Proteus Simulation of Car Parking System:
Now, it’s time to start the design of the Proteus Simulation of our Car parking system
- Before you begin designing, make sure Proteus is installed on your computer and that you have downloaded all of the necessary libraries.
- We'll need Arduino libraries and LCD modules for this project. Make sure you've read the section on using libraries in Proteus software.
- Let's begin by creating a new project, and importing all of the required components, and placing them within the working area.
- Select all of the components from the Proteus component library that we'll require.
Circuit Diagram and Working:
After importing all required components to the workplace, let’s move to connecting them.
- Starting with the connection of LEDs, we are using digital pins 2,3,4,5,6 for LEDs. Connect the positive side of the LEDs to the Arduino UNO board.
- After that, connect the Ultrasonic sensor module’s Trig pin and Echo pin to digital pin 8 and 7 respectively, Vcc to 5v volt power and GND to Ground.
- In the simulation. it will not be possible to change the distance from the Ultrasonic sensor so for that we have connected a potentiometer with the test pin of the module.
- Now start the connection of the Keypad, as this is a 3x4 keypad so it will use 3 pins for columns and 4 pins for rows.
- As there are limited digital pins on Arduino UNO, we have to use the analog pins of Arduino UNO as digital pins.
- Now let’s connect the row pins A, B, C, D with A0, A1, A2, A3 respectively and column pins 1, 2, 3 with digital pins 9, 10, 11 respectively. And we have to connect the pins in an exact manner.
- RTC module uses the I2C protocol, so we will connect SDA and SCL pins to Arduino UNO’s SDA (A4) and SCL (A5) pins respectively. Vcc with 5v power supply and Gnd with the ground.
- As there are no pins left for connecting the LCD module therefore we will use an I2C GPIO expander for connecting the LCD module.
- Connect the SDA and SCL pins of GPIO expander with the SDA and SCL pins of Arduino UNO and we have to set the slave address of GPIO expander, for that we will connect the A0, A1, A2 pins with ground, that will set the I2C slave address to 0x20.
Now we have done the circuit, it’s time to move to the coding side of this project.
Arduino code for the accident detection:
- We must add relevant libraries, which operate as header files in programming languages before we begin writing the code.
- So, if the necessary libraries aren't already installed in the Arduino IDE, we'll need to download them first.
- We can install Arduino libraries by going to 'Sketch > Include Library > Manage Library' in the Arduino IDE. In the library manager, we can now search for our essential libraries. The libraries can also be installed via zip files.
- We can download the libraries from the above instruction, but if they are not available, we can use the following links to download the zip files of libraries.
- Here we used “Wire.h” to enable I2C communication and it is pre-installed.
- “LiquidCrystal_I2C.h” is used for the LCD.
- “Keypad.h” is used for the integration of the keypad module.
- “RTClib.h” is the library for RTC modules.
- Let’s declare the pins for modules. We mainly use two pins i.e. Trig and Echo for the object detection and distance calculation. Here we have connected the Echo pin to D7 and Trig pin to D8 in Arduino Uno and an array for storing the pins for LEDs as D2, D3, D4, D5, D6. Two arrays for storing the pins for keypads such as rowPins for A0, A1, A2, A3 pins and colPins for D9, D10, D11.
- Now, Let’s declare configuration related variables for the keypad. Here we are declaring variables to store the number for Rows and Columns. We will use a 2D char array named ‘hexaKeys’ for storing the symbols of keypad.
- Now declare some general variables for storing the values for ultrasonic sensors, charge, total charged amount, check-in time and check-out time of vehicles.
- Now, Let’s declare the objects of the modules.
- The “customkeypad” is initializing an instance of class NewKeypad. The statement is going to map these symbols with the pins we have declared to connect with Arduino. Hence, it will map according to the row and column pins.
- Next, we are initializing the LCD display with an I2C serial interface and setting the address to 0x20 Hex.
- And we are declaring an object named ‘rtc’ for the “RTC_DS1307” module.
- The void setup() is an important function in the sketch that will execute only once in the whole program. The input, output, and other serial communication initializations are done inside the void setup. Let’s write the void setup sketch now.
- In this setup function, firstly we have enabled the serial communication with “Serial.begin” with the default baud rate of 9600.
- Next, we are initializing the LCD and turning on the backlight of the LCD.
- We have already declared the Trig and Echo pins before in the declaration part, and now we are going to set them up as output and input pins respectively.
- There may be a doubt why we have declared a Trig as output and Echo as input. That is because the Trig pin will generate the ultrasonic wave pulses and the Echo pin will work as a receiver for reflected waves.
- We are using five led’s for the five slots in the parking lot and to make the logic simpler, declare the led pins as output mode.
- Now, we are printing a line in the serial monitor and LCD. We are using the cursor function and printing “Made by” in the first row and “Tushar Gupta” in the second row. (0,0) is representing (column, row) in the LCD.
- After printing the line, clear the LCD screen.
- Now, we are trying to initialize the RTC module and if the RTC is not found, it will print that “Couldn’t find RTC”. and halt the further processing of code.
- After successful initialization of the RTC module we will know if the RTC module is running already , if yes then we don’t have to set the time explicitly otherwise we have to .
- We will use a “dist()” function to calculate the distance using the formula mentioned in component details.
- For the calculation of distance, we will generate the pulses using the Trig pin.
- To generate the pulses , switch the TRIGpin to LOW for 4 microseconds and then HIGH for 10 microseconds then again LOW .
- By using ‘pulseIn’ we can calculate the time duration the wave has taken to travel back from the object.
- “ distance = duration*(0.034/2); ” and here 0.034 is the speed of sound and with this formula, we can calculate the distance in cm and set the threshold values.
- “pulseIn” takes two arguments, first pin number and second logical state. This will read the pin for logic HIGH and return the time period in which that pin was at a HIGH state.
- For more knowledge of “pulseIN “ refer to this link: pulseIN function
- It is the next most important function of Arduino code/ sketch. The “void loop()” will run after the execution of “void setup()”.
- We'll write the code required to run in a continuous loop in this part. So here we'll write our main application code.
- Here, we are going to first discuss the Automatic billing part near the gate in our parking system.
- In the loop function, the Date and Time of that current time are set by “rtc.now”, and the user will enter his slot number in the keypad when he/she is exiting from the slot.
- The user will click the allocated slot number on the keypad and we are collecting that in the “customkey” variable using the “getkey” function.
- The serial monitor will print the custom key entered by the user. Then we will check the slot status by “digitalRead (led[i])”.
- If the led status is HIGH which means the slot was occupied now we will generate the bill for that slot and display that amount on the LCD display for1 second after clear the LCD and set that slot LED to LOW state.
- The next step we are going to do is to calculate the total amount according to his vehicle staying inside the parking lot. And for that, we can do the simple calculation that is “amount = charge*(gotime [i] - cometime [i]) ;”.
- We have already declared the charge amount in the above sections of the program. The charge will be multiplied by “go time - come time”, which is the total time the vehicle stayed inside the lot. And the multiplied result of stay time and charge is the final amount the driver has to pay for his parking slot.
- Now, the driver can pay the amount and exit through the gate. Here, after a second delay, we are clearing the LCD display.
- “What if the driver pressed any wrong key which has a free slot?” That might be the question in your mind. Well, we can cover that condition with an else statement, where we can print “The slot is already empty” on the LCD and let the driver know that he has entered the wrong key in the keypad near the exit gate.
- Till now, we have seen the Automatic billing logic near the exit gate. But let’s see what is the slot allocation process at the entry gate.
- As we have already calculated the distance with the ultrasonic sensor using the “dist()” function, we can set the distance limit to 100cm before the gate, and when a car reaches the entry gate the allocation of the slot will be started.
- The “for loop” here will see what are the slots showing Low/empty in the parking and allocate that empty one to the car by printing “Park your car at ” and “Slot i” in the LCD.
- As this slot was allocated, we have to write this LED as High which indicates the slot is not empty. This is the reason where the slot led is high at the exit gate when the user pressed his slot number in the keypad. We are turning on the LED when we are allocating the slot to a car.
- Now we also have to collect the “come time” by the RTC module for further calculation at the end or near the exit gate.
- We are implementing an if statement where the all LEDs are high, which means all the slots are filled, the LCD should print (“No more slots”) and inform the driver and clear the LCD screen.
Results / Working:
We have completed the Proteus simulation circuit and Arduino code for the Car Parking project. And it is ready for testing.
- Before going to start the simulation, we have to add the hex file of our application code in the Arduino UNO module in Proteus and a hex code for the ultrasonic sensor also.
- To add the hex file, click on the Arduino UNO and a new window will open then click on the Program files, there we will browse to our hex file.
- In the same way, we can add a hex file for the ultrasonic sensor.
- Now start the simulation, on the first boot of the circuit, LCD will display the welcome message and the same message will be displayed in the serial terminal also
- Just for debugging purposes, we are continuously printing the ultrasonic sensor values.
- In the simulation to change the distance between the vehicle and ultrasonic sensor we have used a potentiometer. Now change the value on the potentiometer.
As we can see that for 50% value on the pot ultrasonic sensor value is near to 500 cm and for 77% value on the pot ultrasonic sensor value is near to 850 cm.
- Let's test the condition when the vehicle approaches the sensor, to satisfy that condition the object must be at a distance of less than 100 cm. For that, we have to change the pot value. Set the pot value near to 10 %.
- After that LCD will display a message if that spot is vacant like “Park your car at Slot 1” and LED for the same location will glow.
- To take the bill for any location press the keypad for that location number let’s suppose here the location is 1 so we will click on ‘1’
- After that, it will generate the bill with the total charged amount and the LED for that location will be turned off.
- In case if we click any slot button which is already vacant then LCD will display the message for the slot is vacant.
Here it is not visible which button on the keypad has clicked but suppose we have clicked ‘1’ and if that location is vacant then it will display that message.
- Let’s take another case when we want to park another car. Now slot 1 is already busy so we will park at slot 2.
- This time when the sensor value changes less than 100 cm, then the LCD display will show “Park your car at slot 2” because slot 1 is preoccupied.
- In the image, we can see that both LEDs are glowing as both slots are occupied now.
- For billing, we will click the button on the keypad for the respective slot.
- Let’s take a case when all slots are occupied. Here we can see all slot LEDs are glowing.
- Now we will try to park another car. Then LCD will display ‘no more slot’ as there is no vacant slot available at parking.
I hope you have a good understanding of how our Car parking system project works and that you have liked it. Although it’s a tough nut to crack in the first read, I strongly recommend you to read the logic part twice for better understanding. I believe we have covered almost everything, please let us know if you have any questions or suggestions in the comments section.
Thank you very much for reading this project. All the best for your projects!