How can I use HCSR04 to measure distance between two object?

Thread Starter


Joined Nov 1, 2016
Hi, I am working on a project to measure distance between two objects (A and B) using Arduino.

Both these two objects are moving with time among other objects, but there is always a Line of sight available (assumed for now). After some research I concluded to use ultrasonic sensors.
My idea is to use an ultrasonic transmitter on object A and a receiver on object B

hcsr04-ultrasonic-sensor (1).jpg

Now my understanding of ultrasonic sensors comes frrom this Arduino ultrasonic sensor tutorial blog, i have also shared the image above for ease of asking this question

From this what is understand is, the HCSR04 module has Tx and Rx units and they work independently. Meaning I can connect the two set of generic HCSR04 ultrasonic sensors and Arduino on object A and object B.

Then on object A I can just give a 10ms pulse to trigger pin of sensor and listen to incoming pulse on object B using the Echo pin of the ultrasonic sensor

I thought this would work until I realized I don't know when exactly the pulse was trigger from Object A to do my calculation as mentioned in the blog.

I tried using RTC on both to sync time, but something tells me it won't be reliable.
So it appears I am stuck, is there any way to do this better? I am even willing to scarp the progress and use a better sensor if something like that is available.


Joined Sep 17, 2013
Time syncing of A and B isn't needed if there is a transmitter and receiver on both objects. When B receives a pulse from A it immediately sends a reply back to A. This reply is received at A as the 'echo'.
1) How far apart are A and B likely to be? Centimetres, metres, ..... ?
2) Ultrasonic transducers are directional. How will you ensure that the transmitter on one object is always aimed at the receiver on the other object?

panic mode

Joined Oct 10, 2011
the sound travels at some 340m/s
the sensing range of the sesnor is max 5m or so.
5m / (340m/s)= 14.7ms.

so if you wait 15ms without triggerning anything, surrounding will be 'silent' (free of ultrasound signals).
also note that sound signals decay fast due to inverse square law, also any reflection will be weaker too....

then you can trigger first sensor and wait for response (or 15ms timeout).
then you can trigger second sensor and wait for response (or 15ms timeout).
use separate IO for each sensor (both trigger and read value)
trigger pulse can be short, 10ms is unnecessarily long.