The video begins by introducing the concept of ultrasound, defining it as sound waves with frequencies above the human hearing range (typically 20 kHz). The HCSR04 operates at 40 kHz, using these high-frequency waves to measure distances by reflecting them off objects and calculating the time it takes for the sound to return.
The HCSR04 is an ultrasonic distance sensor that works on the principle of echolocation. It has two transducers: one transmits 40 kHz ultrasonic pulses, and the other receives them after they bounce back from an object. It can detect objects between 2 cm and 400 cm. The sensor has four pins: VCC (5V power), Trig (to send pulses), Echo (outputs pulse return time), and GND (ground).
To measure distance, the Trig pin is set high for 10 microseconds to send an eight-cycle burst of ultrasonic waves. The Echo pin goes high immediately after transmission and goes low when the echo returns. The duration of this pulse on the Echo pin represents the round trip time. If no echo is detected within 38 milliseconds, it indicates no object within range.
The distance is calculated using the formula: distance = speed × time. The speed of sound in air is approximately 340 m/s or 0.034 cm per microsecond. Since the pulse duration is for a round trip (to the object and back), the calculated distance is divided by two to get the actual distance to the object. For example, a 500-microsecond pulse indicates an object 8.5 cm away.
The HCSR04 has several limitations. It struggles with accuracy beyond 4 meters (13 feet) due to signal attenuation. Objects with tilted surfaces can cause sound waves to deflect away, preventing an echo. Soft or irregular surfaces, like fabric, can absorb sound, making detection difficult or impossible for the sensor.