Things used in this project

Hardware components:
Pi 3 02
Raspberry Pi 3 Model B
×1
13285 01
PIR Motion Sensor (generic)
×1
11026 02
Jumper wires (generic)
×3

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

C0df83fd89633625507dfb38114ed16c
neal pence
1 project • 6 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog