Dual Sensor Echo Locator

20,602

178

33

Introduction: Dual Sensor Echo Locator

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

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.

2 People Made This Project!

Recommendations

  • Furniture Contest

    Furniture Contest
  • Explore Science Challenge

    Explore Science Challenge
  • Barbecue Speed Challenge

    Barbecue Speed Challenge

33 Comments

0
Vladimir LL
Vladimir LL

4 months ago

Hello !!!
You make a 3D radar. I want a three-dimensional picture of the terrain. When can you do it?

0
ryan eastwood
ryan eastwood

Question 1 year ago

I have got this full working, how ever, I am wondering how the Processing sketch obtain the time variables from the code running on the arduino. How does it know what it is receiving over the serial communications?

0
lingib
lingib

Answer 4 months ago

Time variables are not used.

The Arduino sends the distance data (Arduino code line 101) to the Processing sketch in comma-delimited format. Each line of data is terminated with a line-feed.

The serialEvent() function in the Processing algorithm (starting at code line 107) detects this line-feed, extracts the distance information, validates it, then displays the objects position.

The Processing validation process rejects meaningless data.

0
ryan eastwood
ryan eastwood

Question 1 year ago

I really need help here. I have everything soldered and setup yet it only shows the object in certain spots not the whole area. Also it shows it too far away but if I alter the offset varible it doesnt even show up. This is for a shool project so please any help wuld be aprreciated.

0
lingib
lingib

Answer 1 year ago

The project should work if you have used the the same components. The fact that you are getting echos indictates you have everything working :)

Some reasons why you might not be able to detect your object everywhere

(1) the object is lower than the transducer and the ultrsonic beam is passing over the top. Try using a large object such as a saucepan while you find the optimum location and angles for the transducers. Once you have this working reduce the target size .

(2) some transducers have a narrower beam-width in which case you will have to position them further away from your target area. Visualize two 30 degree cones coming from each transducer ... you will only be able to detect objects where these two "cones" overlap.

The photo of my setup shows my transducers approximately 50 cm below each edge of my 1 meter square target area with each transducer pointing towards the diagonally opposite corner. I have also stacked two baked-bean cans on top of each other to prevent the beam passing over the top.

0
ryan eastwood
ryan eastwood

Reply 1 year ago

Yet again, it was my fault. I was not taking in to account the offset. I set it up on my dining table and it works fine now. Very accurate! Thank you for your help and the assistance with this amazing project. You always get back to me very quick. Thanks!

0
ryan eastwood
ryan eastwood

Question 1 year ago

Hi, I really am struggling here. When I upload the code to the board using the Arduino sketch I get the error "import does not name a type". Can you please help me? I have installed processing 3.

0
lingib
lingib

Answer 1 year ago

Thank you for your interest in my project :)

Have just downloaded the ino code and it compiles

The method I used was to download the ino file and copy the contents into an empty Arduino sketch using the Notepad++ text editor. I then clicked compile and saved it using the name the arduino IDE suggested. The code then compiled.

The reason the Ardino does a save first is that the ino code must reside in a folder that has the same name. This may account for your error message ?

0
ryan eastwood
ryan eastwood

Reply 1 year ago

It was my fault, sorry, I was running the processing code in the Arduino IDE it works fine now thanks.

0
lingib
lingib

Reply 1 year ago

Glad you have solved the problem ... thanks for letting me know :)

0
zorhayat333
zorhayat333

2 years ago

I need help. My project is 50 cm and I use the codes and make changes, but doesn't mark in template and x value is true while y value is half of x

0
lingib
lingib

Reply 2 years ago

The following comments assume that:
- the project, as published, works
- that you have successfully relabeled the grid axes 0, 25, 50
-----------
Problem 1:
-----------
There are two possible reasons why something may not display. If either of these events occur the dot is shifted out of the display area :
- an invalid reading was obtained
- a valid distance was obtained but it is outside of the display area.

The validation code for checking this is in the Serial Event routine which (to my horror) contains an unfortunate coding error which may be causing your problem.

Change the following code lines:
// ----- gather Heron variables
//float d = c*1.414; //display diagonal (square)
float d = sqrt(150*150 + 100*100); //diagonal (display + offset)

To read:
// ----- gather Heron variables
//float d = c*1.414; //display diagonal (square)
float d = sqrt((Baseline+Offset)*(Baseline+Offset) + (Baseline*Baseline));

It would appear that I have done the sums in my head rather than applying a formula when writing that test line :(
-----------
Problem 2:
-----------
The reason that your dots, when you do get a reading, do not display at the correct height may also be code related.

Try changing the following code lines:
// ----- draw the object
translate(X/100*width, -(Y-Offset)/100*height);

To read:
// ----- draw the object
translate(X/Baseline*width, -(Y-Offset)/Baseline*height);

The above code plots each of the XY coordinates as a percentage of the scaled display widths and heights.

Again it would appear that I have done the sums in my head rather than applying a formula :(

Message me if this solves your problem and I will update the code.

0
ScottB427
ScottB427

2 years ago

can this track more than one object at a time? and small diameter objects?
Im trying to make something that would see the position of arrows in a target and feed that information into a program as X and Y positions.

0
percramer
percramer

2 years ago

Great idea! How accurate do you think this could be?

0
lingib
lingib

Reply 2 years ago

Assuming that the "system" has been calibrated for temperature, humidity, and atmospheric pressure, the accuracy should approximate that of your sensors.

Automatic calibration is possible using a third transducer (in the same environment) spaced a known distance from a separate reflector to calculate the correct value to use in place of the constants 59 and 29.5

Without calibration the accuracy is within 1 or 2 centimeters depending on the shape of the object.

0
mach1950
mach1950

2 years 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.

0
lingib
lingib

Reply 2 years ago

You are welcome ... thanks for commenting :)

0
judas79
judas79

2 years 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?