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

This tutorial is divided into two-part. The first part explains the calibration of an ultrasound sensor and 2d tracking with 2 sensors. while the second part discusses on accurate 2d tracking with multiple ultrasound sensors.

A. Ultrasound sensor calibration and 2d trackingUltrasound sensor or sonar sensors used to measure just the distance from target here I am trying you get the exact location/coordinate of the target. I have used HC-SR04 for the purpose.

I tried to explain a similar thing to the below video.

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.

from the above plot, it is very clear that the output from the sensor is fairly linear. Slop is also almost one (as expected) and the 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.

Measurement for 2D Coordinate: ConceptIn 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 from 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 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.

Measurement for 2D Coordinate: CalculationBy measuring distance by two sensors a triangle will be created. in which one angle is the target and rests two angles are sensors. The 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 sensors can be calculated which further can be converted to Cartesian coordinate (or polar coordinate with a required reference point).

The attached image shows the formula to calculate the location.

Measurement for 2D Coordinate: SetupSetup is very simple, as discussed before it required at least two of these ultrasound sensors. I have attached it to the breadboard. The distance between these modules needs to be measured. this distance needs to measure from left extreme 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 sensors 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 the requirement to intersect cones of the sensor.

Woking of Code:

working of code will follow the 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 to the previously attached video for a demonstration.

B. Ultrasound sensor calibration and 2d trackingThe above method also explained in the below video:

Working:This method makes use of multiple sensors. Higher the number of the sensor can be useful for more accurate measurement. Let's take an example of a setup with 4 sensors (as I am using for the tutorial). So after finishing measurement, we will have the distance to target from all of this sensor.

To calculate the position of the target in the lateral direction we need two measurements to complete a triangle and locate the target position. As we have 4 sensors we will have 6 combinations (4C2) of pairs. These pairs can be seen from the above images.

Once the pair is decided we have to calculate the target location for every combination of the sensor pair. In the end, there will be six measurements for the target location. By using all these six values relatively accurate measurements can be made. now all these data are fused with weightage as per accuracy. if we consider a triangle than the higher distance between the sensor will lead more accurate. So higher weightage is given to the pair having a sensor far from each other.

This method is still not very accurate as we are not making the measurement from the single point target. as the target is a planner object sensor that will measure the distance from the nearest point.

Preparing Setup:

This setup is similar to the previous tutorial on 2d tracking with two sensors. Ground supply and Vcc is connected to a common line and all Tx and Rx pin are connected to one of the Arduino pins. It can be connected to any of the Arduino pins that need to be defined in code. The above image can be referred for the overall connections.

After that, all these sensors need to be mounted with a fixed distance. similar to the previous case, higher separation will lead to better accuracy and vice versa. the sensor may face in any direction for best coverage. In this case higher the number of sensors will face the target better result we can obtain.

Working of CodeThere are basically 4 functions that work to get accurate output and avoid a false reading.

1. Raw_cap(): This function will simply take data from the available sensor, sensor number can be any number, as discussed higher number will give better accuracy. another point need to consider is that in the command

```
pulseIn(Rx[i], HIGH,5000);
```

The Value 5000 need to be changed as per object placement, once we had the approx operating range we can calculate the value of time taken (in Microseconds) by the sound wave to travel through and back to the range and replace with 5000. At the completion of the function, we will end up with an array having values measured by all sensors.

2. Position_calc(): This function will take various combinations (nC2 for n number of the sensor) and will calculate the position of the target in 2D,

3. check(); This function will check every combination taken by position_calc() function is possible to form a triangle or not. If this function concludes this test negative Position_calc() will simply make entry as 0 values, this function is very avoided considering the wrong values of the sensor. This function makes use of the property that summation of the length of any two sides of the triangle is always higher than the length of the rest 3rd side of the triangle.

4. Fuse_data() The above function will take the weighted average of all measurements, weightage proportional to distance in between the pair of the sensor.

Setting Up the Code and Testing the Output:

Values like the number of sensors and sizes of arrays as commented in code need to be updated. Another important parameter is the distance between these sensor need to be defined. Here the distance from the leftmost sensor to all sensors is added in an array named Position [ ].

Once everything is set up target can be placed in front of the sensors and check the output from the sensor.

## Comments