Car Collision Prevention System Using an Arduino and Ultrasonic Sensor

by Kadhir U in Circuits > Arduino

402 Views, 1 Favorites, 0 Comments

Car Collision Prevention System Using an Arduino and Ultrasonic Sensor

20231022_162044.jpg

In 2021, frontal impacts accounted for 18 driver deaths per million registered passenger vehicles in the US [1]. However, an onboard digital warning system could have easily prevented many of these collisions. Such a system can give a driver precious seconds to take action and avoid a crash. This is why most new vehicles have a built-in collision prevention system that uses radar to sound an alarm if it gets too close to whatever is in front of them [2]. These systems have been proven to reduce crashes and injuries from forward collisions by about 40% [3]. Unfortunately, older vehicles do not have this warning mechanism built in. To fix this problem, we propose an affordable collision prevention system with an Arduino Uno, an ultrasonic sensor, and a piezo buzzer that works similarly to a newer car.

Supplies

The ultrasonic sensor we used for this project is the LV-EZ0 Maxbotix Ultrasonic Rangefinder [LV-MaxSonar-EZ Datasheet – MaxBotix]. This sensor is compact and can detect objects up to about 21 feet away, which makes it great for the application of sensing objects on the road in this application.

For the rest of our supplies, we used the Arduino Uno R3 starter kit [Arduino Starter Kit Multi-language]. This kit has the Arduino Uno, breadboard, wires, resistors, piezo buzzer, and LEDs. The piezo buzzer will sound a high-frequency alarm, and the LEDs will be programmed to display your following distance in feet as a digital display.

The total cost of this system is roughly $140.25. In contrast, the same system that comes as a standard or optional feature in newer cars usually costs around $2000 [4]. In addition, the Arduino starter kit comes with many other useful gadgets, such as an LCD screen, allowing for further customization of this device.

Key Concepts

The "following distance" is the distance between your vehicle and the vehicle in front of you. The rule of thumb for safety is to use the four-second rule, which states that whenever the car in front of you passes a fixed object, four seconds should elapse before passing that same object in your vehicle [5]. Typically, when you follow the four-second rule, you should be about 14 feet away from the car in front of you, so the distance at which the alarm goes off should be 7 feet, as that will give the driver enough time and distance to take action.

A piezo buzzer operates using the piezoelectric effect, which is a phenomenon that occurs in certain non-conducting materials, such as quartz crystals and ceramics [6]. When these materials are subjected to an electric field, vibrations are generated that produce a sound. An ultrasonic sensor emits ultrasonic waves, which are sound waves whose frequency is above 20 kilohertz [7], the upper limit of human hearing. These waves have many applications, including proximity detection.

The ultrasonic sensor can communicate with the Arduino in three ways: Pulse Width Modulation (PWM), Analog Voltage Output, or Serial Digital Output [8]. For this project, we will use analog voltage with the ultrasonic sensor since it is the simplest way to communicate with the Arduino using code. Analog voltage output is a continuous output from the sensor that varies in voltage. This means that the voltage output can be any value between the minimum and maximum values of the output range. The sensor's output voltage is related to distance (in inches) by the following equation: distance = Vcc / 512 [8].

Building the Device

First, connect one wire from 5V on the Arduino to "+" on the breadboard and another from GND on the Arduino to "–" on the breadboard. Then, for the piezo buzzer, connect one leg to "-" on the breadboard and the other to a digital pin on the Arduino. For the ultrasonic sensor, connect "AN" on the sensor to an analog pin on the Arduino, "+" on the breadboard to "+5" on the sensor, and "-" on the breadboard to "GND" on the sensor. Last, for the LEDs, connect the cathode (short leg) to "-" on the breadboard using a 220-ohm resistor and connect the anode (long leg) to a digital pin on the Arduino. We used an array of 9 LEDs, which can serve as a digital display indicating the distance to the vehicle in front of you. Once assembled, the Arduino can be programmed using the code in this Git Repository: https://github.com/UKadhir/car-collision-prevention-system].


Here is an image of the completed system.

 

Below are the schematics of the Arduino Uno with the LEDs, piezo buzzer, and ultrasonic sensor.








Device Calibration and Testing

Detailed Beam Pattern.png
Minimum Detectable Object Area Test.png
Aperture Test.png

First, we must calibrate our sensor for optimal performance at the desired range. Our sensor's minimum detectable object area is measured using cardboard squares of various sizes. Our setup for this experiment involved putting the device on a chair where the wall across from the device was about 15-20 feet away, and there wasn't anything near the chair for 2-3 feet. Then, using a thin stick that the sensor wouldn't detect, we slowly moved the cardboard squares taped to the stick toward the sensor to see if the alarm activated at the target distance of 7 feet. The minimum detectable object area was 4 square inches (2 by 2 inches). The significance of this is that the sensor should be able to detect a vehicle approaching from most possible angles. Please see the image above labeled "Image 1" for a detailed diagram of this experiment.


Then, we tested the size of the aperture (width) of the ultrasonic sensor's beam. We used the 2 in by 2 in cardboard square to test the aperture of the ultrasonic sensor. While standing 7 feet from the sensor, the square was moved horizontally to the sensor to achieve different angles of attack up to 45 degrees to test how wide/tall the beam pattern is. The angle of attack is the angle from the vertical (left or right) at which an object can approach the sensor and still be detected. The sensor could detect the cardboard square when the angle of attack was 15 degrees or less, which is substantial enough to detect cars traveling in adjacent lanes. This was calculated using the inverse tangent of the horizontal over the vertical (both in feet), which in this case was approximately arctan(2/7). Please see the image above labeled "Image 2" for a detailed diagram of this experiment. The video below demonstrates the minimum detectable object area and aperture tests. Finally, the sensor was tested with different objects, including a person, a bicycle, and a car. The sensor detected all these with about 90% accuracy, and the maximum detectable distances are listed below.


Car: 21 feet

Person: 10 feet

Bike forward (a person can be on the bike): 14 feet

Bike sideways (a person can be on the bike): 18 feet


Also, this sensor has difficulty detecting objects closer than 100 centimeters [8]. Please see the image above labeled "Beam Pattern" for this ultrasonic sensor's complete and detailed beam pattern.


Notably, this ultrasonic sensor has a finite sampling rate of 42kHz [8]. This implies the sensor can only react to objects moving up to a maximum speed. In other words, if an object moves through the sensor beam pattern before the sensor can take a sample, then the sensor will be unable to register the object. Dividing the sensor's maximum range by the sample rate, we can determine the maximum speed at which an object may travel towards the sensor straight on and get detected by the sensor. This number can be calculated using the following steps:


1 period of 42kHz = 1/(42,000 Hz) = 23.8 uSec

The maximum vertical range of the sensor is 21 feet

The maximum vertical speed at which something can travel and still have the sensor detect it is (21 feet) / (23.8 uSec) = 601364 MPH.

Therefore, this device will have no problem detecting any vehicle traveling on the road in front of it.


Similar calculations can be made for the maximum speed at which an object may be traveling toward the sensor from the side that the sensor can detect.

1 period of 42kHz = 1/(42,000 Hz) = 23.8 uSec

The maximum horizontal range of the sensor (left to right) is 11 feet

The maximum horizontal speed at which something can travel and still have the sensor detect it is (11 feet) / (23.8 uSec) = 315126 MPH.

Building a Device Enclosure

20240304_164923.jpg

Now that it is established that this device is effective at sensing objects at a target distance despite high speeds, we can start to think about how we will use it in real life with a car. This requires us to consider how to power and protect the device from damage. We can use a 9V battery or the 12V power jack inside a vehicle to power this device. However, the 12V power jack is the better option as a car's battery has a much higher capacity than a 9V battery. To keep the device safe and secure inside the vehicle, we can design an enclosure using CAD and laser cut it with openings for the LEDs, piezo buzzer, USB port, and ultrasonic sensor (see picture above). Also, the distance range for each LED is engraved on the enclosure next to each LED cutout. This enclosure is a rectangular prism; all six sides are laser cut and connected using box joints. The dxf file for the enclosure is attached below (I engraved the text on top of the enclosure separately). Further, the video below demonstrates the device in action with this enclosure.

Conclusion

To install this system in a vehicle, the enclosure with the device inside should be glued to the dashboard. Next, extra-long jumper wires should be used so the ultrasonic sensor can stretch out to the nose of the car, where it can be glued. Then, power up the device by plugging the USB cable into the vehicle's 12V jack. Lastly, test the device and ensure that it is working correctly. Once working, this system is complete and ready to save lives by preventing collisions.


References:

[1] Passenger vehicle occupants (iihs.org)

[2] ADAS Radar Sensor Guide: Automotive Radar and How it Works (caradas.com)

[3] Advanced Driver Assistance Systems-Data Details - Injury Facts (nsc.org)

[4] ADAS Statistics: BSW, LDW, ACC & LKA... (caradas.com)

[5] How To Keep A Safe Following Distance When Driving | Drive-Safely.net

[6] Piezo Buzzers | How it works, Application & Advantages (electricity-magnetism.org)

[7] How an ultrasonic sensor works | Sensor Partners

[8] LV-MaxSonar-EZ Datasheet – MaxBotix