to make it extra annoying, I also added a Prowl (http://www.prowlapp.com/) alert as well so that it actually rings her phone when motion is sensed. The prowl link, takes you straight to the twitter account to view the offending picture.
I found that using wifi, I needed both a strong power adapter and a powered hub in order to consistently get video snapshots from the webcam. Also, certain webcams work better than others. You can see a basic wiring diagram at the top. Not sure if it matches my code below. Just make sure you put the Motion Detectors data line on the same pin you specify in code.
You could easily use this as a home motion detector/burlgar alarm. Next step is to get it to automatically turn the light on and off in there.
Here’s the sensor I used:
http://www.amazon.com/gp/product/B007XQ ... 00_s00_i00
Here’s the code. You’ll need to grab prowlpy and Twython python bits and fswebcam for linux (apt-get install fswebcam) in order for this to work. My indenting may be off from the copy/.paste:
Code: Select all
import RPi.GPIO as GPIO import time import sys import prowlpy import os from twython import Twython #set your prowl API key here apikey = ‘YOUR PROWL KEYb’ #Dummy API-key p = prowlpy.Prowl(apikey) #Set the GPIO pin (board numbering) for the PIR PIR = 11 pirState = False pirVal = False GPIO.setmode(GPIO.BOARD) GPIO.setup(PIR, GPIO.IN) while True: pirVal = GPIO.input(PIR) if (pirVal == True): #use this to sound an alarm if you have speakers # os.system(‘mpg321 ./alarm.mp3′) #if motion is detected, check one more time to be sure pirVal2 = GPIO.input(PIR) if (pirVal2 ==True): print “Alarm” try: # Prowl it! # p.add(‘Poop Detected’,'Possible Poop Detection’,”Motion”,1, None, “http://www.twitter.com/catpoopdetector”) #grab a snapshot os.system(“fswebcam /home/pi/scripts/test.jpg”) #tweet it! twitter = Twython( twitter_token = ‘YOUR TOKEN’, twitter_secret = ‘YOUR SECRET’, oauth_token = ‘YOUR TOKEN’, oauth_token_secret = ‘YOUR SECRET’ ) twitter.updateStatusWithMedia(‘/home/pi/scripts/test.jpg’, status=’I just pooped’) except Exception,msg: print msg #wait and do it again time.sleep(25)