The Oscar Detector

kooks

I have always used the cat and turtles as catalysts for different projects. I thought this would be a good one because I hadn’t done much with the raspberry pi camera that I had, and I also wanted to work on using the GPIO pins on the raspberry pi to read sensor data.  This was another good project to practice writing code in python on the pi.  The concept: detect the cat, take his picture, tweet his picture (@KookieHouse).

initial setup and design

I ran a survey asking people where they thought I should put the Oscar detector. Above the cat tower won by a wide margin, but I ran into a couple of issues putting it there which I will explain later. The original design was simple, using the new incredibly small raspberry pi A+, an ultrasonic sensor and the raspberry pi camera. I mounted the system on the wall and aimed the sensor and camera and began my testing. Things weren’t working very well. The idea was to aim the device at a spot I know the cat sits in. Then the distance is measured at a set time interval, and when the cat is there, the distance will be shorter.

IMG_20150130_172701 IMG_20150130_172716

The system worked flawlessly during initial program testing using my hand, but in the new spot it wasn’t working at all. I looked at the distance output and it was reading the maximum distance it can measure. It would detect my hand if it was in the line of sight though, so I figured I could still make it work. Then I tried testing it with the cat.

engineering challanges

Ultrasonic, or sonar sensors are very simple in principal. They use a transmitter to send out an acoustic signal and then read the signal back with a receiver. To trigger it, a pulse is sent to the trigger pin on the sensor. The time is measured on the microcontroller (raspberry pi in my case) between when the signal is transmitted, bounces off of something and is received back. The time between the send and receive can then be converted to distance because we know how fast sound travels through air. This is a good sensor to use with a pi because it’s a digital sensor and pi is not capable on its own of handling an analog sensor.

The problem with acoustic signals, is that they don’t bounce off of everything. Two of these things, unfortunately, are carpet covered cat towers and cats. The signal gets absorbed by everything I am trying to measure, and therefore cannot measure anything.

My next plan was to move the sensor to the food area. I could consistently measure the distance between the sensor and the wall. When the cat got in between the sensor and the wall, the sensor would show the max reading that we all know and love. This worked to sense the cat, but it didn’t actually measure how far away the cat was. It was fine for my setup though.

tweeting using a raspberry pi

The next challenge was to get the raspberry pi to take and tweet the cat’s picture once detected. Taking pictures with the pi is very easy with the raspberry pi camera module, so that never proved to be a challenge. Tweeting was a bit more difficult. I found a great article (here) describing what it takes to get a tweet from the pi to the internet using python. Once I got that working, I found another article from the same blog (here) explaining how to get a picture tweeted. The library used to do all of this fun stuff is called Tweepy. Check them out.

early results

I set up the twitter account with the handle @KookieHouse. Kookie is Oscar’s nickname, and I thought house would be good because I could expand the system if I wanted to. I am currently testing the second camera with Yoshi the turtle right now, but that we can talk about later.

IMG_20150201_002724

The Oscar detector was working fairly well, but the problem with sound is that it has no idea how much light is around. That is a problem when you are trying to take pictures of things. Also, since I couldn’t actually measure distance, I had to just say that Oscar was eating or drinking something. What this amounted to were pictures that were sometimes completely dark, and captions that all read “im eating or drinking something! “. I decided to take the system to the NEXT LEVEL.

adding an arduino, an IR rangefinder and a photoresistor

I decided to improve the system by adding an arduino to the equation. Arduinos can read in analog signals, so I could switch my distance measuring device to that of the infrared kind. This is a light based system, so as long as nothing is black, we are good to go. There is a really good simple explanation here on how those work. I also added a photoresistor which allowed me to only trigger pictures if there was enough light.

Processed with VSCOcam

The arduino program looks at the sensor readings and determines if the cat is there, and if he is, how far away. This allows me to figure out whether he is eating or drinking. If he is eating, it sends a signal from one digital pin. If he is drinking, it sends a signal from the other one. These signals are read by the pi which then tweets appropriately. One issue that has come up repeatedly is the issue of false detection. I believe it has something to do with sunlight but I haven’t gotten around to figuring it out yet.

current system status

Since February 1, the Oscar detector has tweeted close to 400 times. As you can imagine, there is a lot of redundancy in the pictures. Every once in a while you get a gem like the one at the top of the post, but they are mostly just him with his face in his food bowl. I re-positioned the camera a while back but it was still the same idea. Currently I am trying to think of a way to make it a little funnier or more interesting. Here is the circuit:

oscar detector_bb

The yoshi iteration of this setup is in the final stages of testing, and it is also incorporated with a water temperature and level detection system that integrates into my home automation setup. That post will be forthcoming. The python code and arduino program are in my github repository.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s