Working Principle
- Arduino sends a 10 μs pulse to the TRIG pin.
- HC-SR04 emits ultrasonic sound waves.
- Sound waves hit an object and return as an echo.
- The ECHO pin stays HIGH for the travel time.
- Arduino measures this time.
- Distance is calculated using:
Distance=Duration×0.0342Distance = \frac{Duration \times 0.034}{2}Distance=2Duration×0.034
- If the distance is less than or equal to 10 cm:
- Otherwise:
Expected Output
| Distance |
LED Status |
| 5 cm |
ON |
| 8 cm |
ON |
| 10 cm |
ON |
| 15 cm |
OFF |
| 25 cm |
OFF |