Buletin Ilmiah Sarjana Teknik Elektro ISSN: 2685-9572
Distance Estimation on Ultrasonic Sensor Using Kalman Filter
Muhammad Haryo Setiawan 1, Alfian Ma’arif 1, Hamzah M. Marhoon2, Abdel-Nasser Sharkawy3, 4, Abdullah Çakan5
1 Department of Electrical Engineering, Universitas Ahmad Dahlan, Yogyakarta, Indonesia
2 Departemen of System Engineering, Collegee of Information Engineering, Al-Nahrain University, Jadriya, Baghdad, Iraq
3 Mechatronics Engineering, Mechanical Engineering Department, Faculty of Engineering, South Valley University, Qena 83523, Egypt
4 Mechanical Engineering Department, College of Engineering, Fahad Bin Sultan University, Tabuk 47721, Saudi Arabia
5 Konya Technical University, Konya, Turkey
ARTICLE INFORMATION | ABSTRACT | |
Article History: Submitted 16 April 2023 Revised 17 May 2023 Accepted 29 May 2023 | This research focuses on distance estimation using the Kalman Filter method in ultrasonic sensors. The study addresses the issue of accuracy levels in ultrasonic sensors and proposes the use of Kalman Filter to enhance accuracy. The Kalman Filter is comprised of two key components: prediction and update. In this research, the Kalman Filter method is implemented using Arduino Uno and the HC-SR04 ultrasonic sensor. The experimental results involve a comparison between sensor data before and after the application of the Kalman Filter. The filtering outcomes are influenced by the values assigned to the noise sensor covariance matrix (R) and process noise covariance (Q). Through experimentation, it was determined that the optimal values for R and Q are 100 and 0.01, respectively. It is important to strike a balance when selecting these values, as values that are too close may render the filtering result imperceptible, while values that are too disparate may lead to the elimination of original sensor data. In conclusion, the application of the Kalman Filter method in ultrasonic sensors enables accurate estimation and enhances sensor value accuracy by up to 7%. This research contributes to the advancement of distance estimation techniques in the field of ultrasonic sensing. | |
Keywords: Distance; Ultrasonic; Kalman Filter; Arduino | ||
Corresponding Author: Alfian Ma’arif, Department of Electrical Engineering, Universitas Ahmad Dahlan, Bantul, Yogyakarta, Indonesia. Email: alfianmaarif@ee.uad.ac.id | ||
This work is licensed under a Creative Commons Attribution-Share Alike 4.0 | ||
Document Citation: M. H. Setiawan, A. Ma’arif, H. M. Marhoon, A-.N. Sharkawy, and A. Çakan, “Distance Estimation on Ultrasonic Sensor Using Kalman Filter,” Buletin Ilmiah Sarjana Teknik Elektro, vol. 5, no. 2, pp. 210-217, 2023, DOI: 10.12928/biste.v5i2.8089. | ||
Distance measurement is a fundamental quantity that has traditionally been measured using tools such as rulers, calipers, and micrometer screws. However, in modern times, there is a wide range of advanced measuring tools available, including ultrasonic sensors [1], infrared devices [2], lasers [3], and LIDAR [4], although the latter can be costly. These modern tools typically require additional electronic components, such as microcontrollers for distance measurement and LCD displays to showcase the results. Their applications are extensive and varied, encompassing navigation for vacuum robots [5], [6], UAVs [7], [8], height measurement [9]–[11], water level monitoring [12]–[14], car parking distance indicators [15]–[17], and daily distance measurement.
Distance measurement using modern sensor, especially ultrasonic sensor has several disadvantages from external factor such as noise from other tools with high frequency, distortion among objects and the influence from animal with ultrasonic sound ability which may interfere the measurement. Hence, a method is needed to estimate the real measurement for getting more accurate.
In this research, ultrasonic sensor is used to measure the distance on object. This sensor has weaknesses since it is very sensitive toward the changes and has noise from external factor. Thus, a method is needed to overcome the weakness. In this research, Kalman Filter method [18]–[20] will be used to overcome the weakness.
Several researches that have been done using ultrasonic sensor are; the use of ultrasonic sensor which is installed in arrays to detect moving object [21], distance measurement and object detection with wide range up to 180˚ using 5-volt servo motor [22]. Another implementation of ultrasonic sensor is used in the oil tank volume monitoring system [23].
Based on the background described above, the research contribution is about application of Kalman Filter to estimate the distance which is so interesting to do. With the characteristic of ultrasonic sensor which is unstable, has a noise and a lot of implementations can be implemented, it arises challenge for the researcher to design the distance estimation system using Kalman Filter method. The first part of this research is introduction. The second part is proposed method. The third part is research method. The fourth part is result and discussion. The last part will be conclusion.
2.1. Ultrasonic Sensor
Ultrasonic sensor is based on the principle of sound wave reflection to get the distance of an object with a certain frequency. Ultrasonic waves are sound waves that have a high frequency, above 20,000 Hz (20 kHz). Ultrasonic sensors have two main components; the transmitter and the receiver which are connected to a piezoelectric crystal. An alternating voltage is applied to a metal plate to produce ultrasonic waves that are emitted into the air. If there is an object, then the ultrasonic waves will be reflected and received back by the receiver. This reflected wave produces an alternating voltage with the same frequency [24], [25]. Figure 1 shows the illustration of measurement ultrasonic sensor.
Figure 1. Illustration of measurement ultrasonic sensor
2.2. Kalman Filter
The Kalman Filter was published in 1960 by Rudolf E. Kalman, the first person who developed this algorithm. Kalman Filter is a mathematical algorithm that estimates values on data or sensors to reduce the Root-Mean-Square Error (RMSE) of the system [26]. The Kalman Filter is a reliable in the various aspects of application; it can estimate both the previous and the current data, even can predict the next data, and can make estimates in a system state where the model is unknown.
The Kalman Filter has several mathematical derivatives, such as the Standard Kalman Filter, Extended Kalman Filter [27], Unscented Kalman Filter [28], [29], and Ensemble Kalman Filter [30] The Standard Kalman Filter is the simplest filter rather than other derivatives. In this research, The Standard Kalman Filter is used to estimate the distance measurement, in which the parameter used is sufficient for noise reduction. The Kalman Filter is often carried out in two phases; prediction and update. The standard Kalman Filter mathematical equation is shown in equations (1)-(5).
Prediction:
(1) | ||
(2) |
Update:
(3) | ||
(4) | ||
(5) |
These variables state for: is the expected value,
is the transition matrix, u is the control variable,
is the control matrix,
is the variation matrix,
is the process of variation matrix,
is the measurement variable,
is the matrix measurement,
is the Kalman reinforcement,
is the variation matrix measurement,
is the current time period,
is the previous time period, and
are intermediate steps.
Equations (1) to (5) are a general model of the Kalman Filter system that can be modified according to the needs and complexity of the built system. Hence, there is a way to implement the Kalman Filter algorithm to reduce noise on sensor readings and make some adjustments according to the required conditions. Some of the adjustments made are:
In this section, adjustments are made to equation (1) by assigning a value because it has no transition value. Thus it can reduce system input variables that have no input. The adjusted equation is shown in equation (6).
(6) |
By following , then equation (2) is adjusted to be equation (7).
(7) |
In equation (3), the value , int which the sensor value to be filtered is only one sensor reading. So it can be written as equation (8).
(8) |
By following , then equation (4) can be written as equation (9).
(9) |
By following , then equation (5) can be adjusted to be equation (10).
(10) |
2.3. System Design
To make it easier in understanding the application of distance estimation using this ultrasonic sensor, please see the details of system block diagram in Figure 2 and flowchart in Figure 3.
Figure 2. System Blok Diagram
According to Figure 1, the device used in this research is Arduino UNO as a microcontroller, Ultrasonic HC-SR04 as a distance estimation sensor, LCD to display the estimated value, and a Laptop that functions for Arduino serial data communication and as a 5-volt power supply for Arduino using the USB A port. Arduino power supply is used to supply the HC-SR04 ultrasonic sensor and LCD.
Figure 3. Flowchart System
Figure 3 shows how the process of the system flow running in this research. Started by initializing sensor and parameter for estimating using Kalman Filter, then Sensor value block is the process of distance data retrieval that will be estimated by Kalman Filter. Predict Sensor value block is process that predicting sensor value using equation (6). Predict error sensor value block is the difference value between predicted value and actual value according equation (7). Updating prediction sensor value block is the process that update predicted for the next prediction using equation (8). Predicted Kalman Filter block is the process of showing estimated data into LCD. Calculate Kalman reinforcement value block is calculating Kalman gain for the input error value according equation (9). Updating error value block is the process that update error for the next calculation according equation (10).
Estimation distance testing is conducted using measurement method with ultrasonic sensor, then compared with actual measurement using a ruler. Table 1 shows the comparison testing data between ultrasonic sensor measurements and actual distances (in cm).
Table 1. Comparison table between sensor measurement and actual distances (in cm)
Actual distance | Ultrasonic Measured Distance | Ultrasonic Error (%) |
10 | 10.75 | 7.50 |
20 | 20.71 | 3.55 |
30 | 30.19 | 1.90 |
40 | 40.77 | 7.70 |
50 | 50.60 | 6.00 |
According to Table 1, ultrasonic sensor measurement value has various errors, from on 10 – 50 cm measurement distances with a difference between distances of 10 cm. By reaching 7.70% error value, it can cause measurement error. Then filtering using Kalman Filter is carried out to solve the problem, but turning parameter step is needed in this algorithm. Figure 4 are graphics that show turning parameter step R and Q in Kalman Filter algorithm.
(a) | (b) | (c) |
(d) | (e) | (f) |
(g) | ||
Figure 4. (a) R=1, Q = 0.01, (b) R = 1, Q = 0.1, (c) R =1, Q = 1, (d) R = 1, Q = 10, (e) R = 10, Q = 0.1, (f) R = 100, Q = 0.1, (g) R = 100, Q = 0.01 | ||
The results obtained from the test with blue data is raw data that wasn’t filtered with Kalman Filter and the orange color was the filtered data using Kalman Filter with differences parameter R and Q. Figure 4 reveal an interesting observation the Q parameter value surpasses the R parameter value, indicating that the distance estimation measurements in this case remain unfiltered by the Kalman Filter. However, Figures 4 showcase measurement data that has undergone filtering, although some residual noise remains present. Notably, the data exhibits superior quality compared to the test depicted in Figure 4, primarily due to the utilization of a smaller Q parameter value in relation to the R parameter value, resulting in more effective filtering. The most favorable measurement outcomes are obtained when employing parameter values of R = 100 and Q = 0.01, as demonstrated in Figure 4. It is worth mentioning that there is a slight delay at the beginning, with the sensor taking approximately 4-6 seconds to reach optimal performance.
Following the successful determination of the optimal R and Q parameter values through extensive testing, further evaluations were conducted at distances of 10, 20, 30, 40, and 50 using these ideal parameter values. The outcomes of these distance estimation tests using the R = 100 and Q = 0.01 parameter values are presented in Figure 5, showcasing the accurate results achieved.
(a) | (b) | (c) | |
(d) | (e) | ||
Figure 5. (a) distance 10 cm, (b) distance 20 cm, (c) distance 30 cm, (d) distance 40 cm, (e) distance 50 cm | |||
Figure 5 provides valuable insights into the optimal distance estimation measurements obtained from the ultrasonic sensor across various distances, particularly within the range of up to 50 cm. It is important to note that although there may be a slight delay in the initial stages of the measurement, the overall performance remains highly satisfactory. Additionally, Table 2 presents a comprehensive comparison between the sensor's filtered values and the corresponding actual values, allowing for a thorough analysis of their alignment and accuracy.
Table 2. Comparison table of measurement between filtered sensor and actual distances (in cm)
Actual Distance | Distance measured by Ultrasonic KF | Ultrasonic Error KF (%) |
10 | 10.06 | 0.60 |
20 | 20.5 | 2.50 |
30 | 30.09 | 0.90 |
40 | 40.07 | 0.70 |
50 | 50.27 | 2.70 |
According to Table 2, the distance measurement results obtained using the HC-SR04 ultrasonic sensor and the Kalman Filter method. Notably, the measurements exhibit an impressively low error value, consistently below 3%. Furthermore, the error measurement is only 0.6% compared to the actual distance. These findings unequivocally demonstrate the effectiveness of the designed Kalman Filter algorithm, which has significantly increased the efficiency and accuracy of distance measurement.
This study proposes the utilization of the Kalman Filter algorithm for distance estimation measurements using an ultrasonic sensor despite the time required to achieve measurement stability around 4-6 second in this system. The results indicate that using the Kalman Filter algorithm significantly enhances the accuracy of distance measurement compared to not using the algorithm. Optimal parameter values for the Kalman Filter in this system are determined to be and
. The process of fine-tuning these parameters involves employing a trial-and-error methodology, systematically testing values from the lowest to the highest until obtaining the most effective parameter values. This method takes a long time for data analysis process in data analyzing process. However, it is worth that this approach necessitates a substantial amount of time for data analysis. As a suggestion for future research, it is recommended to explore alternative tuning methods for determining the Kalman Filter parameters.
REFERENCES
[1] C. Smith, J. Satme, J. Martin, A. R. J. Downey, N. Vitzilaios, and J. Imran, “UAV rapidly-deployable stage sensor with electro-permanent magnet docking mechanism for flood monitoring in undersampled watersheds,” HardwareX, vol. 12, pp. 1–19, 2022, https://doi.org/10.1016/j.ohx.2022.e00325.
[2] J. H. Choi, J. E. Kim, and K. T. Kim, “People counting using ir-uwb radar sensor in a wide area,” IEEE Internet Things J, vol. 8, no. 7, pp. 5806–5821, 2021, https://doi.org/10.1109/JIOT.2020.3032710.
[3] J. Schlarp, E. Csencsics, and G. Schitter, “Optical Scanning of a Laser Triangulation Sensor for 3-D Imaging,” IEEE Trans Instrum Meas, vol. 69, no. 6, pp. 3606–3613, 2020, https://doi.org/10.1109/JIOT.2020.3032710.
[4] F. Zhang, L. Yi, and X. Qu, “Simultaneous measurements of velocity and distance via a dual-path FMCW lidar system,” Opt Commun, vol. 474, pp. 1–6, 2020, https://doi.org/10.1016/j.optcom.2020.126066.
[5] T. B. Asafa, T. M. Afonja, E. A. Olaniyan, and H. O. Alade, “Development of a vacuum cleaner robot,” Alexandria Engineering Journal, vol. 57, no. 4, pp. 2911–2920, 2018, https://doi.org/10.1016/j.aej.2018.07.005.
[6] Y. Irawan, Muhardi, R. Ordila, and R. Diandra, “Automatic floor cleaning robot using arduino and ultrasonic sensor,” Journal of Robotics and Control (JRC), vol. 2, no. 4, pp. 240–243, 2021, https://doi.org/10.18196/jrc.2485.
[7] A. Gadekar et al., “Rakshak: A modular unmanned ground vehicle for surveillance and logistics operations,” Cognitive Robotics, vol. 3, pp. 23–33, 2023, https://doi.org/10.1016/j.cogr.2023.02.001.
[8] T. Severin and D. Soffker, “Sensor optimization for altitude estimation of spraying drones in vineyards,” in IFAC-PapersOnLine, pp. 107–112, 2022, https://doi.org/10.1016/j.ifacol.2022.11.123.
[9] R. Guo, Y. Zhang, B. Tian, S. Xu and Z. Chen, "Height Measurement of Micro-UAVs with L-Band Staring Radar," 2021 IEEE International Geoscience and Remote Sensing Symposium IGARSS, pp. 7967-7970, 2021, https://doi.org/10.1109/IGARSS47720.2021.9553143.
[10] Q. Wang et al., "Range and Height Measurement of X-Band EM Propagation in the Marine Atmospheric Boundary Layer," in IEEE Transactions on Antennas and Propagation, vol. 67, no. 4, pp. 2063-2073, 2019, https://doi.org/10.1109/TAP.2019.2894269.
[11] G. Montazeaud et al., “Development of a low cost open-source ultrasonic device for plant height measurements,” Smart Agricultural Technology, vol. 1, pp. 1–7, 2021, https://doi.org/10.1016/j.atech.2021.100022.
[12] Azhari, D. Simanjuntak, L. Hakim, and Sabar, “Design and control system of temperature and water level in hydroponic plants,” in Journal of Physics: Conference Series, Institute of Physics, 2022, https://doi.org/10.1088/1742-6596/2193/1/012018.
[13] F. Dhiaulhaq, U. Yusmaniar Oktiawati, and I. V Paputungan, “Designing Arduino-Based Devices for Fluid Height Monitor,” in 2020 8th International Conference on Cyber and IT Service Management, CITSM 2020, Institute of Electrical and Electronics Engineers Inc., 2020, pp. 1–4, 2020, https://doi.org/10.1109/CITSM50537.2020.9268835.
[14] A. K. Sahoo and S. K. Udgata, "A Novel ANN-Based Adaptive Ultrasonic Measurement System for Accurate Water Level Monitoring," in IEEE Transactions on Instrumentation and Measurement, vol. 69, no. 6, pp. 3359-3369, 2020, https://doi.org/10.1109/TIM.2019.2939932.
[15] Y. Saragih, J. H. Prima Silaban, H. Aliya Roostiani and S. A. Elisabet, "Design of Automatic Water Flood Control and Monitoring Systems in Reservoirs Based on Internet of Things (IoT)," 2020 3rd International Conference on Mechanical, Electronics, Computer, and Industrial Technology (MECnIT), pp. 30-35, 2020, https://doi.org/10.1109/MECnIT48290.2020.9166593.
[16] J. Susilo, A. Febriani, U. Rahmalisa and Y. Irawan, “Car parking distance controller using ultrasonic sensors based on arduino uno,” Journal of Robotics and Control (JRC), vol. 2, no. 5, pp. 353-356, 2021, https://doi.org/10.18196/jrc.25106.
[17] W. A. Jabbar, C. W. Wei, N. A. A. M. Azmi, and N. A. Haironnazli, “An IoT Raspberry Pi-based parking management system for smart campus,” Internet of Things (Netherlands), vol. 14, 2021, https://doi.org/10.1016/j.iot.2021.100387.
[18] A. Ma’arif, I. Iswanto, A. A. Nuryono, and R. I. Alfian, “Kalman Filter for Noise Reducer on Sensor Readings,” Signal and Image Processing Letters, vol. 1, no. 2, pp. 11–22, Jul. 2019, https://doi.org/10.31763/simple.v1i2.2.
[19] R. I. Alfian, A. Ma’Arif, and S. Sunardi, “Noise reduction in the accelerometer and gyroscope sensor with the Kalman filter algorithm,” Journal of Robotics and Control (JRC), vol. 2, no. 3, pp. 180–189, 2021, https://doi.org/10.18196/jrc.2375.
[20] I. Iswanto, A. Ma’arif, N. Maharani Raharja, T. K. Hariadi, and M. A. Shomad, “Using a Combination of PID Control and Kalman Filter to Design of IoT-based Telepresence Self-balancing Robots during COVID-19 Pandemic,” Emerging Science Journal, vol. 4, no. Special issue, pp. 241–261, 2020, https://doi.org/10.28991/esj-2021-SP1-016.
[21] K. A. Raza and W. Monnet, “Moving Objects Detection and Direction-Finding with HC-SR04 Ultrasonic Linear Array,” in International Engineering Conference (IEC), pp. 153–158, 2019, https://doi.org/10.1109/IEC47844.2019.8950639.
[22] P. P. Kulkarni, S. R. Kutre, S. S. Muchandi, P. Patil and S. Patil, "Unmanned Ground Vehicle for Security and Surveillance," 2020 IEEE International Conference for Innovation in Technology (INOCON), pp. 1-5, 2020, https://doi.org/10.1109/INOCON50539.2020.9298296.
[23] E. Prayetno et al., “PLTD Engine Tank Oil Volume Monitoring System using HC-SR04 Ultrasonic Sensor Based on Internet of Things (IoT),” International Journal of Electrical, Energy and Power System Engineering (IJEEPSE), vol. 4, no. 1, pp. 134–138, 2021, https://doi.org/10.31258/ijeepse.4.1.134-138.
[24] P. A. Darwito, M. Raditya, H. Sa’diyah, A. Cikadiarta and W. Aditya, "Comparative Study of Burst And Beams Types Ultrasonic Sensor For Distance Measurements," 2019 International Seminar on Intelligent Technology and Its Applications (ISITIA), pp. 46-51, 2019, https://doi.org/10.1109/ISITIA.2019.8937133.
[25] L. Reddy Cenkeramaddi, J. Bhatia, A. Jha, S. Kumar Vishkarma and J. Soumya, "A Survey on Sensors for Autonomous Systems," 2020 15th IEEE Conference on Industrial Electronics and Applications (ICIEA), pp. 1182-1187, 2020, https://doi.org/10.1109/ICIEA48937.2020.9248282.
[26] M. Wachsmuth, A. Koppert, L. Zhang and V. Schwieger, "Development of an error-state Kalman Filter for Emergency Maneuvering of Trucks," 2020 European Navigation Conference (ENC), pp. 1-7, 2020, https://doi.org/10.23919/ENC48637.2020.9317306.
[27] R. V. Garcia, P. C. P. M. Pardal, H. K. Kuga, and M. C. Zanardi, “Nonlinear filtering for sequential spacecraft attitude estimation with real data: Cubature Kalman Filter, Unscented Kalman Filter and Extended Kalman Filter,” Advances in Space Research, vol. 63, no. 2, pp. 1038–1050, 2019, https://doi.org/10.1016/j.asr.2018.10.003.
[28] I. Ullah, Y. Shen, X. Su, C. Esposito, and C. Choi, “A Localization Based on Unscented Kalman Filter and Particle Filter Localization Algorithms,” IEEE Access, vol. 8, pp. 2233–2246, 2020, https://doi.org/10.1109/ACCESS.2019.2961740.
[29] I. Ullah, Y. Shen, X. Su, C. Esposito and C. Choi, "A Localization Based on Unscented Kalman Filter and Particle Filter Localization Algorithms," in IEEE Access, vol. 8, pp. 2233-2246, 2020, https://doi.org/10.1109/ACCESS.2019.2961740.
[30] P. J. van Leeuwen, “A consistent interpretation of the stochastic version of the Ensemble Kalman Filter,” Quarterly Journal of the Royal Meteorological Society, vol. 146, no. 731, pp. 2815–2825, 2020, https://doi.org/10.1002/qj.3819.
Distance Estimation on Ultrasonic Sensor Using Kalman Filter (Muhammad Haryo Setiawan)