Skip to content

Commit

Permalink
Create UltrasonicSensor_Check.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-Chowdhury21 committed Mar 28, 2023
1 parent d4a9b08 commit dccf02d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions UltrasonicSensor_Check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import RPi.GPIO as GPIO
import time
TRIG=21
ECHO=20
GPIO.setmode(GPIO.BCM)
while True:
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(0.2)
GPIO.output(TRIG,True)
time.sleep(0.00001)
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")
time.sleep(2)

0 comments on commit dccf02d

Please sign in to comment.