Skip to content
A project ofgwark.dev

Generic · Integrated circuit

HC-SR04 Ultrasonic Rangefinder

Ping-and-listen distance sensor, 2 cm to 4 m. Four pins, 5 V only, and an echo pin that will happily feed 5 V into a 3.3 V board.

Cheat sheet (SVG)
Logic level
5 V
Package
4-pin 2.54 mm header

1.Pinout diagram

Highlight a signalhover to preview, click to keep

Header, front view

HC-SR04

Pin detail

Hover a pin for its mappings and gotchas. Click to keep it here.

Logic level
5 V
Package
4-pin 2.54 mm header

Fig. 1. HC-SR04 Ultrasonic Rangefinder, 4-pin 2.54 mm header. Hover or tap a signal to light up every pin that carries it.

2.Watch out

3.Level shifting the echo

What has to go around the chip before it will run.

VCCGNDHC-SR042 kOhm between MCU and GND2 kOhm100 uF between VCC (1) and GND100 uFVCC (1) to VCCGND (4) to GND1 kOhm between MCU and ECHO (3)1 kOhmMCUVCC 1VCC 1ECHO 3GND 4
Fig. 2. Level shifting the echo, drawn from Table 1. Dashed parts are optional. Crossing wires are not connected.
Table 1. External parts, and why each one is there.
PartBetween
1 kOhmECHO (3) to MCU
2 kOhmMCU to GND
100 uFoptionalVCC (1) to GND

TRIG is an input and tolerates a 3.3 V drive, so only ECHO needs the divider. The module has no 3.3 V variant worth trusting: the ones sold as 3 V parts are usually the same board with a different regulator.

4.Full pin reference

Every pin, alias and mapping. This is the table that prints.

Table 2. Pin assignments.

Complete pin reference for HC-SR04 Ultrasonic Rangefinder
PinNameFunctions

Primary sources

Found a wrong pin? The whole board is one file, data/boards/hc-sr04.json.

Edit this file on GitHubReport it instead