# How do I calculate Distance between two sensors?

How do I calculate the distance between the two light sensors (ie. Infrared LED and PhotoDiode). Actually I am designing a device based on the similar principle of GPS to control the mouse position on my computer system. Here is the schematic diagram of what I am trying to do:

I placed 3 photo diodes receivers (Red,Green,Blue) and one infrared led (Yellow), I have to find the position of infrared led for which I have to calculate the distance between LED and PhotoDiode, through the distance I can easily create imaginary circles around Photo diodes and can easily find out the position of LED (The common points of circles)

This question might be off-topic for this forum, but I asked it here because I think it is right place for it.

• In what way are you planning to do the distance measurement? Why three different color receivers? – posipiet Mar 4 '12 at 13:25
• @posipiet - The receivers are not coloured, I use colours in the diagram to clearly express my idea. – Farid-ur-Rahman Mar 4 '12 at 13:35
• @posipiet the colors are just for the representation, they are all equal, and the distance I guess is measured by the strength of the signal – clabacchio Mar 4 '12 at 13:44
• @Farid-ur-Rahman it's not exactly clear how could we help you: do you need an algorithm to calculate the distance, a circuit to amplify the signal, or what? – clabacchio Mar 4 '12 at 13:45
• @clabacchio - I need an algorithm to calculate the distance. – Farid-ur-Rahman Mar 4 '12 at 13:53

Finding distances accurate to a few mm is not going to work with LEDs and photodiodes. Light takes about 1 ns per foot. To measure distance with time of arrival you would need resolution of just a few ps. Not only do ordinary LEDs and photodiodes not react that fast, but the circuit to interpret those signals would need to be very very special even if they could.

You may be able to get what you want by using ultrasound instead of light. At about 3 ms per meter, you have some chance of getting reasonable resolution. Typical cheap ultrasound transducers are resonant around 40 kHz. Those will probably not be good enough because the limited bandwidth will get in the way of the time resolution you need. You should look at higher frequency ultrasound transmitters and receivers that are also more broad spectrum. You might have a chance with those.

Otherwise, there are other techniques than time of arrival to determine position. You could still use light if you can determine the direction of the light instead of trying to measure tiny propagation time differences. Two cameras that look for the location of the beacon in theory would be good enough.

• And using differential measures of incident light? – clabacchio Mar 4 '12 at 14:45

If you modulate the LED with a pure tone, at say 100 MHz, it is in principle possible to measure the position by comparing the phase of the signal received at each of the sensors.

One difficulty will be that that the signal is travelling at light speed, 3x10^8 m/s, so a phase measurement of even a 100 MHz signal gives a distance measurement of 3 m per cycle. If you want 1 cm (not too good for a mouse) position accuracy, you need a phase measurement accuracy of about 1 degree (not as easy as it sounds). If you want 1 mm accuracy (more reasonable for a mouse), you'll either need 1 GHz modulation (not likely with an LED) or 0.1 degree phase measurements (something in the province of precision metrology companies like Renishaw).

But let's say you can do this. Then, you won't know the absolute distance from any sensor to the mouse, but you'll know the difference between the distances between the mouse and any two sensors. So you would have two independent measured values, which I'll call $m_1$ and $m_2$, with

$m_1 = d_2-d_1$

and

$m_2 = d_2 - d_1$

where $d_n$ is the distance from the mouse to the n'th sensor.

If $(x_m, y_m)$ are the coordinates of the mouse, you also have

$d_n = \sqrt[]{(x_m - x_n)^2 - (y_m - y_n)^2}$

for each of the 3 sensors.

So you have 5 unknowns ($d_1$, $d_2$, $d_3$, $x_m$, and $y_m$) and 5 equations. Working out the algebra to solve those equations is something you'll have to do for yourself, though.

• If each LED emits at the same phase and the receiver mixes them, the phase difference will the beat frequency and proportional to relative propagation times (within a half-wavelength, at least). I forget the term -- the reverse of a phased array or beam steering. – tyblu Mar 5 '12 at 3:09
• @tyblu, as I understand his setup, he has one LED and 3 receivers. But you are probably right -- there is some clever way to combine the signals to get a more convenient signal for measuring the distance. – The Photon Mar 5 '12 at 5:13
• ... An I & Q demodulator followed by an arctan calculation may be involved ... – The Photon Mar 5 '12 at 5:17