Distance
HC-SR04
The classic 4-pin ultrasonic distance sensor — TRIG a pulse, time how long ECHO stays high.
HC-SR04 · Generic (various Chinese OEMs)
🍌 Simulates in-browserOverview
The HC-SR04 sends a 40kHz ultrasonic burst on TRIG and outputs a pulse on ECHO whose width is proportional to the round-trip time to whatever it bounced off. There's no single "manufacturer" — it's produced by many OEMs to a shared reference design, so quality and exact timing margins vary a little between units, but the interface itself is very consistent. It is a 5V-only part: ECHO idles and pulses at 5V, which will exceed a 3.3V-only board's absolute-max GPIO voltage without a divider.
Wiring tip: TRIG out, ECHO in (5V) — needs a divider on ECHO for a 3.3V board
Pins & wiring
HC-SR04
Module
Physical pin order shown left to right.
All pins
Hover · click to selectSelected pin
vcc
- Direction
- Power
- Logic / rail
- 5 V
Full pin table
| Pin | Name | Role | Direction | Voltage | Note |
|---|---|---|---|---|---|
| 1 | Power | Power | 5 V | — | |
| 2 | GPIO | In | — | Board drives a ≥10µs HIGH pulse to start a measurement. | |
| 3 | GPIO | Out | 5 V | Pulses HIGH for a duration proportional to distance. 5V logic — needs a divider before a 3.3V-only GPIO. | |
| 4 | Ground | Passive | — | — |
Wiring examples
5V host (Arduino Uno)
arduino-uno pinout →| HC-SR04 pin | Connects to | Note |
|---|---|---|
| VCC | 5V | — |
| TRIG | D9 | — |
| ECHO | D10 | — |
| GND | GND | — |
- No level shifting needed — the Uno's own GPIOs are 5V logic already.
3.3V host (ESP32) — needs a divider on ECHO
esp32-devkit-v1 pinout →| HC-SR04 pin | Connects to | Note |
|---|---|---|
| VCC | VIN | VIN carries the board's 5V USB rail — HC-SR04 needs 5V to work correctly. |
| TRIG | GPIO5 | — |
| ECHO | GPIO18 | Through the divider below, not direct. |
| GND | GND | — |
You also need
- Required1 kΩ resistor between ECHO and GPIO18 — Top half of a 1k/2k divider that drops the 5V ECHO pulse to ~3.3V.
- Required2 kΩ resistor between GPIO18 and GND — Bottom half of the divider.
- ECHO idles/pulses at 5V — wiring it directly into a 3.3V-only ESP32 GPIO risks damaging the pin.
- TRIG can be driven directly from a 3.3V GPIO; the sensor reads it as HIGH well below 5V on the vast majority of units.
Specifications
Performance
Interface
- Interface
- digitalsrc
Footprint
Physical pin order
Left to right as the pins are physically arranged on the part — which is not always the order the datasheet lists them in.
- 1vcc
- 2trig
- 3echo
- 4gnd
Alternatives
No alternatives are on file yet for this part.
Documents
Datasheets
Frequently asked questions
What voltage does the HC-SR04 run at?
The HC-SR04 runs at 4.5–5.5V, per the spec sheet below. Always double-check against the specific board you have — some breakouts add an onboard regulator that changes the usable input range.
How many pins does the HC-SR04 have?
The HC-SR04 has 4 pins, communicating over Digital. See the full pinout table in Pins & wiring for each pin's role.
Can I simulate the HC-SR04 before ordering hardware?
Yes — the HC-SR04 has a live in-browser simulation model, so you can exercise the circuit before ordering any hardware.
Where is the HC-SR04 datasheet?
Linked in the Documents section on this page, and cited on every spec that came from it.
Related references
Build it, do not just look it up
Describe your circuit in one sentence and Banana Board wires it to these exact pins, validates it, and lays out a fab-ready PCB.