import RPi.GPIO as GPIO
import time

sensor = 16
buzzer = 18

GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(buzzer,GPIO.OUT)

GPIO.output(buzzer,False)
print ("IR Sensor Ready.....")

try: 
   while True:
      if GPIO.input(sensor):
          GPIO.output(buzzer,True)
          print ("Object Detected")
          while GPIO.input(sensor):
              time.sleep(0.1)
      else:
          GPIO.output(buzzer,False)


except KeyboardInterrupt:
    GPIO.cleanup()
