This project of mine is a bit on the simpler side but as fun as the other projects. In this project, we are going to interface an HC-SR04 Ultrasonic distance sensor module. This module works by generating ultrasonic sound waves that are out of the audible range of human beings and from the delay between the transmission and reception of the generated wave the distance is calculated.
Here we are going to interface this sensor with Arduino and will try to mimic a parking assistant system that according to the distance from the obstacle behind generates different sounds and also lights up different LEDs according to the distance.
So let's get to the fun part now.
Get PCBs for Your Projects Manufactured
You must check out PCBWAY for ordering PCBs online for cheap!
You get 10 good quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop.
About HC-SR04 Ultrasonic Ranging Module
The ultrasonic sensor (or transducer) works on the same principles as a radar system. An ultrasonic sensor can convert electrical energy into acoustic waves and vice versa. The acoustic wave signal is an ultrasonic wave traveling at a frequency above 18kHz. The famous HC SR04 ultrasonic sensor generates ultrasonic waves at 40kHz frequency. This module has 4 pins which are Echo, Trigger, Vcc, and GND
Typically, a microcontroller is used for communication with an ultrasonic sensor. To begin measuring the distance, the microcontroller sends a trigger signal to the ultrasonic sensor. The duty cycle of this trigger signal is 10µS for the HC-SR04 ultrasonic sensor. When triggered, the ultrasonic sensor generates eight acoustic (ultrasonic) wave bursts and initiates a time counter. As soon as the reflected (echo) signal is received, the timer stops. The output of the ultrasonic sensor is a high pulse with the same duration as the time difference between transmitted ultrasonic bursts and the received echo signal.
The microcontroller interprets the time signal into distance using the following function:
Distance(cm) = Echo Pulse Width(microseconds)/58
Theoretically, the distance can be calculated using the TRD (time/rate/distance) measurement formula. Since the calculated distance is the distance traveled from the ultrasonic transducer to the object—and back to the transducer—it is a two-way trip. By dividing this distance by 2, you can determine the actual distance from the transducer to the object. Ultrasonic waves travel at the speed of sound (343 m/s at 20°C). The distance between the object and the sensor is half of the distance traveled by the sound wave and it can be calculated using the below function: