Accurate Proximity Sensor for Parking Assistance Matic Klopčič1,2 , doc. dr. Kristina Stojmenova Pečečnik1 1 University of Ljubljana, Faculty of Electrical Engineering, Tržaška cesta 25, 1000 Ljubljana 2 University of Ljubljana, Faculty of Computer and Information Science, Večna pot 113, 1000 Ljubljana Abstract The distance to obstacles is crucial for safe driving and parking. Currently, cars are equipped with sensors that measure the distance to obstacles, but the distance is only displayed using different colors and sounds. Therefore, we have assembled a device that, with a distance measuring sensor, thermometer, and humidity sensor, measures and calculates the distance to the nearest object. It accurately displays the exact distance down to the centimeter on the screen, providing the driver with more precise information about the proximity to obstacles. Keywords proximity sensor, HC - SP04, DHT22, Raspberry Pi, temperature, relative humidity 1. Introduction All modern cars are equipped with numerous sensors that make our driving experience more comfortable and, above all, safer. From wheel sensors that prevent wheel slippage and activate ESP at the right moment, to sensors measuring battery voltage, thermometers, fuel quantity sensors, and even proximity sensors. These sensors can stop the car if we are approaching an obstacle too quickly, maintain a safe distance from the vehicle in front of us, and assist us in parking. However, there is room for improvement. Currently, cars display the distance to obstacles using colors (green, orange, and red) and audible signals. Nevertheless, this is sometimes not sufficient. In the case of narrow garages or parking spaces, the car may show a red color and emit a warning sound, but other than that, we may not be able to park without getting dangerously close to the obstacle. In such cases, a system that could precisely tell us in centimeters how much space we have left to the obstacle, as it is presented in Figure 1, would be useful. HCI SI 2023: Human-Computer Interaction Slovenia 2023, January 26, 2024, Maribor, Slovenia Envelope-Open mk6792@student.uni-lj.si (M. Klopčič); kristina.stojmenova@fe.uni-lj.si (K. S. Pečečnik) © 2024 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0). CEUR Workshop Proceedings http://ceur-ws.org ISSN 1613-0073 CEUR Workshop Proceedings (CEUR-WS.org) CEUR ceur-ws.org Workshop ISSN 1613-0073 Proceedings Figure 1: Displaying measurements on the touch screen behind the steering wheel. 2. Theoretical background of proximity sensors Proximity sensors are devices that can detect the presence or absence of an object within a certain range without physical contact. They play a crucial role in various applications, from industrial automation to consumer electronics. They utilize different technologies such as infrared (IR), ultrasonic, capacitive, inductive, laser, and photoelectric sensors. Infrared sensors [1] use infrared light for detection and are common in touchless interfaces like smart- phones. Ultrasonic sensors [2] emit and measure ultrasonic waves, widely used in industrial automation. Capacitive sensors [3] measure changes in capacitance, found in touchscreens. Inductive sensors [4] detect changes in inductance caused by metal objects, prevalent in industrial automation. Laser sensors [5] use laser beams for distance measurement, applied in precision applications. Photoelectric sensors [6] emit and detect light changes, suitable for industrial and automation tasks. Proximity sensors find applications in object detection, touchless interfaces in consumer electronics, safety systems in automotive applications and gesture recognition. They con- tribute to safety by detecting objects in automotive settings and industrial automation. Gesture recognition systems benefit from proximity sensors for touchless control of electronic devices. Proximity sensors play a significant role in modern technology, enhancing user experiences and contributing to the efficiency of various industries. 3. Solution - presentation of the sensor system We designed a system with two sensors. To measure the distance from objects, we used the HC-SR04 sensor. However, for precise measurements, we also need a humidity sensor and a temperature sensor. Both are inside the DHT22 module. Figure 2: Transmission (blue signal), reflection (green signal), and reception of signals with a sensor mounted on the front part of the car. 3.1. Proximity sensor HC-SP04 The HC-SP04 operates at 5 V and measures in the range from 2 cm to 4 m. The measurement angle is 15°. The sensor consists of a speaker that emits at 40 kHz frequency and a microphone. With a high pulse at the input trigger pin, which must last at least 10 𝜇s, the module emits 8 pulses at a frequency of 40 kHz. The microphone then receives the emitted pulses if they bounce off objects. The transmission and reflection are shown in Figure 2. Based on the time elapsed between pulse transmission and reception, the distance can be calculated. We know that sound travels at a speed of approximately 340 𝑚𝑠 . The traveled distance can be calculated using the formula: 𝑠 =𝑣 ∗𝑡 (1) where 𝑠 equals travelled distance, 𝑣 represents the speed of sound and 𝑡 is half the duration from the moment the sound left the sensor to the moment we detect it again. However, the speed of sound depends on other physical quantities. At a temperature of 0 °C and an air pressure of 101.325 kPa, the speed of sound is 331.29 𝑚𝑠 [7]. The corrected formula, which includes the influence of temperature and humidity, would be:: 𝑣𝑇 𝐻 = 331, 4 + 0, 6 ∗ 𝑇 + 0, 0124 ∗ 𝐻 (2) where 𝑣𝑇 𝐻 is the corrected speed of sound, T is the current air temperature, and H is the relative humidity of the air. The formula is taken from the website [8]. The sensor output signal has a voltage of 5 V. However, the input pins on Raspberry Pi work on 3.3 V. Therefore, we should lower the output signal voltage from sensor before the input pins. For that purpose, we added voltage divider circuit, which consists of two resistors connected in series. The input is the output signal, and the signal reduced to 3.3 V, will be between the resistors. Equation that represents the voltage divider circuit is: 𝑉𝑜𝑢𝑡 𝑅2 = (3) 𝑉𝑖𝑛 𝑅1 + 𝑅2 where 𝑉𝑜𝑢𝑡 states for 3.3 V signal that goes to Raspberry Pi, 𝑉𝑖𝑛 represents signal from the sensor and 𝑅1 , 𝑅2 are values of two resistors. Resistance 𝑅1 and 𝑅2 can be arbitrary as long as the ratio 𝑉𝑜𝑢𝑡 𝑉 remains 3.3𝑉 5𝑉 = 0.66. We chose 𝑅1 to be 1 𝑘Ω. 𝑅2 is then calculated as: 𝑖𝑛 𝑅2 3.3𝑉 = 1000Ω + 𝑅2 5𝑉 𝑅2 = 0.66 ∗ (1000𝑘Ω + 𝑅2 ) 𝑅2 = 660𝑘Ω + 0.66 ∗ 𝑅2 660𝑘Ω 𝑅2 = 0.34 𝑅2 = 1941 𝑅2 ≈ 2𝑘Ω Entire circuit is presented in Figure 3. 3.2. Humidity and Temperature Sensor DHT22 For measuring temperature and relative humidity, we used the DHT22 sensor. It operates in the voltage range from 3.3 V to 6 V [9]. A polymer capacitor is used for measurement. It measures relative humidity in the range of 0 % to 100 % and temperature from -40 °C to 80 °C. The measurement accuracy is ± 2 % for humidity and ± 0.5 °C for temperature. Sensitivity for humidity is 0.1 %, and for temperature, it is also 0.1 °C. The sampling rate is relatively small, with a maximum sampling rate of one measurement every 2 seconds. However, external temperature and humidity usually do not change very rapidly, and a sampling rate of 2 seconds is entirely sufficient for our application. 3.3. Controlling with Raspberry Pi We controlled both sensors using the Raspberry Pi microcontroller. For displaying the distance from obstacles, we used the ”Raspberry Pi Touch Display” [10]. We wrote the code in the Python programming language [11]. A power bank was used to power the sensors and microcontroller. All components of the system can be seen in Figure 4a. 4. Measurements and Testing We conducted separate tests for each sensor. First, we tested the distance sensor, followed by the temperature and humidity sensors. Subsequently, we integrated all of them into a single distance measurement. We tested the accuracy of the sensor system using a standard meter. We Figure 3: Voltage divider circuit with proximity sensor HS - SP04 and Raspberry Pi. positioned it perpendicular to the wall and conducted measurements at distances of 3 cm from the wall, 10 cm, 20 cm, ... and at intervals of 10 cm onwards up to 150 cm. The measurement error was at most ±1 cm. The sensor system was mounted on the front part of the car, and the screen with the micro- controller was installed behind the steering wheel. Based on the distance from obstacles, we colored the text. The text color is green for distances greater than 1 m, orange for distances between 0.5 m and 1 m, and red for distances below 0.5 m. Changing the color helps the driver recognize potential dangers, as it is more crucial to focus on the surroundings while driving. The example of all three different states can be observed in Figures 4b, 5a, 5b. 5. Results The proximity sensor proved to be very useful as it accurately displays the distance to obstacles with an accuracy of ± 1 cm. We measured the error by placing the sensor at a measured distance from the wall and comparing the distance with the displayed value on the screen. We compared (a) Components of the sensor system. (b) Distance to obstacle is greater than 1 m. Figure 4: All components of the sensor system and an example of displayed distance that is larger than 1 m. (a) Distance to obstacle is between 0,5 m and 1 m. (b) Distance to obstacle is less than 0,5 m. Figure 5: Different colors of the text, according to the proximity to the obstacle. at distances of 3 cm, 10 cm, 20 cm, and then every 10 cm up to 150 cm. The error was consistently within ± 1 cm. The experiment was conducted at temperature 22.1 °C and humidity 52 %. We also tested the system outdoor, where the temperature and humidity were 6.2 °C and 73 % respectively. The error remained ± 1 cm. The only challenge is the relatively narrow measurement angle, which is 15°. At a distance of 1 m, the coverage width is only 0.26 m, calculated as 2 ∗ 𝑡𝑎𝑛(7.5°). While this is acceptable when approaching a wall, obstacles such as pillars, protruding parts, and obstacles at the sides of the car pose a challenge. Additionally, the width of the sensing area decreases as we approach an obstacle. The solution would be to use multiple sensors at different parts of the car. 6. Conclusion and further improvements The developed sensor for measuring the distance to obstacles is practical for parking, as it provides more information about the surroundings. Consequently, there is a lower probability of hitting pillars or edges that are not visible from the driver’s seat, or not knowing how far we are from them. Moreover, according to specifications [12], the system should work between -15 °C and 70 °C, as these are limitations for proximity sensor. Humidity and temperature sensor DHT22 works over a wider ranger, namely between -40 °C and 80 °C. Therefore, the system should work even in hot summer days as well as during winter. However, there are several possible improvements. One sensor covers only a part of the car due to the relatively small detection angle, so it would make sense to add multiple sensors at different parts of the car. This way, all distances could be displayed at once. It would also be interesting to investigate how rain affects the sensor’s operation, assuming the sensor is adequately protected against water ingress. The speed of sound through wa- ter is significantly higher, measuring 1400 𝑚𝑠 at 0 °C [13], and it increases with temperature. Consequently, there may be a measurement error. References [1] A. Sabatini, V. Genovese, E. Guglielmelli, A. Mantuano, G. Ratti, P. Dario, A low-cost, composite sensor array combining ultrasonic and infrared proximity sensors, in: Pro- ceedings 1995 IEEE/RSJ International Conference on Intelligent Robots and Systems. Human Robot Interaction and Cooperative Robots, volume 3, 1995, pp. 120–126 vol.3. doi:10.1109/IROS.1995.525872 . [2] M. R. Hornung, O. Brand, Micromachined ultrasound-based Proximity sensors, volume 4, Springer Science & Business Media, 1999. [3] Y. Ye, C. Zhang, C. He, X. Wang, J. Huang, J. Deng, A review on applications of capacitive displacement sensing for capacitive proximity sensor, IEEE Access 8 (2020) 45325–45342. doi:10.1109/ACCESS.2020.2977716 . [4] P. Kejı́k, C. Kluser, R. Bischofberger, R. S. Popovic, A low-cost inductive proximity sensor for industrial applications, Sensors and Actuators A: Physical 110 (2004) 93–97. URL: https://www.sciencedirect.com/science/article/pii/S0924424703004151. doi:https: //doi.org/10.1016/j.sna.2003.07.007 , selected Papers from Eurosensors XVI Prague, Czech Republic. [5] E. Korkmaz, Optical system design of direct detection short-pulsed laser proximity sensor, Master’s thesis, Middle East Technical University, 2017. [6] S. Juds, Photoelectric sensors and controls: selection and application, volume 63, CRC Press, 1988. [7] G. S. Wong, Speed of sound in standard air, The Journal of the Acoustical Society of America 79 (1986) 1359–1366. [8] D. Nedelkovski, Ultrasonic sensor hc-sr04 and arduino – complete guide, Published online, 2015. URL: https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/, accessed: 12. 12. 2023. [9] Digital relative humidity & temperature sensor am2303/dht22, Published online, 2009. URL: https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+ sensor+AM2302.pdf, accessed: 17. 12. 2023. [10] Raspberry pi touch display, Published online, 2015. URL: https://www.raspberrypi.com/ products/raspberry-pi-touch-display/, accessed: 20. 12. 2023. [11] Python, Published online, 2023. URL: https://www.python.org/, accessed: 20. 12. 2023. [12] Pysupply, the maker emporium, Published online, 2024. URL: https://uk.pi-supply.com/ products/ultrasonic-distance-sensor-hc-sr04, accessed: 23. 1. 2024. [13] M. Greenspan, C. E. Tschiegg, Tables of the speed of sound in water, The Journal of the Acoustical Society of America 31 (1959) 75–76.