cobblerPIR 300x256 How to create a Raspberry Pi Cat Poop DetectorThis started as a project to simply annoy my wife into cleaning the cat box.  Along the way, I learned quite a few good tricks.  Basically, I attached a PIR motion sensor to the raspberry pi, along with a webcam. I wrote a little python script that, when it detects motion, snaps a picture from the webcam and then tweets it and uploads it to this site:

A agzAqCQAAUVRd 300x245 How to create a Raspberry Pi Cat Poop Detector

to make it extra annoying, I also added a Prowl ( 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 Remember, you can also play free blackjack online at Intertops Casino , to help you learn the ropes. consistently get video snapshots from the webcam.  Also, certain webcams work online casino’s 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:

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:

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


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”

# Prowl it!
# p.add(“Poop Detected”,”Possible Poop Detection”,”Motion”,1, None, “”)

#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