Low-cost Car Parking Sensor
This is a tutorial on how to make and install a low-cost parking sensor in the front of your car
![](https://www.geediy.net/wp-content/uploads/2024/07/36aa60c4-533b-4669-b39b-5e12722bd3cc.gif)
Components and supplies
![](https://www.geediy.net/wp-content/uploads/2024/07/image-49.png)
![](https://www.geediy.net/wp-content/uploads/2024/07/image-50.png)
![](https://www.geediy.net/wp-content/uploads/2024/07/image-51.png)
Project description
Example of use
Description
Many parking assistant tools are either too pricey or only come with new car models. In addition, many find it difficult to judge the distance from the front of the car to the curb when parking. This project is the perfect solution, as it is a low-cost Arduino car sensor system that will assist in parking. An ultrasonic sensor is placed underneath the center of the front bumper of the car. The ultrasonic sensor is connected to an RGB LED, a switch, and a buzzer. The LED, switch, and buzzer are all inside the car. The LED and buzzer will alert the driver when they are too close to a parking curb. For example, when parking in a parking spot, it will detect the curb and alert the driver when to stop the car. Because the ultrasonic sensor on the car is susceptible to damage, it will be covered by a 3D-printed case. This case will have a lid, which will open up and down when the switch is flipped.
Manual
Sliding the switch should open and close the cage. If the object is farther than 40 inches, then the LED will light blue. If it is between 30 and 40 inches, it will light green. In between 20 and 30 will light yellow. If the object is closer than 20 inches, the LED will light red and the buzzer alarm will sound. This is the alert for the driver to stop the car. Please note that the ultrasonic sensor (HC-SR04) works best between 2cm-400cm within a 30 degree cone and is accurate to the nearest 0.3cm. It may not always give correct readings, so ensure that you check your surroundings and use caution while using this device.
Instructions
Step 1: Assembling materials
a. Assemble all materials in the “Component and supplies” and “Tools and machines” sections above.
b. 3D print all files listed below in the “Downloadable Files” section. The 3D-printing takes some time, so be sure to do this first.
Step 2: Put together the hinge
a. Follow figures 1 and 2 below. They contain the names of each piece and what the final product should look like.
b. First, hot glue the flaps with the big base. Then hot glue the horns with the small base.
c. After gluing the bases, place the legs of the horns in between the flaps and put a paper clip through the holes.
d. Then take the rod and put it in between the top two holes of the horns. Fit another paper clip through them to attach it.
e. After putting the paper clips in, use your pliers to bend them around and cut off any excess paper clip. The final product should look similar to figure 2 below.
Figure 1: Hinge Schematic
Figure 2: Hinge with labels
Step 3: Assembling the cage
a. First, take your servo motor and wrap it with masking tape. This will protect it from getting damaged by hot glue.
b. Next, cover the box with the lid and tape it in place. Be sure that the lid is completely covering the box. This will ensure that it is waterproof.
c. After the lid is in place, align the hinge. The end of the hinge with the rod should be on top of the cage’s platform, while the other end should be on the lid. Make sure that the hinge is fully in contact with the cage and the lid and that it is near the edges of the platform. This will save room for the servo motor. Once the hinge is in place, hot glue the bases onto the platform and the lid as shown in figure 3.
d. Now take your servo motor and attach it to the rod of the hinge. Most servo motor arms have holes in them, so put a paper clip through that hole and the hole on the rod. Then bend the paper clip around and cut off any excess paper clip.
e. Now that the servo and hinge are connected, place the servo motor on top of the platform of the cage and align it so that the hinge opens and closes the lid as the servo motor spins. Once you find the correct location of the servo motor, hot glue it in place. At this stage, the sensor should look like figure 3.
Figure 3: Cage Schematic
Step 4: Place the box over the servo motor
a. Take the 3D-printed servo motor box and place it over the servo motor. As labeled in figure 4, the wire hole should line up with the wires, and the servo arm hole should line up with the servo motor’s arm.
b. Fish the servo’s wire through the wire hole
c. Then, firmly press the box down and hot glue it to the cage platform. It should like like figure 5.
Figure 4: Servo Motor Box Schematc
Figure 5: Servo Motor Box with Labels
Step 5: Adding Velcro
a. Cut two pieces of Velcro with length 43 mm and width 18 mm. These pieces should be the same size as the back of the ultrasonic sensor.
b. Place one Velcro piece on the back of the ultrasonic sensor, making sure to avoid the pins on the back. Place the other Velcro piece on the top of the inside of the cage.
c. You can now attach the ultrasonic sensor to the cage as shown figure 6.
Figure 6: Velcro Diagram
Step 6: Adding weather strips
a. Take the silicone weather strips and cut two pieces off that have a length of 47 mm. If the silicone weather strip purchased contains a non-adhesive section, cut that section off. This should leave you with two pieces of weather strips that have adhesive on one side.
b. Place the strips on the sides of the cage and leave about a 5 mm overhang as seen in figure 7. This will keep it water tight.
Figure 7: Weather Strips Diagram
Step 7: Determine the location of the cage
a. This step will require some creativity. Each vehicle is different, so each application of this prototype will be slightly different as well.
b. For my car (Lexus ES 350), I was able to attach the cage to the bottom of the front bumper with a hub bolt that has a diameter of 6.5 millimeters (as shown in figure 8). I found the bolt on the bottom of the car and unscrewed it. I then put the bolt through the cage and screwed it back on as depicted in the image below. To determine the location of the sensor on your car, look underneath the front bumper for screws, bolts, or other means of attachment. The closer to the center of the vehicle, the better.
Figure 8: Bolt Diagram
Step 8: Configure the wiring
a. Once you have identified the ideal location for the sensor on the car, a path for the wiring from the sensor to the inside of the car needs to be identified. The breadboard (the component that contains the speaker, LED, and switch) and Arduino will be placed on the passenger side dashboard, so find a way to fit the wires there.
b. For my car, I first fit the wires through the bottom grille of the car. I then brought it up to the front trunk and fished it along the side of the front trunk. I then fit the wires through the passenger-side door (the door can still be opened and closed, but it may cause the wires to become loose). When figuring out the wiring, use a tape measure to determine the wire length that you will need. You will need to refer back to your wire length at a later step. Below is a schematic of the wiring and pictures of the wires in place.
![](https://www.geediy.net/wp-content/uploads/2024/07/image-52.png)
![](https://www.geediy.net/wp-content/uploads/2024/07/image-53.png)
![](https://www.geediy.net/wp-content/uploads/2024/07/image-54.png)
![](https://www.geediy.net/wp-content/uploads/2024/07/image-55.png)
![](https://www.geediy.net/wp-content/uploads/2024/07/image-56.png)
![](https://www.geediy.net/wp-content/uploads/2024/07/image-57.png)
Step 9: Make all of the wire connections on the breadboard and Arduino
a. Following figure 9, make all necessary connections on the breadboard and Arduino. Don’t wire the ultrasonic sensor or servo motor yet. That will come in the next step.
Some things to note for following the schematic:
For the RBG LED, make sure that the flat side of the LED is on the bottom. For the piezo speaker, make sure that you have the negative and positive sides properly aligned. The speaker is polarized so the position of each pin matters. The negative pin should be on the bottom.
Figure 9: Arduino Schematic (Ignore the colors)
Step 10: Connect the wires for the ultrasonic and servo motor
a. Take your four female to female wires and plug them into each of the ultrasonic sensor’s pins.
b. Then, following the wire length you obtained from Step 8, use your wire strippers to cut 7 of your copper wires to that length and strip both ends of each wire (about 1 inch). Then use the stripped copper wires to connect the ultrasonic sensor and servo motor according to figure 9.
c. After connecting all the wires, plug your computer into the Arduino and run the code listed below. To run the code, copy and paste the code from the “code” section into the Arduino IDE and run the program.
d. Following the manual at the top of the page, test each component to verify that they work.
Step 11 (Optional): Soldering
This step is optional. If desired, solder all the breadboard connections to make the connections more secure. Ensure that you first test the circuit to double check that it works before beginning the soldering. When soldering, make sure to wear eye protection and that your location is well ventilated.
Step 12: Installing
a. The last step is to install everything! After attaching the cage to the front of the car (location from step 7), fish the wires through the car as determined from step 8.
b. Test the sensor to make sure everything is working. This can be done by driving towards a parking curb in an empty parking lot (similar to the video at the top of the page). You can then measure the distance from the curb and compare it to the LED light changes made by the sensor. If everything works as expected, then you have successfully completed this project!
Key Considerations and Possible Improvements
Throughout this tutorial, hot glue was used to fit the 3D-printed parts together. However, hot glue is not weatherproof and the lifetime of the hot glue is uncertain. A possible improvement to this prototype would be utilizing a more permanent and weather-proof alternative to hot glue.
Code
#include <Servo.h>
Servo myservo;
const int trigPin = 11; //connects to the trigger pin on the distance sensor
const int echoPin = 12; //connects to the echo pin on the distance sensor
const int redPin = 3; //pin to control the red LED inside the RGB LED
const int greenPin = 5; //pin to control the green LED inside the RGB LED
const int bluePin = 6; //pin to control the blue LED inside the RGB LED
const int buzzerPin = 8; //pin that will drive the buzzer
float distance = 0; //stores the distance measured by the distance sensor
const int switchPin = 7; // switch to turn sensor on and off
void setup() {
pinMode(switchPin, INPUT_PULLUP);
Serial.begin (9600); //set up a serial connection with the computer
pinMode(trigPin, OUTPUT); //the trigger pin will output pulses of electricity
pinMode(echoPin, INPUT); //the echo pin will measure the duration of pulses coming back from the distance sensor
//set the RGB LED pins to output
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buzzerPin, OUTPUT); //set the buzzer pin to output
myservo.attach(9);
}
void loop() {
if (digitalRead(7) == LOW) {
myservo.write(0);
delay(400);
distance = getDistance(); //variable to store the distance measured by the sensor
Serial.print(distance); //print the distance that was measured
Serial.println(" in"); //print units after the distance
if (distance <= 20) { //if the object is close
//make the RGB LED red
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
tone(buzzerPin, 272); //buzz the buzzer pin
delay(100); //wait 100 milliseconds
noTone(buzzerPin); //turn the buzzer off
delay(100); //wait 100 milliseconds
} else if (20 < distance && distance < 30) { //if the object is a medium distance
//make the RGB LED yellow
analogWrite(redPin, 255);
analogWrite(greenPin, 50);
analogWrite(bluePin, 0);
} else if (30 < distance && distance < 40) { //if the object is far away
//make the RGB LED green
analogWrite(redPin, 9);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
} else {
//make the RGB LED blue
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
}
delay(50); //delay 50ms between each reading
} else {
myservo.write(128);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
}
}
//------------------FUNCTIONS-------------------------------
//RETURNS THE DISTANCE MEASURED BY THE HC-SR04 DISTANCE SENSOR
float getDistance()
{
float echoTime; //variable to store the time it takes for a ping to bounce off an object
float calculatedDistance; //variable to store the distance calculated from the echo time
//send out an ultrasonic pulse that's 10ms long
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
echoTime = pulseIn(echoPin, HIGH); //use the pulsein command to see how long it takes for the
//pulse to bounce back to the sensor
calculatedDistance = echoTime / 148.0; //calculate the distance of the object that reflected the pulse (half the bounce time multiplied by the speed of sound)
return calculatedDistance; //send back the distance that was calculated
}
Downloadable files
https://projects.arduinocontent.cc/2b52dacb-3ae7-4836-9c52-2af6e08ad688.stl
https://projects.arduinocontent.cc/da5314fa-bd44-45af-9e48-ba687b95ce9d.stl