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 Possibility:
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
Read more: Ultrasound Sensor: 2D Tracking With Arduino