raspberry gpio tutorial 5...control LED using ultrasonic in tamil
python codings
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
led = 17
echo = 4
trig = 18
GPIO.setup(echo , GPIO.IN)
GPIO.setup(led , GPIO.OUT)
GPIO.setup(trig , GPIO.OUT)
while 1:
GPIO.output(trig ,True)
time.sleep(0.00001)
GPIO.output(trig ,False)
while GPIO.input(echo) == False:
srt = time.time()
while GPIO.input(echo) == True:
end = time.time()
duration = end - srt
distance_cm = duration/0.000058
print distance_cm
if distance_cm < 10:
GPIO.output(led , GPIO.HIGH)
else :
GPIO.output(led , GPIO.LOW)
time.sleep(.1)
************************************************************
copy that and upload in your python idle
Comments
Post a Comment