In modern cars, parking sensors are becoming part of the equipment, because it’s really convenient. In the more expensive models, there is also a video camera, which displays an image during a backward stroke, on which the proximity indicator superimposes.
I decided to make the simplest implementation of parking sensors with sound and light indication.
- Arduino (Uno, Mega, Nano, …)
- HC-SR04 (ultrasonic sensor)
- 3x LED’s (red, yellow, green)
- 3x 220Ohm resistors
The task is to measure the distance between the object and the sensor and, if the range is less than 20 cm, turn on the red LED and sound on the buzzer. If the distance is more than 100 cm turn on the green LED, if from 20 cm to 100 – yellow.
I got this connection scheme:
More details about what pins of the board I connected to:
- TrigPin – 12;
- EchoPin – 13;
- VCC – 5V;
- GND – GND;
LEDs and buzzer:
- Green LED (led) – 2;
- Yellow LED (led2) – 3;
- Red LED (led3) – 4;
- Buzzer (piezo dynamic) – 11;
Above shows the assembled physical scheme. You need only to download the sketch and the parking sensor is ready. We transfer the distance sensor to echolocation mode with a short pulse, at which ultrasonic waves are sent to the surrounding space. We determine the pulse duration using the function pulseln, which shows us the time elapsed before the signal level changes. After receiving the time we translate it into the distance in centimeters by dividing by a constant (for sensor SR04 it is 29.1). Since the time passed by ultrasonic waves to the target is the distance there and back, everything must be divided by 2. Do not forget about the delay between measurements for a particular job.
It turned out not the most compact, and probably not everyone wants to hang such a box on their cars. So here I leave for you open space for creativity.
In unmanned vehicles, in fact, ultrasonic sensors along the sides are also used as part of the short-range navigation system. At long distances, lidars usually work. The onboard computer of the car adds data from all sensors to create a picture of the current location and to create a safe route.
Use these devices in real life with extreme caution. Ideally, such homemade parking sensors are best tested along with a commercial counterpart, to eliminate the possibility of false positives, and the lack of response when approaching objects of different forms.