Saturday, December 29, 2012

Automated Cat Feeder w/ Android App





Problem: My cat Ten-Ten was starving while waiting for me to come home from work to feed him.

Solution: An automated dry cat food and water dispensing system that dispenses food and water on a timer at different times during the day. In version 1.0 of the system, I used an Arduino microcontroller and added a web server module, an LCD module, and an Android mobile application to act as an user interface between my cat and myself. In version 2.0, I ported the entire system to a Raspberry Pi microcontroller and rewrote everything on the backend. As part of the port, I replaced the LCD module with a web application, as well as added other features.



*Version 1.0:

For the food dispensing component, I found a brilliant design here, which used a low RPM high torque motor to rotate a cereal dispenser knob to dispense dry food. Instead of reinventing the wheel, I decided to replicate it.


First, I stabilized the food container base and motor base.


Then, I opened up a hole for the food to fall out from the bottom of the container the dispenser is housed in and hooked up the ~$15 motor I bought online.




For the water dispensing component, I couldn't find anything on the web that fit my taste, so I had to come up with something myself. During the design phase, I went through many iterations. At the end, I settled on using a cheap 350GPH water pump to pump water from a low pressure tubing to a high pressure tubing, which fed into Ten-Ten's dish:



With the mechanics done and enclosed in a plastic drawer container, I used a mosfet tutorial to wire up a mosfet circuit to the knob rotating motor/water pump and my Arduino microcontroller so I could turn the two motors on and off by sending a digital signal from my microcontroller to the circuit. At this point, I slapped some code onto the Arduino using a couple of their open source libraries and I had a working prototype that fed my cat at 9:30am, 2:30pm, and 6:30pm. Now I wanted a cool interface to go along with this project. So I added an ethernet shield to the Arduino and some code to allow the Arduino to serve HTTP requests. With this live on my local network, I built an Android mobile application that would make HTTP requests to ask the Arduino to dispense food and/or water. In addition to this, I also added an LCD module with buttons and some code behind that allowed me to navigate a virtual menu with the buttons, which allowed me to do the same as the mobile app. In hindsight, I realized that adding the LCD module with buttons was a very low return investment because I almost always resorted to the mobile application and never to the LCD module. Here's the system in action:






*Version 2.0:

After using this system for about 4 months on a daily basis, I decided I wanted to make some modifications to it. First, I wanted to get rid of the LCD module and replace it with a web application. Secondly, I wanted to collect logs of when Ten-Ten was given food/water and publish the same logs to Twitter so I can access them anywhere. Because of the amount of code I needed to add in order to make these modifications, I realized that I couldn't use the Arduino due to memory constraints, so I decided to go with a Raspberry Pi.

With a LAMP stack running Debian Linux installed on the Raspberry Pi, I rewrote all the backend code to work with the Pi then modified the Android app slightly so it would be compatible with both the Arduino and Raspberry Pi. Now, whenever Ten-Ten is given food and/or water through the cat feeder, that information is logged into a local MySQL database and published to Twitter. Here's the result of the modifications and hard work:


Web app
Modified backwards compatible Android app

Next step: use Twitter as a control source to feed Ten-Ten.


References:
http://arduino.cc/en/Reference/HomePage
http://arduino.cc/en/Reference/Libraries
http://www.newtonnet.co.uk/catfeeder/
http://bildr.org/2012/03/rfp30n06le-arduino/
http://elinux.org/RPi_Beginners
https://projects.drogon.net/raspberry-pi/wiringpi/
https://dev.twitter.com/docs/twitter-libraries
http://developer.android.com/reference/packages.html