I’ve been encountering a persistent problem with an HC-SR04 Ultrasonic sensor connected to a D1 Mini ESP8266. Despite various attempts to troubleshoot, the sensor fails to return valid distance measurements and often times out, leading to nan values in ESPHome logs. I would appreciate any insights or suggestions you might have. Here’s a detailed account of the issue and the steps I’ve taken so far:
ESPHome Configuration: I’ve double-checked my ESPHome YAML configuration. The trigger pin is set to D1, and the echo pin to D2,
The configuration is really simple and there is much that can go wrong.
Additionally, I’ve used other working sensors’ configurations on the new setup.
Power Supply to D1 Mini: I checked the power supply and change the power source a few times.
Breadboard Setup: I changed the breadboard and the wires a few times to make sure I did not have a faulty breadboard or wire.
Hardware Verification: I’ve tested with multiple HC-SR04 sensors to rule out a defective sensor.
Using the D1 and D2 equivalent to GPIO5 and GPIO4 respectively.
Sensor Testing: Environmental factors and physical obstructions have been considered and ruled out. I’ve also conducted independent tests of the HC-SR04 sensors with a simple Arduino sketch, confirming their functionality outside the ESPHome environment.
Community and Documentation: I’ve looked through the HC-SR04 documentation and searched the ESPHome forums for similar issues but haven’t found a resolution that fits my case.
I have two other sensors working correctly with similar configurations. The codes from the working sensors were directly copied to the new hardware setup, but the problem persists with the new HC-SR04 sensors (I have tried 5 different ones).
I’m reaching out to see if anyone has experienced something similar or can offer guidance on what else I might try to resolve this. Any help would be greatly appreciated.
Thank you for the input. I change to check if anything … but nothing.
This is crazy !!! This is suppose to be so simple.
However I can NOT make these sensors to give me a reading. Like I said I have 2 sensors working for almost 8 months now. Now I an trying to create a few more and I can not !!! CRAZY !!!
I would double check connection (sometimes such cables and prototype boards don’t provide good connection) and try different pins. update_interval has nothing to do with sensor response time, it is just how frequently you’ll be taking the measurement.
Additionally - what is the distance you are measuring? Check the timeout setting - this is related to the max distance the sensor can measure. Check the documentation for parameters: HC-SR04
Hello @adorobis thank you for trying to help.
I did copied your setup, and still having the same issue.
Instead of using 60 min, I used 1 min interval so I can see the results faster.
I had 2 sensors that are working and used the same similar code.
I tried my functional codes in 5 different brand new sensors with new wires and different boards. This is insane and I am so frustrated. Not sure what is doing this.
Although it worked for me before for one sensor, I had to change the value I used for the trigger_pin and the echo_pin for another one to the GPIO# - might be worth a try:
Hello @chairstacker , I did try again to change some of the General I/O and no change. It is so frustrating because this is an easy configuration and I have done it before and currently I have 2 ultrasonic sensors that are working fine.
Now I need to make a few more for other projects and I can not get a single set up to work.
As far as the PINS, it does correspond to what I had in the code
I changed D6 (GPIO12) to trigger and D7 (GPIO13) for Echo.
I have tried, not just other pins, but I have tried 4 different D1 Mini ESP8266 and also 4 different HC-SR04 to make sure that I am not missing something basic.
Like I said before I have 2 functional systems working perfect. I just can not get the next batch to work.