Skip to main content
PartAndStock
Blog

What Is the HC-SR04? Ultrasonic Distance Sensor: Calculation and Uses

October 14, 2026 5 min read
Quick answer

The HC-SR04 is a popular ultrasonic distance sensor. A 10 µs pulse is sent to Trig, the sensor emits sound; the Echo pin stays high for the echo time. Distance = time × 0.0343 / 2 (cm). It measures ~2–400 cm at ~3 mm resolution; it is 5 V and its Echo output may need a level shifter on a 3.3 V MCU.

The HC-SR04 is a popular ultrasonic distance sensor that measures distance with ultrasonic waves. Being cheap and easy to use, it is a standard part in robotics and obstacle detection. For the concept, see what is a sensor.

What is the HC-SR04 used for?

Obstacle/distance detection, parking sensors, water level, robot navigation. A short pulse is sent to the Trig pin, the sensor emits ultrasound; when the echo returns, the Echo pin stays high for the echo time. Distance is computed from this time.

HC-SR04 pinout (4 pins)

PinFunction
VCC+5 V
TrigTrigger (10 µs pulse)
EchoEcho (duration = distance)
GNDGround

How is distance calculated?

Measure how long Echo stays high (µs). The speed of sound in air is ~343 m/s: Distance (cm) = time (µs) × 0.0343 / 2 (divided by two because it is a round trip).

Highlights

ParameterValue
Range~2 – 400 cm
Resolution~3 mm
Supply5 V

Limitations

  • Soft/angled surfaces do not reflect sound → wrong readings.
  • Temperature affects the speed of sound (correction needed for precise measurement).
  • The Echo output is 5 V; a 3.3 V MCU may need a level shifter.

Equivalents and alternatives

  • HC-SR04P / RCWL-1601: 3.3 V-compatible versions.
  • VL53L0X: laser (ToF) distance, more precise.
  • GP2Y0A21 (Sharp): infrared distance.

Find it in our catalog

Use the HC-SR04 search.

Frequently Asked Questions

What is the HC-SR04?+
The HC-SR04 is a popular sensor that measures distance with ultrasonic waves. It emits sound via Trig and reports the echo time via Echo; it measures over ~2–400 cm at ~3 mm resolution.
How does the HC-SR04 calculate distance?+
You measure how long Echo stays high (µs) and find Distance (cm) = time × 0.0343 / 2 (speed of sound ~343 m/s, divided by two because it is a round trip).
What is the HC-SR04 pinout?+
4 pins: VCC (+5 V), Trig (trigger, 10 µs pulse), Echo (echo time), GND.
Does the HC-SR04 work with 3.3V?+
The standard HC-SR04 is 5 V and its Echo output is 5 V; a 3.3 V MCU needs a level shifter. There are 3.3 V-compatible HC-SR04P/RCWL-1601 versions.
What is an equivalent of the HC-SR04?+
The 3.3 V-compatible HC-SR04P/RCWL-1601; the more precise laser VL53L0X; the infrared GP2Y0A21.