Ultrasound Sensor: 2D Tracking With Arduino




About: I love making and flying RC planes.

Ultrasound ranging is a complicated task that made easy by the readily available module for Arduino. To detect or measure the distance it transmits the signal to the target and target reflects that back. Arduino measure time is taken for complete travel. As the speed of sound is known the distance in between module and target can be calculated easily.

Typically this sensor is used to just measure the distance from target here I am trying you get exact location/coordinate of the target.

I have used HC-SR04 for the purpose. Two of this sensor would be required for the purpose.

I tried to explain similar thing on below video.

Step 1: Calibrating the Sensor

To check the accuracy of this sensor I placed a target in front of it and measured the distance by using the ultrasound sensor and also by ruler scale. Measurement by ultrasound sensor is strength forward. Follow this article if for details if required.

from the above plot, it is very clear that output from the sensor is fairly linear. Slop is also almost one (as expected) and standard deviation of the error is around 9mm. which is a mostly static error. As I was measuring all distances from the extreme end of the sensor, while Arduino measures it from the transmitting and sensing element.

Step 2: Measurement for 2D Coordinate: Concept

In the previous case, we were measuring only one distance from the target that gives a circle of that measured radius. the object can be anywhere on the circumference of the circle. But the sensor operates only on the cone shape area so the possibility is reduced to an arc (from a circle).

If we add one more sensor aside the first sensor, the intersection of both of these sensors will give the exact location of the target.

As shown in the 4th figure, both sensor has an operating cone, the area where both of the cones intersects, the exact location can be calculated.

if the object is in the area which covered by only one cone than only range can be calculated. and obviously, we will get no idea about an object if it is outside of these cones.

Step 3: Measurement for 2D Coordinate: Calculation

By measuring distance by two sensors a triangle will be created. in which one angle is the target and rests two angles are sensors. length of all sides of this triangle is known.

Triangle is completely constrained and any required data can be calculated by applying basic geometry. to measure coordinate od the target cosine rule is applied from which angle from one of the sensor can be calculated which further can be converted to Cartesian coordinate (or polar coordinate with a required reference point).

Attached Image shows formula to calculate location.

Step 4: Measurement for 2D Coordinate: Setup

Setup is very simple, as discussed before it required at least two of these ultrasound sensors. I have attached it on the breadboard. That distance between these modules needs to be measured. this distance needs to measure from left extream of one sensor to left of another sensor or vice versa. below point need to be considered while selecting separation distance between the sensor.

  • -If the target is closer then both of these sensors need to be slightly closer, such that the cone of these sensor intersects at close distance.
  • The lower separation will lead to lower accuracy (especially at the high range) and higher separation distance will lead to better accuracy.
  • An angle of sensor facing can be changed as per requirement to intersect cones of the sensor.

Woking of Code:

working of code will follow below steps:

  • Measure range of sensor 1,
  • Measure range of sensor 2,
  • solve the coordinate.

Code is available at below link:

Once the system is set up it can be tested for the various target for accuracy. refer video from 2:28 onward:

Step 5: Summary and Possiblity:

As shown in the previous video this sensor is having relatively poor resolution in the lateral direction. which can be enhanced by-

  • Taking multiple samples and averaging the results and/or
  • multiple sensors for measurement such that a higher number of distance details are available to get the exact location.

This method can be extended to 3D by adding the third sensor out of the plan.



    • Trash to Treasure

      Trash to Treasure
    • Tape Contest

      Tape Contest
    • Arduino Contest 2019

      Arduino Contest 2019

    7 Discussions


    Question 3 months ago

    I thought of using two ultrasonic sensors, as you have done in this Instructable. Congradulations. I had a three pin Ultrasonic Sensor, and It took a while before a member here, showed me the correct code; how to make it function. Finally back to ultrasonic sensors and have 4 of them. I want to recreate what you have done in this instructable, but do no want to get caught up in learning how to code graphs in Processing, as to save time. I'm assuming you are using Processing to connect the Serial information from Arduino to make the graph. Can you post your Processing sketches? I'm new to Processing but have gotten the "Meter Library" to work and connect to the Arduino's serial output. Now I am wondering perhaps it is the Arduino "Serial plotter" that you are using? This video, was a little low in volume, but your second one I could hear good...thanks

    1 answer

    Answer 3 months ago

    Hi .. i am not using processing for plot. It is just Arduino serial plotter.


    4 months ago on Step 3

    The triggering of the sensor is not at the edge of the cone. It will be at the place where the returning energy is great enough to trigger the sensor input. Also, the timing of the two pulses will have to allow for the interference from the other sensor to not be allow to create false triggering by the other sensor. As an improvement, another sensor can be added to measure a know distance in order to remove any changes in properties of air as temperature and humidity change. Other than that, it look like fun.

    2 replies

    Reply 4 months ago

    As correctly explained by notoriouscarl, both measurement are saperated by few milliseconds of time duration.


    Reply 4 months ago

    the sensors are not being triggered at the exact same time, so there should be no interfence.


    4 months ago

    Could this be used with servos to build an airsoft sentry robot on a tripod for instance?

    1 reply

    Reply 4 months ago

    yes, but accuracy is not sufficient,
    curretly i am working on accurate method with make use of 3 or more of these sensor.
    that may be helpful to you.