Advertisement
Guest User

Untitled

a guest
Nov 25th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. from gpiozero import DigitalInputDevice # import library for microwave sensor
  2. from time import sleep # library for timer
  3. import time
  4. import datetime # import datetime
  5. from picamera import PiCamera # import Pi Camera
  6. import RPi.GPIO as GPIO # library for input/output pins
  7. import smtplib
  8.  
  9. GPIO.setmode(GPIO.BCM)
  10. GPIO.setup(27, GPIO.OUT) # BUzzer at port 23
  11. GPIO.setup(17, GPIO.IN) #MICROWAVE SENSOR
  12. #radar = DigitalInputDevice(17, pull_up=False, bounce_time=2.0) # Microwave sensor input at port 17
  13. camera = PiCamera() # create camera object
  14. camera.resolution = (1024, 768) # set camera resolution
  15.  
  16. server = smtplib.SMTP_SSL('smtp.mail.yahoo.com', 465)
  17. server.connect('smtp.mail.yahoo.com', 465)
  18. server.login('pythonalert96@yahoo.com', '!QAZ@WSX')
  19.  
  20. # capture picture and give timestamp
  21. def detector():
  22.     print("Motion detected")
  23.     timestamp = str((datetime.datetime.now()))
  24.     timestamp = timestamp[0:19]
  25.     print("Image captured at",timestamp)
  26.     camera.capture(timestamp+".jpg")
  27.     sleep(2)
  28.     GPIO.output(27, GPIO.HIGH) #trigger buzzer/led
  29.     sleep(0.2)
  30.     GPIO.output(27, GPIO.LOW)
  31.     server.sendmail('pythonalert96@yahoo.com', 'aisyahkarim184@gmail.com', 'testing')
  32. try:
  33.     while True:
  34.         if GPIO.input(17) == 1: #if microwave sensor detect movement
  35.             detector()
  36.         #radar.when_activated = detector #activate sensor
  37.         # GPIO.output(23, GPIO.HIGH) # buzzer sound for 0.2 seconds
  38.         # sleep(0.2)
  39.         # GPIO.output(23, GPIO.LOW) # buzzer sound stop after 2 seconds
  40.         print("No motion detected...")
  41.         time.sleep(2) #to avoid multiple detection
  42. except:
  43.     GPIO.cleanup()
  44.     camera.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement