Raspberry Pi Cat Poop Detector

14 posts
by joshftx » Wed Dec 19, 2012 4:36 pm
This 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: http://www.twitter.com/catpoopdetector


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

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,       “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

Posts: 10
Joined: Sun Dec 02, 2012 3:29 pm
by aTao » Wed Dec 19, 2012 4:42 pm
So.. you spent how much time and $ getting pictures of cats having a poo?
User avatar
Posts: 1053
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg
by bfagioli » Wed Dec 19, 2012 4:58 pm
Fascinating. Almost makes me want to get a cat :)
User avatar
Posts: 123
Joined: Sat Oct 27, 2012 11:49 pm
by Ravenous » Wed Dec 19, 2012 5:16 pm
Now that's what I call a "motion" sensor :oops:

Half seriously - there should be an award for the most borderline-useful raspi projects out there!
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK
by bulldog5046 » Thu Dec 20, 2012 12:43 pm
That's actually quite amusing, i could see it getting quite a following on twitter.

Can i make a suggestion? prehaps add a limiter to prevent multiple posts to twitter for the same instance. And, install an infrared light so the nighttime shots have something to see!
Posts: 36
Joined: Thu Jun 21, 2012 1:50 pm
by rurwin » Thu Dec 20, 2012 1:01 pm
There's too many pictures that are not of a cat pooping. I think you need to take one picture every five seconds while the PIR is active. Then publish the middle one.

Excellent project :D :D
User avatar
Forum Moderator
Forum Moderator
Posts: 4166
Joined: Mon Jan 09, 2012 3:16 pm
by malakai » Thu Dec 20, 2012 1:29 pm
Also how about a feeding detector that way we can get a before and after. I'm totally going to have to make one of these now. My cat will try to kill me in my sleep so I'll need two more PIR's I knew I should have gotten more than one.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)
User avatar
Posts: 1383
Joined: Sat Sep 15, 2012 10:35 am
by pygmy_giant » Thu Dec 20, 2012 1:35 pm
I could use a 'someone called at your house while you were out' alert - especially when expecting deliveries.
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am
by morphy_richards » Thu Dec 20, 2012 1:40 pm
My wife would have asked me how long it took to make a system that could detect a cat pooping event and then asked in that time how many times I could have cleaned the cat litter box myself?
She would then have told me to wash the dishes :shock:
User avatar
Posts: 1601
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
by pygmy_giant » Thu Dec 20, 2012 1:46 pm
Why not just build a robot cat - less mess
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am
by Ravenous » Thu Dec 20, 2012 1:50 pm
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK
by jrmedd » Thu Dec 20, 2012 4:01 pm
Ha! Not only is this almost identical to an idea of mine, you're testing it in the same environment that I nearly used. Bravo. My project: http://jamesmedd.tumblr.com/post/352709 ... -letterbox

(Might be useful for pygmy_giant)
Posts: 20
Joined: Mon Oct 29, 2012 3:48 pm
by pygmy_giant » Thu Dec 20, 2012 7:30 pm
Hi - on your blog you said:

For this project, yes, a switch probably would be better in order to isolate the movement of the letterbox from other movements in my hallway. However, I probably won’t be including one just yet, as the current system is mainly a test of the hardware that I plan to put inside a bird box, hopefully capturing some close-up photos of my avian neighbours.

I have spotted that PIR detector on ebay and was thinking about using it in a robot. I would like it to seek out human activity and thought maybe the combination of movement and directional sound data could be a good test.

Good luck with your bird box project - nice to have something to make us think of spring.
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am
by metracom » Sat Dec 13, 2014 12:56 am
Here's a good use for a Raspberry Pi computer. I removed the manufactures control board and integrated the Litter Robot to a Raspberry Pi. The Raspberry Pi controls the Litter Robot and sends real time twitter updates.


Posts: 1
Joined: Sat Dec 13, 2014 12:43 am