Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gpiozero import DigitalInputDevice # import library for microwave sensor
- from time import sleep # library for timer
- import time
- import datetime # import datetime
- from picamera import PiCamera # import Pi Camera
- import RPi.GPIO as GPIO # library for input/output pins
- import smtplib
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(27, GPIO.OUT) # BUzzer at port 23
- GPIO.setup(17, GPIO.IN) #MICROWAVE SENSOR
- #radar = DigitalInputDevice(17, pull_up=False, bounce_time=2.0) # Microwave sensor input at port 17
- camera = PiCamera() # create camera object
- camera.resolution = (1024, 768) # set camera resolution
- server = smtplib.SMTP_SSL('smtp.mail.yahoo.com', 465)
- server.connect('smtp.mail.yahoo.com', 465)
- server.login('pythonalert96@yahoo.com', '!QAZ@WSX')
- # capture picture and give timestamp
- def detector():
- print("Motion detected")
- timestamp = str((datetime.datetime.now()))
- timestamp = timestamp[0:19]
- print("Image captured at",timestamp)
- camera.capture(timestamp+".jpg")
- sleep(2)
- GPIO.output(27, GPIO.HIGH) #trigger buzzer/led
- sleep(0.2)
- GPIO.output(27, GPIO.LOW)
- server.sendmail('pythonalert96@yahoo.com', 'aisyahkarim184@gmail.com', 'testing')
- try:
- while True:
- if GPIO.input(17) == 1: #if microwave sensor detect movement
- detector()
- #radar.when_activated = detector #activate sensor
- # GPIO.output(23, GPIO.HIGH) # buzzer sound for 0.2 seconds
- # sleep(0.2)
- # GPIO.output(23, GPIO.LOW) # buzzer sound stop after 2 seconds
- print("No motion detected...")
- time.sleep(2) #to avoid multiple detection
- except:
- GPIO.cleanup()
- camera.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement