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

Chicken Coop Livestream
Easy
  • 2,711
  • 10

Full instructions

We have two chickens, and their coop is located at the back of the garden. I decided to build a Pi-based streaming device to check on them.

Test Your Internet Speed Using a Raspberry Pi + Ubidots
Easy
  • 371
  • 5

Protip

Use your Raspberry Pi to measure any internet connection speed with Ubidots.

Raspberry Pi Shutdown / Restart Button
Easy
  • 5,306
  • 20

Full instructions

Building an installation project? Shut down or reboot your project safely, without a keyboard or SSH!

DIY Raspberry Pi Indoor Outdoor Webcam
Easy
  • 1,560
  • 6

Full instructions

Ever want to monitor your home but don't want to buy a $100 1080p webcam? Well I did, and you can too!

3D Printed Case for a RaspPi 3, an Arduino and a 5" Display
Easy
  • 332
  • 4

Full instructions

A simple and compact frame to mount a 5" monitor, a Raspberry Pi, an Arduino, and a battery, which is extensible for other sensors.

Single Device to Control Many Arduinos with NRF24L01+ Sensor
Easy
  • 1,489
  • 8

Turns your fan on and off by sensing the temperature.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog