Advertisement
Dayni

Sensors

Dec 15th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import picamera # Importing the library for camera module
  2. from time import sleep
  3. import RPi.GPIO as GPIO
  4. import time
  5. import test
  6.  
  7. GPIO.setmode(GPIO.BCM)
  8. GPIO.setwarnings(False)
  9.  
  10. GPIO.setup(26, GPIO.IN) #PIR
  11. GPIO.setup(25, GPIO.IN) # Door Switch1
  12. GPIO.setup(24, GPIO.IN) # Door Switch2
  13. GPIO.setup(12, GPIO.OUT) #Buzzer
  14.  
  15.  
  16. try:
  17. time.sleep(2) # to stabilize sensor
  18. while True:
  19. if GPIO.input(26):
  20. GPIO.output(12, True)
  21. time.sleep(1) #Buzzer turns on for 2 sec
  22. GPIO.output(12, False)
  23. print("Motion Detected...")
  24. time.sleep(1) #to avoid multiple detection
  25. time.sleep(0.1) #loop delay, should be less than detection delay
  26. camera = picamera.PiCamera() # Setting up the camera
  27. sleep(2)
  28. camera.capture('/home/pi/Downloads/imag1.jpg') # Capturing the image
  29. camera.close()
  30. time.sleep(1) #loop delay, should be less than detection delay
  31. exec(open("test.py").read())
  32.  
  33.  
  34. if GPIO.input(25):
  35. GPIO.output(12, GPIO.LOW)
  36.  
  37. else:
  38. GPIO.output(12,GPIO.HIGH)
  39. print("Door is opened....")
  40. time.sleep(1) #to avoid multiple detection
  41.  
  42. if GPIO.input(24):
  43. GPIO.output(12, GPIO.LOW)
  44.  
  45. else:
  46. GPIO.output(12,GPIO.HIGH)
  47. print("Window is opened....")
  48. time.sleep(1) #to avoid multiple detection
  49.  
  50. except:
  51. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement