car sensors

In this tutorial, we will illustrate the installation and the use of simple, low-cost parking assist car sensors. We will use two HC-SR04 ultrasonic sensors and four Piezo buzzers to progressively alert the driver about the proximity of nearby cars behind the driver’s car while parking with an acoustic beeping sound. We will also solve practical problems like waterproofing and deploying of wires within a car’s cabin.





Get IoT Essential Guide &  Enter to Win a Free Sensor Kit!




Hardware

  • Arduino UNO (1x)
  • HC-SR04 Ultrasonic sensors (2x)
  • Vcc wire (2m aprox)
  • Gnd wire (2m aprox)
  • Trigger wire (1m aprox)
  • Echo wire (1m aprox)
  • Piezo buzzer (2x)
  • USB car adapter
  • Plastic case/box for Aduino

Software

Tools

  • Pliers

Step 1: Setting up the system

Let’s start by preparing the electronics shown below so we can test the system before actually installing car sensors in the car.

car sensors

Figure 1: Required hardware components – Arduino, plastic case, ultrasonic sensors, Piezo buzzers, wires, and a power adapter

In this project, we will only be using two sensors for the rear: one on the left side of the bumper, and the other on the right side of the bumper. Assistive alert systems in most new cars have up to six sensors for more precise positioning.

HC-SR04 sensors show four pins each:

  • VCC (power supply up to 5V)
  • Trigger
  • Echo
  • Ground

For a more detailed explanation of the functions of these modules please visit this previous tutorial: Using Arduino with Parts and Sensors – Ultrasonic Sensor

Figure 2 below shows a diagram on how to wire the car sensors and buzzers to the Arduino.

ultrasonic car sensors

Figure 2: Wire diagram of the Arduino, ultrasonic sensors, and Piezo buzzers

Step 2: Programming the Arduino

Let’s start writing a program. In general, for any microcontroller firmware we can find the following four elements:

  • Definition of global values and libraries
  • Set-up function
  • Loop function
  • Other functions

Unlike in software development, when programming microcontrollers we normally have some limitations as to how large our code can be. My Arduino Uno comes with an Atmega328, which has 32 KB memory. For this particular application this is more than enough.

The functions pinMode() and digitalWrite() are convenient ways of dealing with the microcontroller’s pins. We will use the pinMode() function to set the direction of the specified pin(s). The direction can be either input or output. Once you set the direction, the pin will only work in that direction. We will use digitalWrite() function to set the specified digital pin to HIGH or LOW. Here, I set pin 2 as another extra ground, which I needed in order to connect the GND pin of one of the devices.

For the sake of simplicity, I have defined a function (calculateDistance (echo, trigger, buzzer) that will be used in one of the sensors first, and in the other sensor second.

We first activate a pin (trigger) because it will take a while to send us back information about another pin (echo). With this time interval we can make some assumptions and calculate a distance (the speed of sound is 340 m/s or 29 microseconds per centimeter). This distance will serve as a parameter to establish how often to emit a beep of 2000 Hz (I found this by trial and error, feel free to change it to your preferred pitch).

I used several built-in functions, such as tone (pin, frequency, duration), digitalWrite (pin), delayMicroseconds(duration), and pulseIn(pin, value).

Step 3: Preparing a good strategy for assembly

Find a waterproof area in the rear body of your car. Sensors will be installed here. In my car I had several options:

  • Inside the tail light covers
  • Near the license plate bulbs
  • On the rear bumpers

If you were to place the car sensors either inside the tail light covers or on the rear bumpers, you must drill holes to allow ultrasound waves to come in and out. Unfortunately, these holes would also allow water to come in (rain, splashes, etc.) unless they were very well made. Waterproofing them with sealant is not an option because the ultrasound waves will not make it out. In addition, you will have the added difficulty of calibrating the position of the holes with respect to the sensor in order to avoid diffraction effects.

car sensors

Figure 3: The problem of diffraction when housing ultrasound sensors. / ©bta304

To learn more about diffraction waves, please click here.

So, I chose to place the car sensors near the license plate because the gap underneath the trunk door/handle is large enough, and it spares me the trouble of drilling holes. All I need to do is slightly adjust the orientation of the sensors to aim towards the corners of the car.

location for car sensors

Figure 4: Finding the right location for the sensors

Step 4: Deploying the hardware inside the car

Find a place for the Arduino and the Piezo buzzers. For this step we will need to un-mount the car door panels and find a safe, empty place to attach the electronics.

Let the fun begin! The inside panels reveal a whole new dimension of your car. What we have there is a lot of space where we can attach many devices (maybe for future posts!). There are also a number of internal wires that supply power to different elements of the car related to safety. Make sure you don’t touch any important wires.

YOU MUST BE VERY CAREFUL WITH THE INTERNAL PARTS OF THE CAR.

We will connect the ultrasonic sensors from the outside of the car to the Arduino through the holes that hold the license plate. I had to make those holes a little bit larger to have all eight wires pass through and still leave room for the supporting screws.

The Piezo buzzers were arranged with simple two-sided adhesive tape.

Assembly of car sensors

Figure 5: Assembly of the HC-SR04 on the right side of the license plate

Assembly of buzzers for car sensors

Figure 6: Assembly of one of the Piezo buzzers with two-sided tape

Locations of car sensors

Figure 7: Locations of the modules on trunk door (inside view)

Locations of car sensors

Figure 8: Locations of the modules (rear view)

Altogether, we will need about 6 meters of wire for the sensors and the buzzers in order for the system to operate comfortably. It is important to color code the wires to prevent confusion in the future.

Step 5: Deploying the wires inside the car

Once the hardware is in place we need to connect all the wires. The sensors need eight cables (two echoes, two triggers, two grounds and two VCCs) that need to go through the holes behind the license plate. Let’s verify the connections:

  • Right sensor trigger / Arduino pin 13
  • Right sensor echo / Arduino pin 12
  • Right sensor GND / Arduino GND
  • Right sensor VCC / Arduino VCC
  • Right buzzer + / Arduino pin 6
  • Left sensor trigger / Arduino pin 11
  • Left sensor echo / Arduino pin 10
  • Left sensor GND / Arduino GND
  • Left sensor VCC / Arduino Vin
  • Left buzzer + / Arduino pin 7

The order of the VCCs and the GNDs is irrelevant as long as they are all connected. My Arduino Uno exposes up to three grounds and I am using Vin pin as a power supply for one of the sensors, supplying the other sensor from the 5V pin.

Other Arduino versions are more or less limited in pins (i.e. Arduino Micro only exposes two grounds), so I decided to make an extra ground by setting the pin 2 to LOW.

Connecting car sensors

Figure 9: Connecting the ultrasound modules and the power

Connecting car sensors

Figure 10: Connecting the modules, the power and the buzzers

Step 6: Powering up the system

The power supply in automobiles is tricky. Although the car battery provides 12 DC Volts (the voltage regulator may overheat and damage the Arduino board if you are using more than 12V), it is connected to an alternator. When starting up the engine the alternator can create huge current peaks and fry any electronic device connected to it. It is called load dump. You can read more about it here.

For this reason, it is best to use an intermediate protective circuit between your Arduino and the car’s power supply. One option is the DIY assembly of a voltage regulator, but its design surpasses the scope of this article, so I opted to recycle an old phone adapter.

I used a USB female adapter cable. I had to replace the end of the USB adapter and attach it to the female adapter. Alternatively, I could have removed the Arduino’s female pin headers and attached all wires.

The question here is: Which one of the four wires goes where? Please see the image below.

supplying power to car sensors

Figure 11: USB type B. When supplying power through the USB only two wires are needed.

In my Arduino Uno the USB connection is type B. Other models have other types of USB connections, so you will have to check yours and adjust to your needs.

Finally, we need to find a power source for our adapter. There are several options:

  • Cigarette lighter receptacle (located a little too far away)
  • Reversing indicator lamp (very convenient but a bit complicated given the operation of my door)
  • Rear windshield wiper (less elegant than the reverse indicator, but also convenient in case I want to disable it)

I was lucky enough to find a connector in between all the wires that ran behind the plastic panel. I checked the voltage and …Voila!

Finding the power for car sensors

Figure 12: Finding the power and polarity in a stray connector within my car

In this tutorial, we developed a fairly simple, cost-effective Arduino-based assistive parking system with car sensors that alert a driver when they get too close to the cars behind them (rear side). Using two ultrasonic proximity sensors and two Piezo buzzers, the system warns the driver with acoustic sounds, with the frequency between the sounds indicating the distance from an obstacle.

We created a real-life application using Arduino and explored the boundaries between the proof-of-concept prototype, the user experience prototype and the functional prototype. In a future tutorial, we may expand on the concepts we discussed here today to build an improved version of the assistive parking system with better features and functionalities. What do you think?


If you have any comments or questions, please leave them for us at Google +. Follow us there; we will be posting the next tutorial soon.





Get IoT Essential Guide &  Enter to Win a Free Sensor Kit!