Parking sensor with Arduino and the HC-SR04

Parking sensor

Almost all cars currently produced have a parking sensor or already integrated parking sensor. These types of sensors range from simple proximity sensors that warn you when you are going to hit an object and warn you with a sound signal or other somewhat more complex systems that incorporate a camera and show you the image and some lines of the limits in the on-board display.

Be that as it may, these types of devices it is very practical to park properly and not to do it "by ear" like some… This will avoid visits to the bodyworker due to damage caused by hitting a bollard or another parked car. But unfortunately, not all cars have one, and most older cars don't. But that doesn't mean that you can't implement one in your car. Here we are going to show you how to do it.

Buy the parking sensor

parking sensor

There are already parking sensors created on the market for those who are less handy for these things. So if you are not a maker and you do not like DIY, you can opt for this type of products that are not excessively priced. Some can be used as a replacement for the parking sensor if the one in your car has broken or to put it in a car that did not have it as standard.

No products found.and it can range from € 20 to € 30. All usually have several sensors to place on the bumper at the back of your car and lead the wiring to the interior of the cabin to put the device that emits the sound inside. Others also include a small display that shows the distance to hit the object behind.

Also exist some that are somewhat more advanced, and instead of sensors they have cameras. As for the interface to be installed in these cases inside, it is a screen that will show the image that you can see to park the car in a simpler way. In these cases, the price is around € 50.

Create your own parking sensor

Now if you want to create it yourself, you can use this project using an arduino board, a simple code for its programming, and ultrasound sensors to measure distances such as the HC-SR04. If you prefer, you can vary this distance sensor for others that we have described in HwLibre to add greater precision, although this would be enough.

How does a parking sensor work?

First of all, you should have a good understanding of how the parking sensor of a car works. It is a very basic device. The principle on which it is based is that of Measure distances with the help of an ultrasonic or optical sensor. When it is at a certain distance from hitting an object, it will emit a signal, usually sound by means of a buzzer or similar. That way, the driver will know when to stop to avoid crashing.

So this is what you should reproduce with Arduino, use one or more distance sensors, and when they detect a certain distance, the microcontroller activates a buzzer or visual signal system that warns. Adding more than one distance sensor will allow you to have greater precision from different angles, since with a single sensor you will not be able to warn of objects that are not within the range of the sensor.

More information - VL53L0X laser sensor / HC-SR04 Ultrasonic Sensor

Required components

To create your own parking sensor you will need to:

  • License plate Arduino, it can be several of the models that you have at your disposal and even compatible plates.
  • Ultrasound sensors HC-SR04, although you can use a similar one.
  • LEDs or buzzer, as you want to base on sound or visual signal. In this case, both visual and sound signals are used with the buzzer. Remember that if you buy a simple buzzer, you will need some extra elements as we detail in the article that we dedicate to the buzzer, but if you acquire it in the form of a module it will integrate everything you need ...
  • No products found. Dupont for connection.
  • 3 resistances de 220 ohms optional
  • Protoboard o PCB if you want to solder it to make it permanent.

How to do it step by step

Circuit with Arduino

Once you have everything you need, the following is connect components properly. To do this, you can follow the simple scheme of this circuit that I show you here. The connection is very simple. Once everything is connected, it would only be necessary to program the microcontroller from the Arduino IDE.

In this case, we use three different colored LEDs. For example, it can be one green, one yellow, and one red, although you can use other colors. Green will indicate that you can continue reversing without problems. Yellow indicates that you must be careful because it is approaching the object, and red when you have to stop the march to avoid colliding. The distance marked as viable, precautionary and stopping must be properly calibrated ...

El Arduino IDE sketch that would have to be programmed for the circuit to work, it would be:

#define pulso 9  //pin para el pulso en el #9
#define rebote 8 //pin donde recibe rebote en el #8
#define led_verde 13  //LED verde
#define led_amarillo 12  //LED amarillo
#define led_rojo 11  //LED rojo
#define SIN_PROBLEMA 100 //Distancia razonable de 1m
#define PRECAUCION 20  //Distancia peligrosa 20 cm
int distancia;  //Variable distancia
float tiempo;  //Variable de tiempo
void setup()
//Declaraciones para las salidas o entradas de cada pin
  pinMode(pulso, OUTPUT); 
  pinMode(rebote, INPUT);
  pinMode(led_verde, OUTPUT); 
  pinMode(led_amarillo, OUTPUT); 
  pinMode(led_rojo, OUTPUT); 
void loop()
  digitalWrite(pulso,LOW); //Estabilizar el sensor antes de comenzar
  digitalWrite(pulso, HIGH); //Enviar pulso ultrasonido
  tiempo = pulseIn(rebote, HIGH);  //Mide el tiempo
  distancia = 0.01715*tiempo; //Calcula la distancia a la que estás del objeto
  if(distancia > SIN_PROBLEMA)  //Evalúa la distancia
    digitalWrite(led_verde, HIGH);
    digitalWrite(led_amarillo, LOW);
    digitalWrite(led_rojo, LOW);
  else if (distancia <= SIN_PROBLEMA && distancia > PRECAUCION) //Distancia de precaución
    digitalWrite(led_verde, LOW);
    digitalWrite(led_amarillo, HIGH);
    digitalWrite(led_rojo, LOW);
  else  //si la distancia es menor de 20 centímetros o menor -> ALERTA
    digitalWrite(led_verde, LOW);
    digitalWrite(led_amarillo, LOW);
    digitalWrite(led_rojo, HIGH);

You can modify the codes to add more than one sensor to put on the sides and central area of ​​your car. You can also change the distances that are considered safe, precautionary, or dangerous based on your abilities or how sensitive you want them to be. You can even modify the tones of the buzzer. To use cameras, you could do it using a different method, and simply connect a signal from an LCD screen to the image signal from the cameras ...

As you can see, it is a very simple code. Now it would be a matter of moving from the breadboard to a more stable design to leave it permanently working in your car. For that, once proven that it works properly, you can solder the components on a perforated plate or PCB to install it in the car ...

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.