Dual Sensor Echo Locator

12,329

158

16

About: 55+ years in electronics, computers, and teaching ... now retired.

Intro: Dual Sensor Echo Locator

This instructable explains how to pinpoint the location of an object using an Arduino, two ultrasonic sensors, and Heron’s formula for triangles. There are no moving parts.

Heron’s formula allows you to calculate the area of any triangle for which all sides are known. Once you know the area of a triangle, you are then able to calculate the position of a single object (relative to a known baseline) using trigonometry and Pythagoras.

The accuracy is excellent. Large detection areas are possible using commonly available HC-SR04, or HY-SRF05, ultrasonic sensors.

Construction is simple ... all you require is a sharp knife, two drills, a soldering iron, and a wood saw.

Images

  • The video clip shows the unit in operation.
  • Photo 1 shows the assembled “echo locator”
  • Photo 2 shows a typical display. The object is the red (flashing) dot.
  • Photo 3 shows the video test setup. It was necessary to position the two HY-SRF05 ultrasonic sensors 50cm below the baseline to completely “illuminate” the detection area with sound.

Step 1: Wiring Diagram

Photo 1 shows the wiring diagram for the “dual sensor echo locator”.

Sensor B is rendered “passive” by placing several layers of masking tape over the transmit (T) transducer. This tape blocks the ultrasonic sound that would otherwise be emitted.

Step 2: Parts List

As shown in photo1, very few parts are required to complete this project:

The following parts were obtained from https://www.aliexpress.com/ :

  • 1 only Arduino Uno R3 complete with USB cable
  • 2 only HY-SRF05, or HC-SR04, ultrasonic transducers

The following parts were obtained locally:

  • 1 only male arduino header strip
  • 2 only female arduino header strips
  • 2 only pieces of scrap aluminium
  • 2 only small pieces of wood
  • 2 only small screws
  • 3 only cable ties
  • 4 only lengths plastic coated wire (assorted colors) [1]

Note

[1]

The total length of each wire should equal the desired distance between the sensors plus a small amount for soldering. The wires are then twisted together to form a cable.

Step 3: Theory

Beam Patterns

Photo 1 shows the overlapped beam patterns for transducer A and transducer B.

Sensor A will receive an echo from any object in the “red area”.

Sensor B will only receive an echo if the object is in the “mauve area”. Outside this area it is not possible determine the coordinate of a object. [1]

Large “mauve” detection areas are possible if the sensors are widely spaced.

Calculations

With reference to photo 2:

The area of any triangle may be calculated from the formula:

area=base*height/2 ............................................................................... (1)

Rearranging equation (1) gives us the height (Y-coordinate):

height=area*2/base ............................................................................... (2)

So far so good ... but how do we calculate the area?

The answer is to space two ultrasonic transducers a known distance apart (baseline) and measure the distance each sensor is from the object using ultrasound.

Photo 2 shows how this is possible.

Transducer A sends a pulse which bounces off the object in all directions. This pulse is heard by both transducer A and transducer B. No pulse is sent from transducer B ... it only listens.

The return path to transducer A is shown in red. When divided by two and the speed of sound is factored in, we can calculate distance “d1” from the formula: [2]

d1 (cm) = time (microseconds)/59 ......................................................(3)

The path to transducer B is shown in blue. If we subtract distance “d1” from this path length we get distance “d2”. The formula for calculating “d2” is: [3]

d2 (cm) = time(microseconds/29.5 – d1 ............................................ (4)

We now have the length of all three sides of the triangle ABC ... enter “Heron”

Heron’s formula

Heron’s formula uses something called a “semi-perimeter” in which you add each of the three sides of a triangle and divide the result by two:

s=(a+b+c)/2 ........................................................................................ (5)

The area may now be calculated using the following formula:

area=sqrt(s*(s-a)*(s-b)*(s-c)) ............................................................. (6)

Once we know the area we can calculate the height (Y-coordinate) from equation (2) above.

Pythagoras

The X-coordinate may now be calculated by dropping a perpendicular from the triangle vertex to the baseline to create a right-angled triangle. The X-coordinate may now be calculated using Pythagoras:

c1 = sqrt(b2 - h2) ................................................................................ (7)

Notes

[1]

The target area can be completely “illuminated” with sound by positioning the sensors below the baseline.

[2]

The value of 59 for the constant is derived as follows:

The speed of sound is approximately 340m/S which is 0.034cm/uS (centimeters/microsceond).

The reciprocal of 0.034cm/uS is 29.412uS/cm which, when multiplied by 2 to allow for the return path, equals 58.824 or 59 when rounded.

This value may be adjusted up/down to account for air temperature, humidity, and pressure.

[3]

The value of 29.5 for the constant is derived as follows:

There is no return path so we use 29.5 which is half the value used in [2] above.

Step 4: Construction

Mounting brackets

Two mounting brackets were made from 20 gauge aluminium sheet using the method described in my instructable https://www.instructables.com/id/How-to-Cut-Fold-...

The dimensions for my brackets are shown in photo 1.

The two holes marked “baseline” are for attaching a string to each sensor. Simply tie the string off at the required spacing for easy setup.

Sensor sockets

The sensor sockets (photo 2) have been fashioned from standard Arduino header sockets.

All unwanted pins have been pulled out and a 3mm hole drilled through the plastic.

When soldering the connections take care not to short the wires to the aluminium bracket.

Strain reliefs

A small piece of heat-shrink tubing at each end of the cable prevents the wires from unravelling.

Cable ties have been used to prevent unwanted cable movement.

Step 5: Software Installation

Install the following code in this order:

Arduino IDE

Download and install the Arduino IDE (integrated development environement) from https://www.arduino.cc/en/main/software if not already installed.

Processing 3

Download and install Processing 3 from https://processing.org/download/

Arduino Sketch

Copy the contents of the attached file, “dual_sensor _echo_locator.ino”, into an Arduino “sketch”, save, then upload it to your Arduino Uno R3.

Close the Ardino IDE but leave the USB cable connected.

Processing Sketch

Copy the contents of the attached file, “dual_sensor_echo_locator.pde” into a Processing “Sketch”.

Now click the top-left “Run” button ... a graphics screen should appear on your screen.

Step 6: Testing

Connect the Arduino USB cable to your PC the

Run “dual_sensor_echo_locator.pde” by clicking the “top-left” run button on your Processing 3 IDE (integrated development environment).

Numbers, separated by a comma should start streaming down your screen as shown in photo1.

Error message at startup

You may get an error message at startup.

If so change the [0] in line 88 of photo 1 to match the number associated with your “COM” port.

Several “COM” ports may be listed depending on your system. One of the numbers will work.

In photo 1 the number [0] is associated with my “COM4”.

Positioning your sensors

Space your sensors 100cm apart with the object 100cm in front.

Rotate both sensors slowly towards the diagonally opposite corner of an imaginary 1 meter square.

As you rotate the sensors, you will find a position where a flashing red dot appears on the graphics display.

Additional data will also appear (photo 2) once the sensors have located your object:

  • distance1
  • distance2
  • baseline
  • offset
  • semi-perimeter
  • area
  • X coordinate
  • Y coordinate

Step 7: Display

The display has been written using Processing 3 ... a 100cm baseline is shown.

Changing the baseline

Let’s change our baseline from 100cm to 200cm:

Change “float Baseline = 100;” in the Processing header to read “float Baseline = 200;”

Change the labels “50” and “100” in the Processing “draw_grid()” routine to read “100” and “200”.

Changing the offset

Larger target areas may be monitored if we position the sensors below the baseline.

A variable “Offset” in the Processing header must be altered if you choose to do this.

  Click here   to view my other instructables.

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Audio Contest 2018

      Audio Contest 2018
    • Furniture Contest 2018

      Furniture Contest 2018

    16 Discussions

    0
    None
    mach1950

    2 months ago

    This is a great "ible" lingib. I love the idea of using cheap HC-SR04's even though you only need one transmitter. So effective and cheap and easy but so intriguing. I'm 68 and it forces me to re-engage with my old trig books. Thanks for sharing.

    1 reply
    0
    None
    lingibmach1950

    Reply 2 months ago

    You are welcome ... thanks for commenting :)

    0
    None
    judas79

    2 months ago

    Very cool project. Is there a particular reason you are triggering both modules, in the .pde, even though the "B" trigger on the module is blocked with a covering?

    1 reply
    0
    None
    lingibjudas79

    Reply 2 months ago

    The time interval for sensor A is from when Echo line A goes high until Echo line A goes low.

    Similarly the time interval for sensor B is from when Echo line B goes high until Echo line B goes low.

    The Echo lines only go high when the sensors receive a trigger pulse. For the system to work we must trigger BOTH sensors together.

    The ping from sensor B is not heard by sensor A as the transmit pulse is blocked by the addition of masking tape over the transmit sensor B.

    If you examine the Arduino code you will see that I quickly trigger each sensor in turn then wait until both Echo lines have gone high.

    The reason for waiting is that there is a considerable delay after a Trig pulse before the Echo line go high ... see the waveforms in my article https://www.instructables.com/id/Enhanced-Ultrason...

    The point at which both Echo lines go high is defined as my start point ... the slight time difference between Trig pulses is not significant.

    This time difference, however, may be eliminated by writing a "pattern" to the output port. An example of this technique may be found in my instructable https://www.instructables.com/id/CoreXY-CNC-Plotte...

    0
    None
    lingibRaphango

    Reply 2 months ago

    Thank you for commenting :)

    0
    None
    stanleyella

    Question 2 months ago

    Why ping both srf04? I don't understand c. How can you pulse in both sensors at the same time?

    1 more answer
    0
    None
    lingibstanleyella

    Answer 2 months ago

    The time interval for sensor A is from when Echo line A goes high until Echo line A goes low.

    Similarly the time interval for sensor B is from when Echo line B goes high until Echo line B goes low.

    The Echo lines only go high when the sensors receive a trigger pulse. For the system to work we must trigger BOTH sensors together.

    The ping from sensor B is not heard by sensor A as the transmit pulse is blocked by the addition of masking tape over the transmit sensor B.

    If you examine the Arduino code you will see that I quickly trigger each sensor in turn then wait until both Echo lines have gone high.

    The reason for waiting is that there is a considerable delay after a Trig pulse before the Echo line go high ... see the waveforms in my article https://www.instructables.com/id/Enhanced-Ultrason...

    The point at which both Echo lines go high is defined as my start point ... the slight time difference between Trig pulses is not significant.

    This time difference, however, may be eliminated by writing a "pattern" to the output port. An example of this technique may be found in my instructable https://www.instructables.com/id/CoreXY-CNC-Plotte...

    0
    None
    UncleEd

    2 months ago

    Thank you for making me think. Now I need to get a pencil and calculator.

    1 reply
    0
    None
    lingibUncleEd

    Reply 2 months ago

    Sounds like you have a project in mind! Thanks for commenting :)

    0
    None
    lingibJoseA124

    Reply 2 months ago

    Glad you like the idea ... thanks for commenting :)

    Superb....

    I have one doubt... ultrasonic only measure in straight. That's why we use a servo motor to for make a radar Display. Then how its measure object left or right to the sensors.

    1 reply

    Your concept of "ultrasonic only measure in straight" (lines) assumes that a single transmit/receive sensor is pointing directly at the target. This project has one transmit sensor and two receive sensors.

    The beam-width of an ultrasonic transmitter is approximately 30 degrees ... think of this as, say, 100 individual beams each at a slightly different angle to the one next to it.

    In physics the "angle-of-incidence" to a "perpendicular" equals the "angle-of-reflection" on the opposite side.

    Ultrasonic "radar-like" displays using a servo and a single receive sensor only see the the beam that gets reflected directly back (along the perpendicular)... the other 99 beams get lost.

    This detector uses the same principle. Sensor A sees the beam that gets reflected directly back ... the other 99 beams each get reflected at slightly different angles.

    Sensor B sees one of these 99 reflected beams ... the other 98 beams get lost.

    Photo 2 in Step 3 shows diagrams of the two beam paths and the equations for determining the X and Y coordinates relative to sensor A

    1
    None
    BrownDogGadgets

    2 months ago

    Holy wow! That is pretty awesome!

    We just need an alien statue to recreate a classic scene from the movie "Aliens".

    "Game over man! Game over!"

    1 reply