Arduino “having11” Guy
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!

EasyFull instructions provided1 hour5,118
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!
Rpi intruder bb

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

Arduino “having11” Guy

Arduino “having11” Guy

39 projects • 256 followers
IoT, Arduino, and Raspberry Pi. I can create designs, code, and build projects for only $22/hr. Just message me with your project request.

Comments