Evan Rust
Published © GPL3+

Raspberry Pi Texting Intruder Alarm!

Make your raspberry pi text you if it senses an intruder in a set amount of time using a simple PIR sensor and internet connection!

BeginnerFull instructions provided1 hour10,271
Raspberry Pi Texting Intruder Alarm!

Things used in this project

Hardware components

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

Software apps and online services

Python IDLE (on Raspberry Pi)

Story

Read more

Schematics

Schematic

Just connect!

Code

The Raspberry Pi Code

Python
Copy and Paste
import time
import smtplib
import RPi.GPIO as GPIO

TO= "your phone # as a carrier email address: 'phone#@txt.att.net' for \ example" #all of the credentials
GMAIL_USER="your GMAIL account email address"
PASS= 'your account password'

SUBJECT = 'Alert!'
TEXT = 'Your Raspberry Pi detected an intruder!'

GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)

def send_mail(): #the texting portion
    print "Sending text"
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(GMAIL_USER,PASS)
    header = 'To: ' + TO + '\n' + 'From: ' + GMAIL_USER
    header = header + '\n' + 'Subject: ' + SUBJECT + '\n'
    print header
    msg = header + '\n' + TEXT + '\n\n'
    server.sendmail(GMAIL_USER,TO,msg)
    server.quit()
    time.sleep(1)
    print "Text sent"

while True:
    if GPIO.input(4)==1: #trigger if sensor has detected something
        send_mail()
        time.sleep(60*2) #Sleep for 2 minutes
    else:
        time.sleep(5) #check every 5 seconds

Credits

Evan Rust

Evan Rust

122 projects • 1080 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments