HC-SR04P ultrasonic distance (3.3-5 V) with ESP32

Supply 3.3-5 V Bus GPIO Measures distance
VCCTRIGECHOGND

Pins and ESP32 wiring

PinRoleESP32 pinNotes
VCCPower3V3Use 3V3: then ECHO is also 3.3 V and safe for the ESP32
TRIGInput (the ESP32 drives it)D25A 10 µs HIGH pulse starts a measurement
ECHOOutput (the part drives it)D26Pulse length = echo time. Level equals VCC: at 5 V use a divider
GNDGroundGND

Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.

Sources

Try it in 3D in BoardPilot

BoardPilot Part data (JSON)

Related parts

Part data: CC BY 4.0, free to reuse with credit to BoardPilot.