Forum

How to use un ultra...
 
Notifications
Clear all

[Solved] How to use un ultrasonic sensor HC-SR04 with Raspberry Pi 4

3 Posts
2 Users
0 Likes
743 Views
Posts: 1
Guest
Topic starter
(@Gerry)
New Member
Joined: 2 years ago

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!

2 Replies
Posts: 13
(@raspi)
Active Member
Joined: 2 years ago

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)
Reply
1 Reply
Guest
(@Doran)
Joined: 2 years ago

New Member
Posts: 2

@raspi Thank you 👍

Reply

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share:
Scroll to Top