Pages: [1]   Go Down
Author Topic: Very slow HC-SR04 ultrasonic sensor?  (Read 757 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 105
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Jim
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 105
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: [1]   Go Up
Jump to: