# Ultrasonic Distance Sensor - RCWL-1601 -

**URL:** <https://forum.core-electronics.com.au/t/ultrasonic-distance-sensor-rcwl-1601/12717>\
**Category:** Raspberry Pi\
**Created:** [7 January 2022 07:50 UTC](https://forum.core-electronics.com.au/t/ultrasonic-distance-sensor-rcwl-1601/12717 "2022-01-07T07:50:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fusun175588](https://avatars.discourse-cdn.com/v4/letter/f/c89c15/32.png) [@Fusun175588](https://forum.core-electronics.com.au/u/Fusun175588)\
**Post date:** [7 January 2022 07:50 UTC](https://forum.core-electronics.com.au/t/ultrasonic-distance-sensor-rcwl-1601/12717/1 "2022-01-07T07:50:13Z")

</div>

Hi All,

I am trying to get the sensor working on a raspberry pi 3b using the code below. However, receiver is consistently energising the echo pin. As the echo pin is constantly high, the code is stuck at the calculation line.

Just wondering if I have missed anything?

```auto
import RPi.GPIO as GPIO
import time

try:
    GPIO.setmode(GPIO.BOARD)

    PIN_TRIGGER = 18
    PIN_ECHO = 22
    

    GPIO.setup(PIN_TRIGGER, GPIO.OUT)
    GPIO.setup(PIN_ECHO, GPIO.IN)
    
    GPIO.output(PIN_TRIGGER, GPIO.LOW)
    
    print("Waiting for sensor to settle")
    print(GPIO.input(PIN_ECHO))
    time.sleep(2)

    print ("Calculating distance")
    print(GPIO.input(PIN_ECHO)) # This line should print 0 but it is printing 1.
    
    GPIO.output(PIN_TRIGGER, GPIO.HIGH)
    time.sleep(0.00001)
    GPIO.output(PIN_TRIGGER, GPIO.LOW)

    while GPIO.input(PIN_ECHO)==0:
        pulse_start_time = time.time()
    while GPIO.input(PIN_ECHO)==1:
        pulse_end_time = time.time()

    pulse_duration = pulse_end_time - pulse_start_time
    distance = round(pulse_duration * 17150, 2)
    print("Distance:",distance,"cm")

finally:
    GPIO.cleanup()

```

Regards,  
Fu

---

<div class="post-metadata">

**Author:** ![Liam120347](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/liam120347/32/5003_2.png) [@Liam120347](https://forum.core-electronics.com.au/u/Liam120347)\
**Post date:** [7 January 2022 13:10 UTC](https://forum.core-electronics.com.au/t/ultrasonic-distance-sensor-rcwl-1601/12717/2 "2022-01-07T13:10:56Z")

</div>

Hi Fu,

What does your circuit look like? I came across this guide that PiHut made for use on a Raspberry Pi: [HC-SR04 Ultrasonic Range Sensor on the Raspberry Pi | The Pi Hut](https://thepihut.com/blogs/raspberry-pi-tutorials/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi)

For timing dependent stuff like this I would outsource it to a microprocessor, like a [Pico](https://core-electronics.com.au/raspberry-pi-pico.html) or use a fully baked sensor with one embeded like the [PiicoDev Distance sensor](https://core-electronics.com.au/piicodev-laser-distance-sensor-vl53l1x.html)
