SEN0151 URM06 Pulse Ultrasonic Sensor With RaspberryPi

userHead Mehmet AliTor 2022-06-21 18:33:46 405 Views1 Replies

Hi, 

I want to use my SEN0151 URM06 Pulse Ultrasonic Sensor with RaspberryPi 3B+. 

However, I couldn't write a proper python code that would make the sensor work correctly. 

With the code I wrote below, the sensor stops after about 3-5 minutes. I couldn't understand why. 

<code>

import RPi.GPIO as GPIO

import time
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

TRIG = 23
ECHO = 24

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

GPIO.output(TRIG, True)

while True:
   time.sleep(2)
   GPIO.setup(TRIG,GPIO.OUT)
   GPIO.setup(ECHO,GPIO.IN)

   GPIO.output(TRIG, False)
   time.sleep(0.0005)
   GPIO.output(TRIG, True)
   time.sleep(0.0005)
   GPIO.output(TRIG, False)
   print ("dalga gonderildi")

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

   while GPIO.input(ECHO)==1:
       continue
   pulse_end = time.time()
   
   print ("olculdu")
   pulse_duration = pulse_end - pulse_start

   mesafe = pulse_duration*100000
   print(mesafe)

</code>

 

I would like your help for a RaspberryPi code similar to the example arduino application in the link below.

https://wiki.dfrobot.com/URM06-PULSE_Ultrasonic_SKU_SEN0151

2022-06-23 16:44:17

Hi! Did you buy only one module? Does the same code work fine on another sensor?

userHeadPic Tonny12138