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.

EasyFull instructions provided1 hour16,452
Raspberry Pi Controlled PIR Sensor with Email Notifications

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×3

Story

Read more

Schematics

Raspberry Pi 40 pin schematic

Use to locate GND, 5V, and GPIO4
40%20pin%20schematic

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 • 7 followers
Contact

Comments