neal pence
Published © GPL3+

Raspberry Pi Controlled PIR Sensor with Email Notifications

This project will cover the assembly and coding of a PIR sensor and Email notifications through Gmail with a basic subject line.

BeginnerFull instructions provided1 hour27,391
Raspberry Pi Controlled PIR Sensor with Email Notifications

Things used in this project

Story

Read more

Schematics

Raspberry Pi 40 pin schematic

Use to locate GND, 5V, and GPIO4

Code

Code

Python
Just copy and paste once you have created a new python file.
import RPi.GPIO as GPIO
import time

sensor = 4

GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)

previous_state = False
current_state = False

while True:
    time.sleep(0.1)
    previous_state = current_state
    current_state = GPIO.input(sensor)
    if current_state != previous_state:
        new_state = "HIGH" if current_state else "LOW"
        print("GPIO pin %s is %s" % (sensor, new_state))
        import smtplib
 
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login("from_email_address", "from_email_password")
 
        msg = "INTRUDER!"
        server.sendmail("from_email_address", "to_email_address", msg)
        server.quit()

Credits

neal pence

neal pence

1 project • 13 followers

Comments