So I have my raspberry pi, I watched a YouTube tutorial on what to do. I copied absolutely everything but still, it's not working. The wiring is surely correct as it is copied from the video and the code is also. I run the code and it says its running, there are no issues, yet the distance sensor is not measuring the distance, or at least it isn't showing the result. I have absolutely no idea what to do, I rewired, got a new HC-SR04 sensor, changed the power cable for the pi.

https://github.com/makertut/raspberry-hc-sr04 <- code is in here.

The output is just 'Distance measurement in progress Waiting for sensor to settle'

  • That code should have timeouts on the 'while GPIO.input(' loops. Post a clear photo of your wiring.
    – CoderMike
    Apr 6 at 11:30
  • gyazo.com/dc2a4198ae07939c20c54fdf600affc9 Here is a link to the wiring, its a photo. Also I appreciate the help. Thank you!
    – Martin
    Apr 6 at 13:15
  • Looks like one end of a resistor is plugged into row 8 of the board, connected to nothing.
    – CoderMike
    Apr 6 at 19:00
  • Nope, it's all connected correctly, here is a picture. I took out the sensor for visibility sake. gyazo.com/d06c997ac9bce32b8b8d8160b1f07efb
    – Martin
    Apr 6 at 21:16
  • That image has 2 resistors in row 2, Milliways image has resistors in rows 2 and 3.
    – CoderMike
    Apr 6 at 21:48

Using the following wiring diagram:

enter image description here


enter image description here

With the code from https://github.com/makertut/raspberry-hc-sr04 : (NOTE: code requires TRIG and ECHO to be swapped to match circuit)

import RPi.GPIO as GPIO
import time

TRIG = 24 
ECHO = 23

print "Distance Measurement In Progress"

    while True:

        GPIO.output(TRIG, False)
        print "Waiting For Sensor To Settle"

        GPIO.output(TRIG, True)
        GPIO.output(TRIG, False)

        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"

except KeyboardInterrupt: # If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup
    print("Cleaning up!")

I get the following response:

Distance: 10.39 cm
Waiting For Sensor To Settle
Distance: 10.58 cm
Waiting For Sensor To Settle
Distance: 12.47 cm
Waiting For Sensor To Settle
Distance: 12.52 cm
Waiting For Sensor To Settle
Distance: 13.7 cm
Waiting For Sensor To Settle
Distance: 15.83 cm
Waiting For Sensor To Settle
Distance: 15.51 cm
Waiting For Sensor To Settle
Distance: 15.76 cm
  • I am genuinely speechless. I have no Idea what to do. My wires and connections look perfect, The code is the exact same as yours. What you have given me is what I have done. I am genuinely so grateful for your response. I really appreciate the effort you have put in to help me. When I run the code I just get 'Distance measurement in Progress. Waiting for sensor to settle' Here is a picture: gyazo.com/88a4992857aeb5950c0099b265fe706d Here are another 2: gyazo.com/ff58ef6a0c2dc1bc8f939bb96a45956c gyazo.com/24f198c738b5d2bd8d886b3ee96e18fc
    – Martin
    Apr 7 at 18:25
  • Are you using a 1K resistor between echo and GPIO23 and 2K resistor between GPIO23 and GND?
    – CoderMike
    Apr 7 at 20:30
  • It is a 1k resistor at echo and 2.2k at gnd
    – Martin
    Apr 8 at 15:08
  • CoderMike I really want to thank you, it is working, the resistors seemed to be incorrect, genuinely you are such a good person. Thank you so much for the devotion and help, really, I am so grateful!
    – Martin
    Apr 8 at 15:22
  • Great, please mark the answer as correct if working.
    – CoderMike
    Apr 8 at 15:29

You appear to be asking us to debug some random tutorial you found on the internet which you may or may not have followed correctly.

Try https://gpiozero.readthedocs.io/en/stable/recipes.html?highlight=distance#distance-sensor

If this doesn't work you need to post details of your setup.

  • Hi! Thank you so much for your feedback, I have done everything that is on that link, I am getting a warning when i run the code 'no echo received'. I Think it is a problem with the code, that diagram from the link you sent me is what is in front of me right now.
    – Martin
    Apr 6 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.