Pimoroni Explorer Hat Pro, Velleman HC-SR05 Ultrasonic Sensor


#1

How do you connect the HC-SR05, to the Explorer Hat ?

VCC - 5V
Echo - ?
TNG - ?
OUT - ?
GND - GND


#2

Have a look at this, https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi


#3

VCC - 5V
Echo - INPUT
TNG - OUTPUT
OUT - ?
GND - GND


Thanks


#4

I don’t know what to tell you, Velleman don’t give any detailed info on how to use it? Not that I could find anyway?


There is a link to download the user manual on the left but it doesn’t have much info in it. Basically how to hook it up to an Arduino.
Found this though, might help, https://www.youtube.com/watch?v=xACy8l3LsXI


#5

You need to send a 10uS pulse into the Trigger Pin and then watch the Echo pin for a response.

The Echo pin will go HIGH, remain HIGH momentarily, and then go LOW in response to your Trigger.

You must record the amount of time this signal is HIGH with reasonable precision- doing this with Python on the Pi isn’t especially accurate.

The recorded time is the duration of both the outbound and return leg of your ultrasonic ping. Should be easy to convert to centimetres; given sound travels at 343meters/second and your measurement is twice the distance you want to record.


#6

This works for the Ultrasonic Sensor.

import RPi.GPIO as GPIO
import time
import explorerhat

GPIO.cleanup()

GPIO.setmode(GPIO.BOARD)

TRIG = 31
ECHO = 16

print (“Distance Measurement In Progress”)

GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)

GPIO.output(TRIG, False)
print(“Waiting For Sensor To Settle”)
time.sleep(1)

while True:
GPIO.output(TRIG, 1)
time.sleep(0.00001)
GPIO.output(TRIG, 0)

    while GPIO.input(ECHO)==0:
      pulse_start = time.time() 

    while GPIO.input(ECHO)==1:
      pulse_end = time.time() 

    pulse_duration = pulse_end - pulse_start 

    distance = pulse_duration * 17150 

    distance = round(distance, 2) 
                    
    print ("Distance:",distance,"cm") 

    time.sleep(1)

GPIO.cleanup()


#7

An easily clickable “code” tags option on this forum would be nice, hint hint. Instead of having to use , , or is it ‘’’ ‘’’ I forgot already?

Nice that you figured it out. I’m going to copy your code for my own use, if you don’t mind. Its a shame some of the indents appear to have been lost. I have a rover project of my own on the go with a Pi Zero W and an Explorer pHat. I have plans to add an ultrasonic sensor at some point.