Question: Rasberry Pi HELP! So I am working on a code for ultrasonic sensor that should get the speed of an object. Everything on breadboard is

Rasberry Pi HELP! So I am working on a code for ultrasonic sensor that should get the speed of an object. Everything on breadboard is set up correct. ive tried multiple breadboard and sensors so its not that. and the code did at one point but no longer does and I cant figure it out.
'import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
TRIG = 17
GPIO.setup(TRIG,GPIO.OUT)
ECHO = 16
GPIO.setup(ECHO,GPIO.IN)
def measure_distance():
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)
if distance > 2 and distance
print("Distance:",distance - 0.5,"cm")
else:
print("Out Of Range")
return distance
def get_speed(distance, time):
speed = (distance / 3600)
return speed
while True:
distance = measure_distance()
print("Distance: %.2f" % distance)
time.sleep(1)
speed = get_speed(distance, time)
print("Speed: %.2f m/s" % speed)
time.sleep(1)
GPIO.cleanup()'
Rasberry Pi HELP! So I am working on a code for ultrasonic
sensor that should get the speed of an object. Everything on breadboard
is set up correct. ive tried multiple breadboard and sensors so its

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!