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

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

Similar projects you might like

Setting Up Your Pi Cap on the Raspberry Pi 1, 2 or 3
Easy
  • 64
  • 2

Protip

Follow this tutorial to set up your Pi Cap with a Raspberry Pi 1 A+/B+, Raspberry Pi 2 or Raspberry Pi 3.

Setting Up Your Pi Cap on the Raspberry Pi Zero
Easy
  • 72
  • 2

Protip

Follow this tutorial to set up your Pi Cap with a Raspberry Pi Zero.

Secure Simple Remote Access for Camera Viewing
Easy
  • 2,001
  • 8

Full instructions

Turn your RPi into a full featured camera with remote access, end2end encryption, and easy user enrollment.

PiCorder
Easy
  • 3,606
  • 14

Full instructions

A simple Pi-based camcorder using the very nice HyperPixel touchscreen from Pimoroni.

RPi Serial Console Automation using Arduino
Easy
  • 234
  • 3

Full instructions

A follow-up article to "One Button Restart of a Stalled Raspberry Pi": 3 digital pins provide 8 separate functions that can be called.

Run uTorrent on Raspberry Pi
Easy
  • 467
  • 2

Protip

Step-by-step instruction of running uTorrent on Raspberry Pi 2 using ExaGear Desktop.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login