An Approach for Precise Distance Measuring using Ultrasonic

: Ultrasonic sensors are commonly used as an affordable way to measure distance


Introduction
Among physical properties measurements, measurement of distance is often most important.Distance measurement is essential for many applications, including autonomous robots, vehicle parking systems, production facilities, fluid level measurement and many others.
There are many non-contact sensors currently available to measure distance: laser sensor, infrared sensor and ultrasonic sensors.Among them, the ultrasonic rangefinder sensors provide low-cost solutions and are easy to use.There are two main concepts in distance measuring with ultrasonic range sensors: using either the pulse-echo method or the continuous wave method.[1] Distance measuring with the continuous wave method requires more expensive equipment.
In order to improve the accuracy of ultrasonic measurement sensors, additional equipment and methods are needed, such as a Kalman filter [1], Neural Network [2], and probability theory [3].
In a competitive market environment, companies seek to optimize products and find cost saving solutions, such as raising the quality of low-cost sensors without increasing the production cost.A few affordable ultrasonic measurement solutions that increase accuracy up to centimeter level are available [4,5].The main goal of research is to increase accuracy up to millimeter level, often using cost-effective sensors based on the Time-Of-Flight (TOF) threshold detection approach.

Time of Flight Measurement Method with Threshold Detection
TOF is the time taken by an ultrasonic wave to hit an obstacle and return.Ultrasonic distance measurement with the TOF method is based on the following physical parameters: speed of sound in the air; environmental factors; and time of detection of the reflecting wave.Equation (1) illustrates the relationship between these parameters: . 2 Where D is a distance to be measured, S V is the speed of the sound.T is the Time- Of-Flight (TOF).Speed of the sound ( S V ) is the key parameter in Ultrasonic distance measurement and is sensitive to environmental factors such as humidity and temperature.
331.2 ( 0.6) Equation ( 2) explains the change of sound speed due to temperature.C is temperature in Celsius.Humidity impact is usually negligible in practice, but temperature must be taken into consideration to measure the distance up to millimeter level.If the temperature changes about 5 Celsius, the distance changes about 3 mm in 1000 microsecond (the speed of sound is 342.3 m/s in 20 Celsius and sound distance taken is about 343.2 mm in 1000 microseconds).
Since measuring temperature accurately is not a difficult task, measuring the TOF time accurately is the critical measurement to determine distance using ultrasonic methods.
In the threshold method, TOF time is measured as described in Figure 1.The first graphic shows a square wave signal from a pulse generator.The second graphic is TOF time and the third graphic illustrates the fluctuation in echo detector.

Test Setup.
In the test setup 40 kHz ultrasonic sensor module is used.It has two transducers.(Pulse Generator and Echo Detector).For temperature measurement analog sensor is used that it guarantees 0.5 Celsius accuracy as it is mentioned in the datasheet.Atmega328P microcontroller is utilized to execute ultrasonic sensor and temperature sensor.The system is monitored by PC using MATLAB.
Internal 16-bit timer with 16MHz clock frequency is used for TOF duration estimation.Prescaler value of the timer is set to 8. Therefore, it operates at 2MHz frequency which provides 0.5 microseconds (0.01716 mm at 20 Celsius) resolution.It is accurate enough for the desired measuring.
As an obstacle 25cm × 40cm plate is used and reference measuring is established by ruler which has the accuracy of millimeter level as shown in Figure 3.The ultrasonic sensor is placed 10 cm above the surface and ruler.Devices are placed on the rail system for precise sampling and testing.The length of the rail system is 50 cm.

Analysis of The Ultrasonic Sensor Module
The first analysis used the testing sensors without applying any improvement method.This analysis allows determination of the sensor module characteristic.Distance was measured 100 times up to 500 mm and changes in the measurement were observed.
The measurement results show fluctuations up to 8-mm as shown in Figures 2 and 3.This is satisfactory performance, if the accuracy needed is at the centimeter level.In order to measure up to millimeter level, it is necessary to increase accuracy.
It is necessary to calibrate the sensor because the minimum measurement is always slightly more than the actual distance.In order to determine temperature accurately, the temperature has been measured 100 times and an average is taken.Several distance measurement results (100 measurements in each distance) are shown in Figures 2 and 3.
Sensor performance is not sufficient for millimetric measurements, as noted in previous studies on ultrasonic sensors, which show fluctuation in measurements [1,3,8,9].The results obtained using only one measurement (max value is chosen to find the max value of the error) are shown in Figure 4.

Figure 4.
If sample data is taken in sufficient quantity, all distributions approximately resemble a Gaussian distribution, so that the mean of the sample data gives an accurate result.There are studies on ultrasonic sensor improvement using Gauss distributions [3,5,10].Most often, it is required to take 100 samples in order to obtain sufficient accuracy in mentioned studies.Increasing the number of samples improves the accuracy of the measurement, but taking too many samples (much more than 100 samples) increases the measurement time greatly, and not usefully.Therefore, 100 samples are taken using the sensor module and the results are examined.
Figures 5 and 6 shows the measurement results obtained by averaging 100 samples.Measurements have been taken between 100 mm and 500 mm with 1-cm intervals.Measurements using mean value increase the accuracy.The maximum error value decreased from 13-mm to 8-mm.Moreover, the Sum of Squared Error (SSE) decreases from 3010 mm 2 to 1135 mm 2 .In addition to this, the results are not on a straight line, as seen in Figure 6.The measurement result which is obtained using mean value is not sufficient enough to provide 1-mm accuracy.For this reason, additional techniques are necessary in order to achieve the desired precision.Increasing the sample size might increase accuracy but it is not efficient to increase sample size up to 200, 300 or more samples to get more accuracy.If the curve is not what it is expected, using curve fitting techniques to fit measurements to the curve can help to increase sensitivity.For example, Least Square fitting, Piecewise Least Square fitting and Vandermonde data fitting approaches are preferred for increasing accuracy.Least Squares Method (LSM) is the most suitable approach for error reduction, and a first order equation is chosen to apply the LSM.However, the nonlinearity of the curve obtained from the measurement results causes worries about providing 1 mm accuracy after LSM method has been applied.For this reason, the piecewise LSM and Van der Monde methods have been applied in measurements to achieve more accurate results.As seen in the Figure 8, LSM has reduced the error rate slightly.However, the measurements have still an unacceptable error rate.The LSM method finds the optimal first order equation parameter using sample data but the few sample points shown in Figure 7 below are not exactly over the polynomial line.Errors results from mentioned sample points which are not over the fitting line.The LSM method decreases the errors but does not sufficiently minimize them in this study.Therefore, piecewise LSM (PLSM) method has been applied to the sample data in order to decrease the error values much more than the LSM method.
As shown in Figure 9, the PLSM method has reduced the error value much more than other methods and reduces the maximum error rate from 5-mm to 2-mm.SSE decreases from 1135 to 25.8 Measurement errors have then decreased 2 mm.In addition, 80% of error values lie in the 1 mm range.The measurement results are encouraging, moreover error rates might decrease with additional work, and these results have been obtained using sample data.For this reason, real-time testing is necessary to demonstrate the true performance of the PLSM.

Figure 9.
The last curve fitting approach is the Vandermonde Method (VM).The VM method is expected to perform well because an nth order polynomial function is used to fit the curve.As shown in Figure 10, the VM method shows satisfying performance.The maximum error value does not exceed 1.5 mm and just like LSM, real-time tests are necessary to show the real performance of the VM.Therefore, the PLSM and VM methods have been tested in real time.The specified distances have been measured repeatedly to determine whether the method is stable or not.
When the measurements have been repeated, the error rate is mostly under 2 mm in the PLSM method and the VM method, but results are variable.Variable results are unacceptable.In order to increase sensitivity, it is necessary to search for other ways to obtain more accurate results without increasing the number of samples.

Smart Filter for Threshold Detection Technique
The measurement results above have not been satisfactory.For this reason, the sample was analyzed again, more thoroughly, to increase accuracy without increasing the number of samples.In the Smart Filter approach, detected signals are grouped and examined.The correct measurement time is selected by using previous characteristics of the sensor.
After the Smart Filter True Measurement detection algorithm has been applied, test results and graphs are: In Figure 11 it is seen that the error rate never exceeds 1 mm.It is mostly 0.4 mm below.The results satisfy the intended sensitivity and accuracy value.At the same time, the measurement results are much better than the datasheet results at the distances targeted.Real time test results show the same accuracy.As a result, after filtering, the accuracy of measurements has been increased at a high level.Moreover, measurement results are sustainable.

Conclusion
This research proposes that a highly accurate distance measurement can be achieved using a low cost sensor.The raw data from an ultrasonic sensor that measures distance by a threshold method has been examined.Measurement values were modified and compared using the Least Squares Method, the Vandermonde Method, and Smart Filter True Measurement method.The Least Squares Method and the Vandermonde Method increase the accuracy of the sensor module, up to 1 mm, but not to the desired level.Using the Smart Filter True Measurement detection algorithm, the accuracy of the ultrasonic sensor has been increased beyond the specifications of the sensor.In order to achieve 1 mm accuracy and better, the ambient temperature has to be continuously measured in real time.

First, a test
setup is assembled and аa low cosrt sensor module is analyzed on it.Several numerical methods are then applied to the sensor data to improve accuracy.Each result is shown and discussed.At the end, the Smart Filter Signal Detection algorithm is explained and the test results are shown.Citation: Aliew, F. An Approach for Precise Distance Measuring using Ultrasonic Sensors.Eng.Proc.2022, 4, x. https://doi.org/10.3390/xxxxxPublished: date Publisher's Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.Copyright: © 2022 by the authors.Submitted for possible open access publication under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).