ohmio

Circuits / Sensors

ESP32 with an HC-SR04 (ECHO through a divider)

The HC-SR04 needs 5 V and its ECHO is 5 V; a 3.3 V board's pin takes it through 1 kΩ / 2 kΩ, which leaves 3.33 V, while TRIG at 3.3 V is enough for the module

ESP32 with an HC-SR04 (ECHO through a divider), simulated on a breadboard

Tap a part to see its voltages and currents. It is a model, not a measurement.

What do you need?

The AliExpress links are affiliate links: if you buy through them ohmio.dev gets a commission, at no extra cost to you. Affiliate links

This page is a guide: the numbers come from a simulation, and real parts vary. Check your parts before you power the circuit. Safety and responsibility

Why does an HC-SR04 need a voltage divider on an ESP32?

The HC-SR04 needs 5 V, and then its ECHO pin goes up to about 5 V when high: 4.95 V in this model. An ESP32 pin works with 3.3 V logic, and 5 V straight into it would push current through the pin's protection diode. Two resistors solve it. R1 (1 kΩ) and R2 (2 kΩ) form a divider that passes two thirds of ECHO, so the pin sees 3.30 V during the echo and about 0 V the rest of the time, while only 1.65 mA flows through the pair. TRIG goes the other way and needs no help: the ESP32's 3.3 V output is enough to start the module. The sketch is the one from the UNO, a 10 µs pulse, pulseIn and microseconds ÷ 58, so an object at 30 cm prints 30. The module takes its 5 V from VIN, which carries 5 V when the board is powered by USB.

Values from the Protoboard ISO simulation: a model, not a bench measurement.