Strange problem with HC-SR04

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
onlize
Normal user
Posts: 44
Joined: 12 Aug 2017, 03:44

Strange problem with HC-SR04

#1 Post by onlize » 20 Mar 2018, 01:53

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.

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Strange problem with HC-SR04

#2 Post by budman1758 » 21 Mar 2018, 06:27

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".

onlize
Normal user
Posts: 44
Joined: 12 Aug 2017, 03:44

Re: Strange problem with HC-SR04

#3 Post by onlize » 21 Mar 2018, 06:47

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.

ssathya
New user
Posts: 4
Joined: 16 Mar 2018, 23:18

Re: Strange problem with HC-SR04

#4 Post by ssathya » 29 Mar 2018, 15:36

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.

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");
}

onlize
Normal user
Posts: 44
Joined: 12 Aug 2017, 03:44

Re: Strange problem with HC-SR04

#5 Post by onlize » 31 Mar 2018, 06:07

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?

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Strange problem with HC-SR04

#6 Post by toffel969 » 31 Mar 2018, 09:14

onlize wrote: 31 Mar 2018, 06:07 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?
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

onlize
Normal user
Posts: 44
Joined: 12 Aug 2017, 03:44

Re: Strange problem with HC-SR04

#7 Post by onlize » 31 Mar 2018, 16:36

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.

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Strange problem with HC-SR04

#8 Post by Shardan » 31 Mar 2018, 19:25

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.
Regards
Shardan

onlize
Normal user
Posts: 44
Joined: 12 Aug 2017, 03:44

Re: Strange problem with HC-SR04

#9 Post by onlize » 01 Apr 2018, 02:04

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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 40 guests