In this project we connect an HC-SR04 an Ultrasonic Sensor to Raspberry Pi.
We use Python Threading Library to read incoming Data.
The Data is shown in Graphic by using Tkinter Sprite Library.
- On Raspberry Pi Create a directory
- downloadTest_HC-SR04 and unzip them in that folder
- On Raspberry Pi under Menu Programming select Thonny Python IDE
- from menu file open file Test_HC-SR04.py
- Connect Serial Device to Raspberry Pi
- run the Python file
A basic ultrasonic sensor consists of one or more ultrasonic transmitters , a receiver, and a control circuit. The transmitters emit a high frequency ultrasonic sound, which bounce off any nearby solid objects. Some of that ultrasonic noise is reflected and detected by the receiver on the sensor. That return signal is then processed by the control circuit to calculate the time difference between the signal being transmitted and received. The distance wird calculated base on time difference of Transmit and receive Time and sound speed (about 34300 meter per second).
Time Difference = 2 *Distance (in meter) / 34300 (meter per second sound speed) or
Distance = 17150 * Time Difference
- Working Voltage: DC 5V
- Working Current: 15mA
- Working Frequency: 40Hz
- Max Range: 4m
- Min Range: 2cm
- Measuring Angle: 15 degree
- Trigger Input Signal: 10µS TTL pulse
- Echo Output Signal Input TTL lever signal and the range in proportion
- Dimension 45 * 20 * 15mm
- Walk Through code
- we use a Thread (HC_SR04_Thread ) to set Trigger and wait for Echo and measure the time difference
- using tkinter Library for Graphics