ESP32 ultrasonic sensor wiring on breadboard – is this correct?

Hello,

I am currently working on a smart parking system project. The idea is to use an ESP32 together with an ultrasonic sensor to detect whether a parking space is occupied, and then send the data to a web application.

At the moment, I am trying to build and test a single unit using an ESP32 (without Arduino Uno). I am powering the ESP32 through USB, and then distributing power to the breadboard by connecting 3.3V (3V3) and GND from the ESP32 to the power rails.

The ultrasonic sensor is connected as follows:

  • VCC → 3.3V rail
  • GND → GND rail
  • TRIG → GPIO pin (e.g., D5)
  • ECHO → GPIO pin (e.g., D18)

However, I understand that the ECHO pin of many ultrasonic sensors outputs 5V, while the ESP32 uses 3.3V logic.

My questions are:

  1. Is it safe to connect the ECHO pin directly to an ESP32 GPIO (like D18), at least for testing?
  2. Should I always use a voltage divider (for example 1kΩ and 2kΩ resistors) between ECHO and the ESP32?
  3. If yes, could you confirm that this is the correct approach for protecting the ESP32 input?

Also, I would appreciate if someone could confirm whether my overall wiring approach (powering the breadboard from ESP32 3.3V and GND and connecting the sensor this way) is correct.

Thank you for your help!


please post a link to the sensor’s datasheet.

there’s a chance that the sensor needs 5V for both input and output and then you would need a level shifter (which are cheap for your use-case)

also, the sensor may require more power than your ESP32 board can deliver (the AMS1117 on your board can theoretically deliver 1A but that’s the absolute maximum and requires a heatsink which is not present on your board).

Here is the sensor I am using: https://makerhero.com/img/files/download/RCWL-1655-Datasheet.pdf

Could you please give me some advice on how I should properly build this setup?
What should I change in my wiring, and what additional components would you recommend for a reliable and safe project?
For example:
1.a level shifter or voltage divider?
2.should I use an external power supply instead of the ESP32?
3.are there any components I am missing?
I would really appreciate a clear recommendation on how to proceed and what I should buy or adjust.

So what does the datasheet say about voltage?

What have you set R7 to, that determines if you use WIRE1, UART, I2C. I like IIC but you may have other preferences. I looked in library manager to see if an RCWL-1655 library existed but didn't find one. I did find a different library but for the same type of sensor. It has the same 3 interfaces and sample code for each. Check it out.

the datasheet doesn’t say much about the output voltage but google’s AI has some good news:

AI Overview

The RCWL-1655 ultrasonic sensor outputs a 3.3V or 5V TTL level signal on its ECHO pin in GPIO mode, matching the voltage of the supplied power (2.8-5.5V). It acts as a standard HC-SR04 compatible distance sensor, producing a high-level pulse proportional to the distance measured.

Logic Level: The output voltage on the Echo pin matches the operating voltage (2.8-5.5V) suitable for 3.3V or 5V microcontrollers.
Default Mode: The default GPIO mode (sometimes labeled GP10 in documentation) behaves as an HC-SR04 compatible trigger/echo interface.
Operation: The sensor outputs a high-level TTL pulse indicating the time-of-flight, requiring a trigger pulse to start the measurement.

If that is correct, you don’t need any level shifting.

The ultrasonic module seems to draw a maximum of 40mA which is totally within the capabilities of your ESP32 board.

The code should be pretty straightforward.

you may want to have a look at this page

@k4sl

The ultrasonic sensor is connected as follows:

VCC → 3.3V rail
GND → GND rail
TRIG → GPIO pin (e.g., D5)
ECHO → GPIO pin (e.g., D18)

That's good

Yes.

2 Should I always use a voltage divider

No.

confirm whether my overall wiring approach (powering the breadboard from ESP32 3.3V and GND and connecting the sensor this way) is correct.

It's correct.

Thank you

Hi! Welcome to the Forum.

The link you posted is from a brazilian store. If you’re from Brazil, you may want to know that there is a specific forum session in portuguese.

you can come back from time to time, share your accomplished projects and help others. :wink: