0

I'm trying to configure US100 ultrasonic distance sensor on my raspberry pi device. I'd follow the approach described in this link but not getting any output from the device.

I'm sharing my code too so that if anyone can find what I'm doing wrong in any of the cases.

import RPi.GPIO as GPIO
import time
import logging

LOG_FILENAME='US_100.log'
logging.basicConfig(format='%(asctime)s %(message)s',filename='US_100',
level=logging.DEBUG)


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
TRIG = 18
ECHO = 24
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
while True:
    GPIO.output(TRIG,False)
    time.sleep(1.5)
    print("Waiting for sensor to settle")
    GPIO.output(TRIG,True)
    time.sleep(0.0001)
    GPIO.output(TRIG, False)
    pulse_start=time.time()

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

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

    pulse_duration = (pulse_end-pulse_start)
    print("Pulse duration =%1f " %pulse_duration)
    distance = (pulse_duration*343/2)
    if distance >0.5 and distance <400:
        print("Distance = %1f" %distance)
    else:
        print("Out of Range")

    logging.debug(distance)
James Z
  • 12,209
  • 10
  • 24
  • 44
Apoorv Mishra
  • 1,489
  • 1
  • 8
  • 12
  • What voltage does the US100 sensor take? Is it 3V3 logic, or 5V? With the HC-SR04, it's 5V so you need a voltage divider to take it down to 3V3 level. Some are 3V3 so you won't need any resistors. I googled the US100 and it's got an extra pin, looks like 2 GND pins from the picture, so it's definitely not identical. – ben_nuttall Mar 15 '19 at 00:21
  • Also try the built-in DistanceSensor class in gpiozero: https://gpiozero.readthedocs.io/en/latest/api_input.html#gpiozero.DistanceSensor – ben_nuttall Mar 15 '19 at 00:21
  • I've connected resistors to for lowering down the voltage level to 3V3 level. I've tried the DistanceSensor class but got no result with the same. I've also tried UART ports for the US100 but that didn't work either. – Apoorv Mishra Mar 15 '19 at 06:23

0 Answers0