Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Wiring the HC-SR04 to the Pico 2 Using a Voltage Divider

If you are using the regular HC-SR04 like I am, you will need to create a voltage divider for the Echo pin. In this section we will look at how to set up the circuit. However, if you are lucky and you bought the HC-SR04 Plus, you can skip to the next page. The circuit becomes much simpler because you can power the sensor with 3.3 V instead of 5 V.

Common resistor combination

Below are some resistor pairs you can use to bring the HC-SR04 Echo signal down to about 3.3 V. R1 is the resistor connected to the Echo pin, and R2 is the resistor connected to ground.

R1 (With Echo)R2 (With Gnd)Output Voltage
330 Ω470 Ω2.94 V
330 Ω680 Ω3.37 V
470 Ω680 Ω2.96 V
680 Ω1 kΩ2.98 V
1 kΩ1.8 kΩ3.21 V
1 kΩ2 kΩ3.33 V
1 kΩ2.2 kΩ3.44 V
1.5 kΩ2.2 kΩ2.97 V
2.2 kΩ3.3 kΩ3.00 V
3.3 kΩ4.7 kΩ2.94 V
4.7 kΩ6.8 kΩ2.96 V
6.8 kΩ10 kΩ2.98 V
22 kΩ33 kΩ3.00 V
33 kΩ47 kΩ2.94 V
47 kΩ68 kΩ2.96 V

You can choose any resistor pair from the table because all of them bring the 5 V Echo signal down to a safe level near 3.3 V. In practice it is best to use the values you already have in your kit.

Connection for the Raspberry Pi Pico 2 and Ultrasonic Sensor

Pico 2 Pin Wire HC-SR04 Pin
VBUS (Pin 40)
VCC
GPIO 17
Trig
GPIO 16 (via Voltage Divider)
Echo (through 1kΩ/2.2kΩ divider)
GND
GND
  • VCC: Connect the VCC pin on the HC-SR04 to VBUS (Pin 40) on the Pico 2. The HC-SR04 requires 5V power, and VBUS provides 5V from the USB connection.
  • Trig: Connect to GPIO 17 on the Pico 2 to trigger the ultrasonic sound pulses.
  • Echo: Connect to GPIO 16 on the Pico 2 through a voltage divider (1kΩ resistor from Echo pin, 2kΩ or 2.2kΩ resistor to ground). The junction between the resistors connects to GPIO 16. This divider steps down the 5V Echo signal to ~3.4V, protecting the Pico’s 3.3V GPIO pins.
  • GND: Connect to any ground pin on the Pico 2.

pico2

Connection for the Pico 2 and LED

Pico 2 Pin Wire Component
GPIO 3
Resistor (220Ω-330Ω)
Resistor
Anode (long leg) of LED
GND
Cathode (short leg) of LED