In this guide, you will find a comprehensive explanation and setup for utilizing a Raspberry Pi 3B+ (running Ubuntu Server 22.04) in conjunction with the HC-SR04 Ultrasound component.
This project aims to help you grasp the fundamental principles of ultrasound technology and enhance your familiarity with the GPIO (General-Purpose Input/Output) library.
Distance = time * speed
Here, the speed of sound in air is approximately 343 m/s.
Note: Raspberry Pi 3B+ GPIO pins support a maximum voltage of 3.3 V. Therefore, the use of a voltage divider is necessary.
To view essential information about Raspberry Pi pins, including pin enumeration, use the following command:
pinout
Below is the configuration for connecting the HC-SR04 Ultrasound module in BOARD mode:
- Connect the Vcc channel to the 5V pin.
- Connect the Trig channel to GPIO18, which supports PWM (Pulse Width Modulation).
- Connect the Echo channel to GPIO24, ensuring its voltage is reduced to around 3V using a voltage divider.
- Connect the Gnd channel to a GND pin.
For the voltage division, two resistors are employed to achieve a voltage of approximately 3.125 V:
- 550 Ω (combination of 330 Ω and 220 Ω resistors)
- 330 Ω
Refer to the following wiring diagram for a clearer visualization:
To get started, follow these steps:
- Clone the repository onto your Raspberry Pi 3B+ using the terminal:
git clone https://github.com/mataruzz/raspberryPi_components_tests.git
- Navigate to the cloned directory:
cd raspberryPi_components_tests
- Execute the ultrasound test script:
./HC_SR04_ultrasound/ultrasound_test.py
By following these instructions, you'll successfully set up and run the HC-SR04 Ultrasound module with your Raspberry Pi 3B+.