# HC-SR04 always reads 0 on an ESP32? Here's why

> A 0 from an HC-SR04 means no echo pulse arrived. Check 5 V power, the echo divider, the 10 us trigger, the 60 ms cycle, range and angle, and the timeout.

[HTML version](https://soldr.ai/blog/hc-sr04-reads-zero-esp32)

8 November 2026 · Soldr

**Short answer:** a reading of 0 almost always means the echo pulse never arrived and the timing function gave up. Check, in this order: the sensor is powered from 5 V (its datasheet says DC 5 V); the echo signal actually reaches the ESP32 pin through your divider or level shifter; the trigger is a 10 µs pulse; you wait more than 60 ms between measurements; and the target is between 2 cm and 4 m away, within about 15° of straight ahead.

The HC-SR04 is simple: you send a short trigger pulse, it fires an ultrasonic burst, and its echo pin goes high for as long as the sound took to come back. On an Uno this usually works first time. On an ESP32 it often prints 0 forever. In Arduino code, `pulseIn()` returns 0 when it times out waiting for the pulse, so 0 doesn't mean "nothing in front": it means "no echo pulse seen". Here's what the module's datasheet says and where things go wrong, as cited on our [HC-SR04 reference page](https://soldr.ai/docs/components/hc-sr04).

## 1. It's powered from 3.3 V

The datasheet gives a working voltage of **DC 5 V**. On an ESP32 it's tempting to wire VCC to the 3.3 V pin so the echo comes back at a safe level. Below its rated supply the module isn't specified to work, and a steady 0 is a common result. Power the HC-SR04 from 5 V (the DevKit's 5V pin when it runs from USB) and handle the echo level separately (next point).

## 2. The echo never reaches the ESP32 pin

The datasheet describes the echo output only as "TTL level", without a voltage figure. Powered from 5 V, its high level can be well above the ESP32's 3.6 V input rating, so it should go through a voltage divider or a level shifter. That's where it often breaks:

- **Divider the wrong way round.** The larger resistor goes from the ESP32 pin to ground, the smaller one from the echo pin to the ESP32 pin. Swapped, the pin sees too little voltage to count as high.

- **A loose or missing ground.** The sensor, the divider and the ESP32 need a shared ground. The datasheet even asks for GND to be connected first when powering up.

- **The wrong pin in the code.** Check the echo pin number in the sketch against where you wired it, and avoid the ESP32's boot-sensitive pins. See [ESP32 strapping pins](https://soldr.ai/blog/esp32-boot-strapping-pins).

There's more on choosing a divider in [5 V sensors on a 3.3 V ESP32](https://soldr.ai/blog/5v-sensor-3v3-esp32-logic-levels).

## 3. The trigger pulse is wrong

The datasheet specifies a **10 µs TTL pulse** on the trigger input. A trigger that's too short, or one that's never brought low before the pulse, may not start a measurement. The usual pattern is: drive the trigger low briefly, high for 10 µs, then low again, then time the echo. A 3.3 V trigger from the ESP32 is normally read as high by the module's TTL input.

## 4. Measuring too often

The datasheet suggests a **measurement cycle of over 60 ms**. Trigger again before the previous burst has died away and the module can miss the new echo, or catch the old one. Space readings at least 60 ms apart; 100 ms is a comfortable default.

## 5. The target is out of range or at an angle

- **Range:** 2 cm to 400 cm. Closer than 2 cm and the echo returns before the module is listening.

- **Angle:** the datasheet gives a 15° measuring angle. A wall at a steep angle reflects the sound away from the sensor.

- **Surface:** soft, small or rounded objects reflect less. Test against a flat, hard surface first.

If readings work against a wall but not your real target, the wiring is fine and it's the target.

## 6. The timeout is too short (or too long)

A 4 m round trip takes about 23 ms at the speed of sound. If your timing call's timeout is shorter than the distances you expect, far targets read as 0. If it's much longer, a missed echo blocks your loop. A timeout around 25 to 30 ms covers the full range.

## Converting the pulse to distance

The echo pulse width is the round-trip time. Distance = pulse time × speed of sound ÷ 2. At roughly 343 m/s, that's about 58 µs per centimetre of distance, so `distance_cm = pulse_us / 58.0`.

## A sketch that says what's wrong

Sketches Soldr writes report each part at startup and print a fix line when a check fails, so a dead sensor shows up as a named line in the Serial Monitor instead of a silent 0. [How to read those lines](https://soldr.ai/blog/arduino-serial-monitor-self-test-debugging). When you describe the build, say how the echo is handled ("HC-SR04 on 5 V with a divider on the echo pin"), so the build doesn't have to guess.

On Compoden: [HC-SR04](https://compoden.com/products/hc-sr04-ultrasonic-sensor-module-5v-distance-2cm-400cm), [ESP32-DevKitC](https://compoden.com/products/esp32-devkitc-development-board-black-wifi-bluetooth-module), [resistor pack](https://compoden.com/products/resistor-variety-pack-100-pcs-10-values-14w-carbon-film). Describe your build on [app.soldr.ai](https://app.soldr.ai). Sign in and get 100 credits free.
