Hey guys,
I'm diving into Raspberry Pi projects and I've got an HC-SR04 ultrasonic sensor that I want to use. I've seen some cool stuff you can do with it, but I'm not quite sure how to get started.
Any of you fellow dudes have experience using the HC-SR04 ultrasonic sensor with a Raspberry Pi 4? Could you give me a quick rundown of the steps or any tips to make it work?
I'd really appreciate your expertise on this. Thanks a lot in advance for your help, guys!
Hello
Project: Measure distances with an ultrasonic sensor and Raspbery Pi 4
Hardware required:
1 HC-SR04 ultrasonic sensor
1 breadboard
1 1K ohm resistor
1 2k ohm resistor
Wiring Circuit:
First place the ultrasonic sensor on the bredboard (see image).
Next, connect the four pins of the sensor to the pins of the Raspberry Pi through the breadboard.
Connect the GND pin with the GND pin.
Connect Trigger pin to GPIO pin 25
Connect the Echo pin to GPIO pin 23 using a voltage divider. For this connect one end of the 1K ohm resistor to the Echo pin, and the other end to a 2k resistor. Connect the other end of the 2k ohm resistor to the Raspberry Pi's GND.
Script
from gpiozero import DistanceSensor from time import sleep sensor=DistanceSensor(23,25) while True: print('Distance: ', sensor.distance*100, 'cm') sleep(1)