, Raspberry Pi Motion Detector Code
from gpiozero import MotionSensor
from picamera import PiCamera
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
import datetime
import time
import smtplib
#Email Addresses
FromAddress =
ToAddress =
#Finds Motion Sensor and Camera
PIRSensor = MotionSensor(4)
camera = PiCamera()
#Exit While loop
Tripped = True
#Wait Five Seconds
time.sleep(5)
while Tripped:
if PIRSensor.motion_detected:
print("Motion Detected")
#Take a Picture
Tripped = False
TimeCaptured = “/home/pi/Desktop” + datetime.datetime.now().strftime(“%Y-%m-
%d%H:%M:%S”) + “.png”
camera.rotation = 180
camera.capture(TimeCaptured)
print("Image Taken")
#Create the Message
msg = MIMEMultipart()
msg[ “Subject”] = “Intruder”
msg[“From”] = FromAddress
msg[“To”] = ToAddress
#Attach the File
File = open(TimeCaptured, “rb”)
img = MIMEImage(File.read())
File.close()
msg.attach(img)
# Log in Details for FromAddress
username=“”
password=“1999hot”
# The Email Sends from a Microsoft Account
server = smtplib.SMTP(“smtp-mail.outlook.com:587”)