logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

How To Make Parking Assist Car Sensors

Rabindranath Andujar
Published by Rabindranath Andujar at July 19, 2016
Categories
  • Arduino
Tags
  • Arduino
  • camera
  • communication
  • drives
  • innovation
  • motor
  • open source hardware
car sensors

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

  • Arduino IDE
  • Github

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.

Define global variables
1
2
3
4
5
6
#define trigPin1 13
#define echoPin1 12
#define buzzerPin1 6
#define trigPin2 11
#define echoPin2 10
#define buzzerPin2 7

This code will run once at the beginning
1
2
3
4
5
6
7
8
9
10
11
void setup() {
  Serial.begin (9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(buzzerPin1, OUTPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(buzzerPin2, OUTPUT);
  pinMode(2, OUTPUT);         // We will use the pin 2 as ground. We need to make sure it
  digitalWrite(2,LOW);             // is in LOW position so it works as a ground.
}

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.

This will iterate as long as there is power applied to the Arduino
1
2
3
4
void loop() {
  calculateDistance(echoPin1, trigPin1,buzzerPin1);  //Get the distance for the left
  calculateDistance(echoPin2, trigPin2,buzzerPin2);  //Get the distance for the right
}

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//**********************************************************************************
//***Function to measure time of return of an ultrasound echo.************
//***Set up for distances shorter than 2 m, which is enough for parking**
//***Beyond that HC-SR04 is not reliable ***********************************
//**********************************************************************************
void calculateDistance(int echo, int trigger, int buzzer){
  long duration, distance;
  digitalWrite(trigger, LOW);              // Set the trigger pin of the HC-SR04 to LOW
  delayMicroseconds(2);                   // Wait a little to stabilize the sensor
  digitalWrite(trigger, HIGH);             // Set the trigger HIGH and send a pulse
 
  delayMicroseconds(10);                 // Wait for 10us until the wave comes back
  digitalWrite(trigger, LOW);              // Set the trigger pin of the HC-SR04 to LOW again
 
  duration = pulseIn(echo, HIGH);   // Arduino’s built in function pulseIn reads a pulse
            // (either HIGH or LOW) on a pin. Returns the length of
// the pulse in microseconds or 0 if no complete pulse
// was received within the timeout.
 
  distance = (duration/2) / 29.1;       // The speed of sound is 340 m/s or 29 microseconds
// per centimeter.
// The ping travels out and back, so to find the distance
// if the object we take half of the distance travelled.
 
  if (distance >= 200 || distance <= 0){
Serial.println("Out of range");     // Use some feedback in the serial port for
        // debugging
  }
  else {
tone(buzzer,2000,25);         // Arduino’s built in function tone generates a square
           // wave of the specified frequency (2000Hz) for the
           // indication time (25 ms)
delay(distance*10); // The delay gives feedback beeping faster the closer
// we get to an object
Serial.print(distance); // Use some feedback in the serial port for
// debugging
Serial.println(" cm");
  }
}

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!




Rabindranath Andujar
Rabindranath Andujar
Rab holds PhD in Computational Physics and has been a dedicated researcher in the areas involving computing, automation and complex systems. Rab also has experience in electronics, robotics and digital manufacturing.

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • Driver Assist Car Predicts Your MovesDriver Assist Car Predicts Your Moves
  • An Intro to: CMUcam5 Pixy Vision Camera SensorAn Intro to: CMUcam5 Pixy Vision Camera Sensor
  • Intro to CMUcam5 Pixy Vision Camera Sensor Part 2 – Creating a Ball Balance BeamIntro to CMUcam5 Pixy Vision Camera Sensor Part 2 – Creating a Ball Balance Beam
  • Motor Current When Applying a Torque LoadMotor Current When Applying a Torque Load
  • Arduino Bluetooth Gloves Part 1 – BasicsArduino Bluetooth Gloves Part 1 – Basics
  • Guide to Connecting Arduino & Raspberry Pi + DIY Arduino and Raspberry Pi Camera Robot!Guide to Connecting Arduino & Raspberry Pi + DIY Arduino and Raspberry Pi Camera Robot!
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort