Welcome back friends!!!
Now let's move on to the ultrasonic interfacing with raspberry pi
import RPi.GPIO as GPIO #Imporing GPIO module
import subprocess #Importing Sub-process Modules, which will be discussed later
import time #Importing time modules
GPIO.setmode(GPIO.BCM) # Setting up a mode of operation
TRIG = 23 # Assigning a pin no. for Trigger
ECHO = 24 # Assigning a pin no. for Echo
GPIO.setup(TRIG,GPIO.OUT) # Setting up a trigger pin
GPIO.setup(ECHO,GPIO.IN) # Setting up a echo pin
GPIO.output(TRIG, False)
print "Waiting For Sensor To Settle"
time.sleep(2) # Wait for 2 seconds
while(True): # Start a loop to process this continuously
GPIO.output(TRIG, True) # Start a trigger
time.sleep(0.00001) # To make the trigger i frequency
GPIO.output(TRIG, False) # Stop a trigger
while GPIO.input(ECHO)==0: # loop to check the status of echo pin
pulse_start = time.time() # Note the initial pulse release time
while GPIO.input(ECHO)==1: # loop to check the status of echo pin again
pulse_end = time.time() # Note the final pulse reach time
pulse_duration = pulse_end - pulse_start # finding the travel time of a pulse by taking difference
distance = pulse_duration*17150 # calculating distance
distance = round(distance, 2) # rounding off
print "Distance:",distance,"cm" # printing Output
GPIO.cleanup()
Execute this program as like the previous one
for any doubts and more explanation
comment me!!!!
Thank you
bye
----
Arun
Now let's move on to the ultrasonic interfacing with raspberry pi
import RPi.GPIO as GPIO #Imporing GPIO module
import subprocess #Importing Sub-process Modules, which will be discussed later
import time #Importing time modules
GPIO.setmode(GPIO.BCM) # Setting up a mode of operation
TRIG = 23 # Assigning a pin no. for Trigger
ECHO = 24 # Assigning a pin no. for Echo
GPIO.setup(TRIG,GPIO.OUT) # Setting up a trigger pin
GPIO.setup(ECHO,GPIO.IN) # Setting up a echo pin
GPIO.output(TRIG, False)
print "Waiting For Sensor To Settle"
time.sleep(2) # Wait for 2 seconds
while(True): # Start a loop to process this continuously
GPIO.output(TRIG, True) # Start a trigger
time.sleep(0.00001) # To make the trigger i frequency
GPIO.output(TRIG, False) # Stop a trigger
while GPIO.input(ECHO)==0: # loop to check the status of echo pin
pulse_start = time.time() # Note the initial pulse release time
while GPIO.input(ECHO)==1: # loop to check the status of echo pin again
pulse_end = time.time() # Note the final pulse reach time
pulse_duration = pulse_end - pulse_start # finding the travel time of a pulse by taking difference
distance = pulse_duration*17150 # calculating distance
distance = round(distance, 2) # rounding off
print "Distance:",distance,"cm" # printing Output
GPIO.cleanup()
Execute this program as like the previous one
for any doubts and more explanation
comment me!!!!
Thank you
bye
----
Arun
No comments:
Post a Comment