Last active
May 12, 2017 15:12
-
-
Save AO8/39d0d63d3d53e7bd6bc24e506d13c73a to your computer and use it in GitHub Desktop.
Use a PIR sensor, Raspberry Pi, and PiCamera to detect motion, take a timestamped photo, then send a text message alert from Gmail with Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Allow less secure apps to access your Gmail account | |
# https://en.wikipedia.org/wiki/List_of_SMS_gateways | |
# [email protected] for AT&T | |
# [email protected] for Sprint | |
# [email protected] for T-Mobile | |
# [email protected] for Verizon | |
from gpiozero import MotionSensor | |
from picamera import PiCamera | |
from datetime import datetime | |
import smtplib | |
camera = PiCamera() | |
pir = MotionSensor(4) # GPIO pin on Raspberry Pi | |
while True: | |
pir.wait_for_motion() | |
filename = datetime.now().strftime("%m-%d-%Y_%H.%M.%S.jpg") | |
camera.capture(filename) | |
pir.wait_for_no_motion() | |
username = "[email protected]" | |
password = "yourPassword" | |
server = smtplib.SMTP("smtp.gmail.com:587") | |
server.starttls() | |
server.login(username, password) | |
server.sendmail(username, "[email protected]", "Warning! Motion detected!") | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment