HC-SR04 with ESP32-S3-DevKitC-1

Wiring for the HC-SR04 ultrasonic distance on the ESP32-S3-DevKitC-1 (ESP32-S3, 3.3 V logic), chosen with the same pin rules BoardPilot uses: default buses first, and no pins that are used for flash, USB, the debugger or booting.

Wiring

HC-SR04 pinRoleESP32-S3-DevKitC-1 pinNotes
VCCPower5VNeeds 5 V: use 5V
TRIGInput to the part4A 10 µs HIGH pulse starts a measurement
ECHOOutput from the part5
GNDGroundG

Check before you power it on

Test code (Arduino)

void setup() {
  Serial.begin(115200);
  pinMode(4, OUTPUT);  // TRIG on 4
  pinMode(5, INPUT);   // ECHO on 5
}

void loop() {
  digitalWrite(4, LOW);  delayMicroseconds(2);
  digitalWrite(4, HIGH); delayMicroseconds(10);
  digitalWrite(4, LOW);
  long us = pulseIn(5, HIGH, 30000);
  Serial.println(us / 58.0);  // distance in cm
  delay(200);
}

Arduino board: esp32:esp32:esp32s3. Use the port labelled UART. If uploading does not start, hold BOOT, press and release RESET, then release BOOT.

Questions

Which ESP32-S3-DevKitC-1 pins do I use for the HC-SR04?

VCC → 5V, TRIG → 4, ECHO → 5, GND → G.

Does the HC-SR04 work with the ESP32-S3-DevKitC-1 at 3.3 V?

The HC-SR04 works at 5 V, so its output (ECHO → 5) can reach 5 V. The ESP32-S3-DevKitC-1 pins take only 3.3 V: add a voltage divider (for example 1 kΩ and 2 kΩ) or a level shifter on that wire.

BoardPilot checks this wiring in 3D as you build it, and finds crossed or missing wires on the real board.

Download BoardPilot

Full ESP32-S3-DevKitC-1 pinout · HC-SR04 ultrasonic distance: all pins and data

The HC-SR04 on other boards

Other parts on the ESP32-S3-DevKitC-1