B4R Question I need a library for HC-SR04 ultra sonic module

vali khandangoll

Active Member
Hi all of you.
I have 2 HC-SR04 ultra sonic module like below.

my library works correctly with module No 1 and not works with No2 in B4R.
my library always return 0 in module No2.
Does anyone have a library for this type of module?
 

janderkan

Well-Known Member
Licensed User
Longtime User
1679429138649.png
 
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
Do you have any code ?
Have you tried any of the similar threads ?
What board are you using ?
 
Upvote 0

emexes

Expert
Licensed User
I have 2 HC-SR04 ultra sonic module like below.

On a slight tangent: do you have two modules to provide "stereo" operation?

As in, if you transmit using module 1, do *both* modules 1 & 2 both receive the echo (likely offset slightly by time)? Or does a module only start receiving *after* it has done a transmit?
 
Upvote 0

emexes

Expert
Licensed User
Does anyone have a library for this type of module?

How accurate does the distance measurement need to be?

If your Arduino isn't too busy, it might be simpler taking readings with a software polling loop and a Delay(1). Sound travels around 30 cm in 1 ms, and divide that by two for the round trip, so you'd be getting readings in the order of +/- 15 cm.

Or if you were willing to time and rely on your Arduino's empty polling loop rate, then +/- 1 cm looks plausible.
 
Upvote 0
Top