I have done some tests using three modified hc-sr04 in order to check if it is possible synchronize the receivers accurately enough to determine if an object is to the left, near center, or to the right using time differences.
Using only one hc-sr04 as active transmitter/receiver and two acting as receivers, it should be possible to calculate the position of one or more objects by triangulation.
The two receivers are placed 16 cm apart and angled toward the center with a common focus about 20 - 25 centimeters in front. The T/R is mounted vertically to have both the transmitter and receiver at the center.
For processing the signal out of the amplifier, the onboard mcu is disabled when acting as receiver only.
To replace the onboard mcu, at2313a/at4323a are used with the Attinycore as core.
At2313a requires use of a non buffered simple hardware serial out to be able to print an int.
All the hc-sr04 are synchronized within a few microseconds, using the rising edge of the T/R echo pin to start the timer1 of the two receivers as well as the T/R using pinchangeinterrupt.
Even using a 16Mhz x-talclock divided by 8 takes more than 32 ms before the first overflow, sufficient for the distances in question.
On the two receivers, the onbord mcu has been disabled, unsoldering pin 9, threshold, and pin 10, signal in, order to avoid any interference from the mcu.
The at2313a/at4323a of the T/R is connected to the threshold and signal of the onboard mcu.
On the versions of the hc-sr04 used(versions with 2 transistors), the design flaw of the band pass filter, peak at around 12 Khz, has been modified to a peak closer to 40 Khz, resulting in a much better sensitivity.
The analog comparator, pin AIN0, is connected directly to the signal output of the hc-sr04 (was pin 10 of the onboard mcu).
Every time an echo pulse train starts, the analog comparator interrupt function checks if the interrupt time stamp should be saved, at the moment up to 4 timestamps.
The resolution of the timestamps is 1 usec when sent to the controller.
The controller, at the moment an arduino uno is used, only needs to send a trigger signal to the T/R, then wait around 30ms before collecting the data by sending a signal to the at2313a/at4323a, one at a time, in order to receive the timestamps using the software serial library.
The controller then processes the data to establish the position of one or more objects within the width of the transmitter beam.
A simple median filter is used to smooth up to 8 pings before processing the timestamps.
At the moment, only very simple tests are done.
Let us call the receiver to the right A, center B and left C.
At the moment triangulation is used in three ways, A-B, B-C, A-C.
(Arduino Playground - IntersectionOfCircles)
Before the triangulation, a test is made to determine if the distance A is less than C or B.
If that is the case, the object is to the right of the center.
Next test is to see if distance C is less than A or B, in that case the object is to the left of the center.
X-offset is used to move the resulting position in the x direction when calculating B-C.
Here are some test results, only for the first echo shown.
First with a wall/board in front:
A 1472usec: 25.82cm
B 1492usec: 26.18cm
C 1487usec: 26.09cm
Echo: 0
Point A (0.00x,0.00y), B (8.00x,0.00y), Obj (2.86x,25.67y)
Distance AB is 8.00, X-offset 0.00
Distance A to object is 25.82
Distance B to object is 26.18
Echo: 0
Point B (8.00x,0.00y), C (8.00x,0.00y), Obj (12.29x,25.82y)
Distance BC is 8.00, X-offset 8.00
Distance B to object is 26.18
Distance C to object is 26.09
Echo: 0
Point A (0.00x,0.00y), C (16.00x,0.00y), Obj (7.57x,24.69y)
Distance AC is 16.00, X-offset 0.00
Distance A to object is 25.82
Distance C to object is 26.09
A can, 5cm in diameter, is used for the next tests.
Placed near the center:
A 1114usec: 19.54cm
B 1111usec: 19.49cm
C 1133usec: 19.88cm
Echo: 0
Point A (0.00x,0.00y), B (8.00x,0.00y), Obj (4.13x,19.10y)
Distance AB is 8.00, X-offset 0.00
Distance A to object is 19.54
Distance B to object is 19.49
Echo: 0
Point A (0.00x,0.00y), C (16.00x,0.00y), Obj (7.59x,18.01y)
Distance AC is 16.00, X-offset 0.00
Distance A to object is 19.54
Distance C to object is 19.88
Near right edge:
A 1055usec: 18.51cm
B 1097usec: 19.25cm
C 1114usec: 19.54cm
Echo: 0
Point A (0.00x,0.00y), B (8.00x,0.00y), Obj (2.26x,18.37y)
Distance AB is 8.00, X-offset 0.00
Distance A to object is 18.51
Distance B to object is 19.25
Echo: 0
Point A (0.00x,0.00y), C (16.00x,0.00y), Obj (6.77x,17.23y)
Distance AC is 16.00, X-offset 0.00
Distance A to object is 18.51
Distance C to object is 19.54
Near left edge:
A 1112usec: 19.51cm
B 1092usec: 19.16cm
C 1023usec: 17.95cm
Echo: 0
Point B (8.00x,0.00y), C (8.00x,0.00y), Obj (14.81x,17.91y)
Distance BC is 8.00, X-offset 8.00
Distance B to object is 19.16
Distance C to object is 17.95
Echo: 0
Point A (0.00x,0.00y), C (16.00x,0.00y), Obj (9.83x,16.85y)
Distance AC is 16.00, X-offset 0.00
Distance A to object is 19.51
Distance C to object is 17.95
Finally, 2 cans placed left and right with the right one a little closer than the left one:
A 862usec: 15.12cm
B 1000usec: 17.54cm
C 974usec: 17.09cm
Echo: 0
Point A (0.00x,0.00y), B (8.00x,0.00y), Obj (-0.94x,15.09y)
Distance AB is 8.00, X-offset 0.00
Distance A to object is 15.12
Distance B to object is 17.54
Echo: 0
Point B (8.00x,0.00y), C (8.00x,0.00y), Obj (12.99x,16.82y)
Distance BC is 8.00, X-offset 8.00
Distance B to object is 17.54
Distance C to object is 17.09
Echo: 0
Point A (0.00x,0.00y), C (16.00x,0.00y), Obj (6.02x,13.87y)
Distance AC is 16.00, X-offset 0.00
Distance A to object is 15.12
Distance C to object is 17.09
Almost usable to avoid objects in the path.
I have searched for ways to do more accurate calculations, but so far without success.
Any suggestions?