Strange problem with HC-SR04
Moderators: grovkillen, Stuntteam, TD-er
Strange problem with HC-SR04
I am trying to use ESPEasy with HC-SR04 and I have some strange problem.
If I connect everything and start the device, it comes up for a very short period of time and, I think, it reboots. It keeps rebooting. I see 5-10 ping and 5-10 ping time outs. It keeps doing this.
I found the fix, but it I need something better. If I want to fix it, I have to disconnect Trig and Echo pins and connect them when device is up and running. After that, everything works until I reboot it next time.
I followed this article and used option with resistors: https://www.letscontrolit.com/wiki/index.php/HC-SR04
Any ideas? I have two nodeMCU devices and both do the same for me. Is it a bug with HC-SR04?
Thank you.
If I connect everything and start the device, it comes up for a very short period of time and, I think, it reboots. It keeps rebooting. I see 5-10 ping and 5-10 ping time outs. It keeps doing this.
I found the fix, but it I need something better. If I want to fix it, I have to disconnect Trig and Echo pins and connect them when device is up and running. After that, everything works until I reboot it next time.
I followed this article and used option with resistors: https://www.letscontrolit.com/wiki/index.php/HC-SR04
Any ideas? I have two nodeMCU devices and both do the same for me. Is it a bug with HC-SR04?
Thank you.
- budman1758
- Normal user
- Posts: 303
- Joined: 15 Apr 2017, 05:13
- Location: Riverside CA USA
Re: Strange problem with HC-SR04
What GPIO's are you connecting to? Can you provide a diagram of your setup?
"The glass is twice as big as it needs to be".
Re: Strange problem with HC-SR04
Thank you for your reply. In the end, I was not able to connect at all, so I had to reset and reflash it. Everything works now.
Re: Strange problem with HC-SR04
I have a similar problem. Soon after I boot my Wemos I get a good reading but subsequently, my device is not able to measure any readings. Here is the log:
SR04 : Distance: 132.17
WD : Uptime 1 ConnectFailures 0 FreeMem 18128
SR04 : Distance: No reading!
Host unreachable: 40992557
WD : Uptime 1 ConnectFailures 0 FreeMem 17944
SR04 : Distance: No reading!
I did try the the following sketch and it works okay.
SR04 : Distance: 132.17
WD : Uptime 1 ConnectFailures 0 FreeMem 18128
SR04 : Distance: No reading!
Host unreachable: 40992557
WD : Uptime 1 ConnectFailures 0 FreeMem 17944
SR04 : Distance: No reading!
I did try the the following sketch and it works okay.
Code: Select all
#include <NewPing.h>
#define TRIGGER_PIN 2
#define ECHO_PIN 4
#define MAX_DISTANCE 1000
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup(){
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
}
void loop(){
digitalWrite(LED_BUILTIN, HIGH);
delay (300);
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Ping: ");
long median = sonar.ping_median(10);
float medianFtCompute = (float)median/(148.0 * 12.0);
float medianInch = sonar.convert_in(median);
float medianCm = sonar.convert_cm(median);
Serial.print(medianInch/12.0);
Serial.print(" ft ");
Serial.print(medianFtCompute);
Serial.print(" ft computed ");
Serial.print(medianCm);
Serial.println(" cm");
}
Re: Strange problem with HC-SR04
This problem is back. It seems like it starts when I connect HC-SR04.
I use, as suggested in that document, GPIO-13 and GPIO-12.
Also, I have PCF-8574A attached to this device.
Any ideas?
I use, as suggested in that document, GPIO-13 and GPIO-12.
Also, I have PCF-8574A attached to this device.
Any ideas?
Re: Strange problem with HC-SR04
Could be a power problem. What is your power supply? Are the cables thick enough?
Hypothesis:
Sending an US-ping takes quite a bit of power, so does WiFi. Maybe, when both cooincide --> instability of 5V power supply.
Suggested remmedy:
Beef up PSU, maybe just a cap over 5V to GND and see if behaviour persists.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8
Re: Strange problem with HC-SR04
Thank you for the suggestion, but I tried different PW. I have a few Power Supplies that I use when I play with Raspberry PI devices.
Re: Strange problem with HC-SR04
Can you test an older firmware like the R120 or R147?
Just to see if it is a problem with hardware or with software.
I've tested the setup in the wiki for several days without problem before publishing it with a Mega version, but that's a while ago.
Just to see if it is a problem with hardware or with software.
I've tested the setup in the wiki for several days without problem before publishing it with a Mega version, but that's a while ago.
Regards
Shardan
Shardan
Re: Strange problem with HC-SR04
Sorry, but it is already in place and working. I do not want to start making changes now.
It restarts multiple times in the beginning, but after that everything seems to be working.
It restarts multiple times in the beginning, but after that everything seems to be working.
Who is online
Users browsing this forum: No registered users and 11 guests