Ultrasonic Sensor HC-SR04

# Overview An **ultrasonic sensor** is an electronic device used to measure distance or detect objects by emitting ultrasonic sound waves and analyzing the echoes that return. These sensors operate using high-frequency sound waves that are above the human hearing range (typically above 20 kHz). # How It Works ![Pasted image 20250128114858.png](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/Pasted_image_20250128114858.png?v=1741565134) 1. **Emission:** The sensor’s **transmitter** emits ultrasonic waves. 2. **Reflection:** The waves travel through the air until they hit an object and reflect back. 3. **Reception:** The sensor’s **receiver** detects the reflected waves (the echo). 4. **Calculation:** The sensor calculates the distance using the following formula. Here, the time represents the total duration for the sound wave to travel to the object and return. Dividing by 2 accounts for the round trip of the wave. $$ Distance = \frac{Speed\ of\ Sound \times Time}{2} $$ # HC-SR04 Ultrasonic Sensor The **HC-SR04** is a popular and affordable ultrasonic distance sensor used in various DIY electronics and robotics projects. It measures the distance to an object by emitting ultrasonic waves and calculating the time it takes for the echo to return. ![Pasted image 20250127172635.png](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/Pasted_image_20250127172635.png?v=1741565138) ![](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/Pasted_image_20250127172615.png?v=1741565142) ### Pinout | Pin | Name | Description | | --- | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 1 | VCC | Power supply (3.3V or 5V) | | 2 | Trig | Trigger input signal
Setting this pin to HIGH for 10µs, the sensor initiates an ultrasonic burst. | | 3 | Echo | Echo output signal
The **Echo** pin goes high when the ultrasonic burst is sent and stays high until the echo is received, then it goes low. The duration the Echo pin stays high is used to calculate the distance. | | 4 | GND | Ground | ## **Key Features** - **Operating Voltage**: 3.3V-5V DC - **Operating Current**: ~15mA - **Measurement Range**: 2 cm to 400 cm (0.78 inches to 13 feet) - **Accuracy**: ±3 mm - Trigger Input Signal: 10us TTL pulse ## Pin Functions The **HC-SR04** ultrasonic sensor measures distance by sending out sound waves and measuring how long it takes for them to bounce back. Here’s how it works in simple terms: ### Trigger (Trig) Pin The MCU send a small pulse (around 10 microseconds) to the **Trig** pin to tell the sensor to start. This pulse makes the sensor send out an ultrasonic sound wave. ### **Echo Pin** After the wave is sent, the sensor listens for the sound to bounce back (echo). The **Echo** pin stays **high** while the sensor waits for the echo. Once the echo is received, the pin goes **low**. The sensor measures how long the **Echo** pin stays high. The longer it stays high, the farther away the object is. Using the time it takes for the echo to return, you can calculate the distance to the object. In summary, the **Trig** pin triggers the sound wave. The **Echo** pin tells MCU how long it took for the sound wave to return, which helps calculate the distance.

RELATED ARTICLES