Skip to main content

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-browser
Voltage
4.5–5.5V
Package
Module
Pins
4
Interfaces
Digital
Lifecycle
Unknown
Footprint
Curated mapping

Overview

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

ultrasonicdistance5v-onlydigital

Pins & wiring

01Pin map
4 positions

HC-SR04

Module

Physical pin order shown left to right.

PowerGroundGPIO

All pins

Selected pin

vcc

Power
Direction
Power
Logic / rail
5 V
Full pin table
PinNameRoleDirectionVoltageNote
1PowerPower5 V
2GPIOInBoard drives a ≥10µs HIGH pulse to start a measurement.
3GPIOOut5 VPulses HIGH for a duration proportional to distance. 5V logic — needs a divider before a 3.3V-only GPIO.
4GroundPassive

Wiring examples

5V host (Arduino Uno)

arduino-uno pinout →
HC-SR04 pinConnects toNote
VCC5V
TRIGD9
ECHOD10
GNDGND
  • 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 pinConnects toNote
VCCVINVIN carries the board's 5V USB rail — HC-SR04 needs 5V to work correctly.
TRIGGPIO5
ECHOGPIO18Through the divider below, not direct.
GNDGND

You also need

  • Required1 kΩ resistor between ECHO and GPIO18Top half of a 1k/2k divider that drops the 5V ECHO pulse to ~3.3V.
  • Required2 kΩ resistor between GPIO18 and GNDBottom 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

Electrical

Active Supply Current
15 mAsrc
Operating Voltage
4.5 – 5.5 Vsrc

Performance

Measures
distancesrc
Range Min
2cmsrc
Range Max
~400cm (readings get unreliable beyond ~4m)src
Accuracy
±3mmsrc
Resolution
~0.3cmsrc
Sampling Rate
16.6 Hzsrc

Interface

Interface
digitalsrc

Physical

Package
Module
Length
45 mmsrc
Width
20 mmsrc
Height
15 mmsrc
Weight
8.5 gsrc
Mounting
module

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.

  1. 1vcc
  2. 2trig
  3. 3echo
  4. 4gnd

Alternatives

No alternatives are on file yet for this part.

Documents

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.

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.

Start building free