Ultrasonic icon indicating copy to clipboard operation
Ultrasonic copied to clipboard

Potential Issue: Using GPIO 34 / 35 for Ultrasonic Trigger/Echo Causes Unstable Behavior on ESP32

Open greenhand0403 opened this issue 9 months ago • 0 comments

Hi, I'd like to share a recent issue I encountered while using this library on an ESP32 board that may help others avoid the same pitfall.

I initially set the TRIG and ECHO pins to GPIO 34 and 35 on the ESP32. After uploading the sketch, the board behaved abnormally:

It sent corrupted signals over USB, causing my mouse to move and click randomly on my PC.

The behavior persisted until I unplugged the board.

Even after resetting the board, I had to reflash it on a different PC to regain control.

Upon further testing, I changed the TRIG and ECHO pins to GPIO 17 and 25, and everything started working normally.

🔍 Diagnosis: GPIO 34 and 35 on the ESP32 are input-only pins. Using them with Ultrasonic (which needs output on the TRIG pin) seems to lead to undefined or unstable behavior. This is not a fault of the library, but it's something that may not be obvious to new users.

✅ Recommendation: Avoid using GPIO 34–39 for ultrasonic sensors, especially for the TRIG pin. Stick to GPIOs that support both input and output.

greenhand0403 avatar May 28 '25 07:05 greenhand0403