Go Down

Topic: Very slow HC-SR04 ultrasonic sensor? (Read 1 time) previous topic - next topic


Problem: My ultrasonic sensor takes forever.  It adds 100 to 500mS to my loop() cycle time.  I'm using an HC-SR04 (same as SRF04?) ultrasonic sensor with the arduino library (ultrasonic.h) downloaded from your site.  I tried another HC-SR04 sensor without any improvement so I think the problem is with the library.  I have also tried the ultrasonic.h library from iteadstudio.com with no improvement.  I undefined the COMPILE_STD_DEV line as suggested in the readme but still have the same delay.  The delay seems to change as it is being used.  Maybe the delay is caused by it waiting for a good reading before proceeding?  I can't delay other time-critical functions in my loop() such as reading an encoder.  If it doesn't get a good reading immediately then it should skip that bad reading, return a failed bit, and try again in the next loop().

Any suggestions?


Have you heard about the NewPing library?  It's a better way to interface with ultrasound sonar sensors because it uses interrupts so your code will not block as much.



Thanks jtbourke!  I tried the NewPing library and it works great!  Thanks to the creator Tim Eckel!  All the other sonic libraries should be removed to prevent others wasting their time with them.  Does no one at arduino.cc approve library additions?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131