BEEP Like a Car! Sonar Sensor

I don’t like much the noisy BEEP you get with modern cars when parking sensor are enabled, but is quite useful, isn't it?!

Do I need a portable sensor telling me how far I am from an obstacle? Probably not, at least until my eyes keep working.

However, I still wanted to experiment and make my own portable “parking” sensor (or audible distance measurement tool).

Car sensors are IR, but I had not a spare IR receiver at home, instead I found an HC-SR04 ultrasonic sensor in the drawer. Some easy wiring/coding it is: How to BEEP like a car!

Bill of materials:

- HC-SR04 x 1: ultrasonic sensor

- uChip: Arduino IDE compatible board

- Piezoelectric Buzzer

- 10 KOhm, 820 Ohm resistors (or any other value you find around getting close enough)


- micro-USB cable ( plus a 5V USB power source if you want to make it portable)

Step 1: Wiring

The micro-USB connector provides the power that uChip delivers on VEXT (pin_16) and GND (pin_8).

As for the GPIO wiring, any combination is possible as long as you use PWM enabled pin ports.

In my case, I used pin_1 to control the buzzer, while pin_9 and pin_10 are connected to the ECHO and TRIGGER signal pins respectively of the ultrasonic sensor.

Independently whether you are using an active or a passive buzzer (which are a buzzer with integrated driving circuit or a simple piezoelectric membrane respectively), the control circuit is equivalent. However, be careful when wiring an active buzzer since you must check the polarity of the pins, while using a passive that is negligible.

TIP: How do you check whether your buzzer is active or passive?

Usually an active buzzer carries a + mark somewhere on it indicating the polarity. On the other hand, passive transducers do not have such a mark.

Step 2: Programming

Load the sketch “BeepLikeACar.ino” into uChip using the Arduino IDE.

Set the various #define accordingly to your needs. As default, the minimum distance is 200 mm while the maximum is 2500 mm. Furthermore, you are more than welcome to modify the BUZZ_DIV define in order to change the frequency with which the beep occurs.

TIP: The code now works using the delay() function which is absolutely not the optimal solution in a real car sensor application!

Indeed, using delay() the MCU is kept busy by the time counting function and cannot process any other info. What happens is that, in case we move too fast, the sensor won’t respond quickly enough to see the obstacle since it is busy on “waiting”. Thus, DO NOT USE THIS CODE ON SELF-CONTROLLED MOVING DEVICES SINCE IT COULD BE DANGEROUS!!

However, without direct access to registers or interrupts usage, the code is easier to read and everybody can understand what the code does. That is why I preferred the delay() function approach for this tutorial.

The optimize code will be published in the next future.

Step 3: Enjoy!

Connect the micro-USB cable to uChip and go around your house, BEEP like a car!



    • Paper Contest

      Paper Contest
    • Weaving Challenge

      Weaving Challenge
    • Epilog X Contest

      Epilog X Contest