Twitter Controlled Pet Feeder

by amandaghassaei in Circuits > Arduino

70763 Views, 230 Favorites, 0 Comments

Twitter Controlled Pet Feeder

main.jpg
IMG_3303 copy.jpg
peanut.jpg

A great project for busy pet owners. This Twitter-Controlled pet feeder automatically dispenses food in response to activity on your Twitter account. The project is controlled by an Arduino and uses the Arduino Ethernet shield to receive data from Twitter. I hacked this automatic Pet Feeder from Amazon to build this project, but you could easily modify your own motorized feeder to work.

Parts List:

(1x) Automatic Pet Feeder Amazon
(2x) 10K Ohm 1/4-Watt Carbon Film Resistor (1 package) Radioshack #271-1335
(1x) Arduino Ethernet Shield Radioshack #276-130
(4x) CdS Photoresistors 5 pack (1 package) Radioshack #276-1657
(1x) Grid-Style PC Board Radioshack #276-147
(2x) White Super-bright LED Indicator Radioshack #55050633
(1x) Male Header Pins 40 Position Jameco #160882
(4x) "D" Alkaline Batteries (1 package) Radioshack #23-865
(2x) 4.7K Ohm 1/4-Watt Carbon Film Resistor (1 package)
(2x) current limiting resistors, see the sample calculation below

from the specs of the LEDs I used:
"Continuous forward current: 30mA"
"Forward voltage: 3.6V"

using the following relationship:
V(volts) = I(amps) * R(ohms)
rearranged to:
R = V / I

we can calculate the resistance as follows:
voltage across resistor = 5V - 3.6V = 14V
1.4V / 0.03A = 47ohms

I used 100 ohm 1/4W 5% Carbon Film Resistors Radioshack #271-1311 so that the LEDs wouldn't be operating at their maximum ratings. Check the datasheet of the LEDs you use to calculate these values.

Additional Materials:
drill
Solder Radioshack #64-013
22 Gauge Wire Radioshack #278-1224

Open Pet Feeder

IMG_3103 copy.jpg
IMG_3104 copy.jpg
Unscrew 8 screws from the base of the pet feeder and carefully lift the bottom panel of the feeder open.  There are some wires which permanently attach the bottom panel to the body, be careful not to put too much strain on them.

Unscrew Pcb

IMG_3111 copy.jpg
IMG_3117 copy.jpg
Remove six small screws from control pcb.  One of the screws is hidden under a small pcb on top of the main pcb.  Once all the screws are removed, the pcbs should easily lift off the plastic enclosure.

Schematic

Screen shot 2012-05-04 at 5.11.57 PM.png
Screen shot 2012-05-04 at 5.36.44 PM.png

The schematic is shown above, I've also attached a fritzing document for your reference. This feeder is programmed to manually dispense food when the "set" and "volume" buttons are depressed at the same time. By wiring light sensitive resistors across these buttons we can simulate the mechanical pushbutton action as follows:
When the photoresistors are not exposed to light their resistance will be very high and the processor in the feeder will think that the buttons aren't being pressed. By telling the arduino to light up some LEDs near the photoresistors, the resistance will decrease low enough for the feeder's processor to think that the buttons are being depressed.
I've also attached two pushbuttons in the circuit so that I could manually turn the LEDs on for troubleshooting purposes. These buttons are not essential to the project (but useful).
I also be diverted some power from the feeder's four D batteries to power the arduino.

Downloads

Drill Holes in Pcb

IMG_3127 copy.jpg
IMG_3124 copy.jpg
IMG_3133 copy.jpg
Locate the "volume" and "set" buttons on the pcb (compare with the labels on the outside of the feeder enclosure).  Remove the tape and small circular metal covering from these buttons (figure 2).  You will see two exposed traces on each button.  Each outer trace has two holes drilled in it (see figure 1).  Drill two additional holes in the pcb, one in each of the inner circular button traces (figure 3).

Solder Wires to Pcb

IMG_3123 copy.jpg
IMG_3135 copy.jpg
Solder four wires to the control pcb so each of the four exposed button traces has one wire electrically connected to it.

Screw Pcb Back Onto Enclosure

IMG_3140 copy.jpg
Screw the control pcb back onto the feeder enclosure.

Solder Header Pins on Protoboard

IMG_3141 copy.jpg
IMG_3142 copy.jpg

The protoboard will house the circuitry that allows the arduino to interface with the feeder's control pcb. This board will attach directly to the pins on the arduino ethernet shield. Solder header pins to the protoboard so that it can snap into the power, analog, and digital 0-7 pins on the arduino ethernet shield.

Solder White LEDs and Current Limiting Resistors

IMG_3146 copy.jpg
IMG_3145 copy.jpg
IMG_3148 copy.jpg
IMG_3149 copy.jpg
IMG_3152 copy.jpg
IMG_3153 copy.jpg
IMG_3155 copy.jpg
IMG_3154 copy.jpg
Solder two 100ohm resistors to the protoboard.  One resistor should be electrically connected to the header pin for arduino digital pin 2 and the other resistor to digital pin 3 (figure 2).  Bend the leads of two white LEDs and solder to the copper side of the protoboard as shown in figures 3 and 4.  Solder a (red) jumper wire between each of the 100ohm resistors and the anodes of each of the white LEDs (figures 5 and 6).  Solder two (black) jumper wires between the cathodes of both LEDs and the to arduino ground (figure 7 and 8).

Solder Resistors and Photoresistors to Protoboard

IMG_3158 copy.jpg
IMG_3156 copy.jpg
IMG_3159 copy.jpg
IMG_3160 copy.jpg
IMG_3161 copy.jpg
IMG_3162 copy.jpg
IMG_3163 copy.jpg
IMG_3164 copy.jpg

Solder one large and one small photoresistor (from the set of five) in series on the protoboard (make sure they are on the same side as the LEDs). Bend the leads of the photoressitros so that they are pointed directly at one of the LEDs. Solder a 4.7kOhm and 10kOmh resistor in series with these two photoresistors (fig 4).

Repeat these steps for the second LED.

Attach to Feeder PCB

IMG_3165 copy.jpg
IMG_3166 copy.jpg
IMG_3167 copy.jpg
Screen shot 2012-05-04 at 5.11.57 PM.png
Attach the leads from the "set" button to the protoshield so that the four resistors/photoresistors are in series between them (see notes on schematic if this is unclear).  Repeat this for the "volume" button leads.

Attach Control Buttons

IMG_3168 copy.jpg
IMG_3170 copy.jpg
IMG_3171 copy.jpg
Attach two tact switches to the protoboard so that each delivers 5v to the LED and current limiting resistor circuit (bypassing the need for a 5V signal from arduino pins 2 and 3).

Wire Power

IMG_3177 copy.jpg
IMG_3179 copy.jpg
Locate the red and black leads on the underside of the feeder battery compartment.  Solder a (red) jumper wire from the red lead to the arduino Vin and another (black) wire from the black lead to arduino ground.

Attach Arduino and Ethernet Shield

IMG_3175 copy.jpg
IMG_3172 copy.jpg
IMG_3173 copy.jpg
IMG_3174 copy.jpg

Stack arduino, ethernet shield, and protoboard on top of each other.

Drill Holes in Enclosure

IMG_3294 copy.jpg
Drill two holes in the feeder enclosure.  The holes should be large enough to fit an ethernet cable and a usb cable through.

Connect USB and Ethernet

IMG_3296 copy.jpg
IMG_3297 copy.jpg
IMG_3298 copy.jpg

Plug a usb cable and an ethernet cable to the ports on the arduino and the ethernet shield. Thread cables through the holes you've just drilled in the project enclosure.

Reassemble Enclosure

IMG_3302 copy.jpg
Reattach bottom of enclosure using six screws.  Attach food compartment and lid.

Batteries

IMG_3180 copy.jpg
Insert 4 D batteries into feeder battery holder, and flip switch on bottom of feeder to off position for now.

Firmware

arduino_logo1.png

This firmware will read incoming twitter data so that if you tweet "feed me!" from the username omnomnom the arduino will light up the two LEDs attached to pins 2 and 3 for 1 second, causing the food delivery sequence to start.


I am using Arduino 1.0 for this project, I recommend downloading this version (or later) for this project. If you do not want to use the new version, make sure you have the following Arduino libraries (they are bundled with v1.0):
- Ethernet (for the Ethernet Shield)
- EthernetDHCP (for self-configuring the IP address is you use DHCP at home)

Turn on the power switch on the bottom of the feeder, the LCD should flash 12:00 and the motors should run through the food delivery sequence once. Refer to the manual if you would like to set the clock or set additional food timers, this won't be necessary for the project. Press the rec button and record a personalized message for your pet, this will play at the end of each food delivery sequence.

Here is the Firmware:
<pre>/*
  Twitter Client with Strings
 
 This sketch connects to Twitter using an Ethernet shield. It parses the XML
 returned, and looks for <text>this is a tweet</text>
 
 You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield, 
 either one will work, as long as it's got a Wiznet Ethernet module on board.
 
 This example uses the DHCP routines in the Ethernet library which is part of the 
 Arduino core from version 1.0 beta 1
 
 This example uses the String library, which is part of the Arduino core from
 version 0019.  
 
 Circuit:
  * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 21 May 2011
 by Tom Igoe
 modified by Amanda Ghassaei June 2012
 https://www.instructables.com/id/Twitter-Controlled-Pet-Feeder/
 
 This code is in the public domain.
 
 */
#include <SPI.h>
#include <Ethernet.h>


//variable to prevent overfeeding
boolean justFed = 1;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
IPAddress ip(190,298,34,132); //<<< ENTER YOUR IP ADDRESS HERE!!!

// initialize the library instance:
EthernetClient client;

const int requestInterval = 60000;  // delay between requests = 1min

char serverName[] = "api.twitter.com";  // twitter URL

boolean requested;                   // whether you've made a request since connecting
long lastAttemptTime = 0;            // last time you connected to the server, in milliseconds

String currentLine = "";            // string to hold the text from server
String tweet = "";                  // string to hold the tweet
boolean readingTweet = false;       // if you're currently reading the tweet

void setup() {
  
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  
  // reserve space for the strings:
  currentLine.reserve(256);
  tweet.reserve(150);

// initialize serial:
  Serial.begin(9600);
  // attempt a DHCP connection:
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Ethernet.begin(mac, ip);
  }
  // connect to Twitter:
  connectToServer();
  
  testing();
}



void loop()
{
  if (justFed){
    if (client.connected()) {
      if (client.available()) {
        // read incoming bytes:
        char inChar = client.read();

        // add incoming byte to end of line:
        currentLine += inChar; 
  
        // if you get a newline, clear the line:
        if (inChar == '\n') {
          currentLine = "";
        } 
        // if the current line ends with <text>, it will
        // be followed by the tweet:
        if ( currentLine.endsWith("<text>")) {
          // tweet is beginning. Clear the tweet string:
          readingTweet = true; 
          tweet = "";
        }
        // if you're currently reading the bytes of a tweet,
        // add them to the tweet String:
        if (readingTweet) {
          if (inChar != '<') {
            tweet += inChar;
          } 
          else {
            // if you got a "<" character,
            // you've reached the end of the tweet:
            readingTweet = false;
            Serial.println(tweet);
            
            if(tweet == ">feed me!"){
             digitalWrite(2, HIGH);
             digitalWrite(3, HIGH);
             Serial.println("LED ON!");
             delay(1000);//turn on for 1 sec
             digitalWrite(2, LOW);
             digitalWrite(3, LOW);
             justFed = 0;
            }
            if(tweet != ">feed me!"){
             digitalWrite(2, LOW);
             digitalWrite(3, LOW);
             Serial.println("LED OFF!");
            }
          
            // close the connection to the server:
            client.stop(); 
          }
        }
      }   
    }
    else if (millis() - lastAttemptTime > requestInterval) {
      // if you're not connected, and two minutes have passed since
      // your last connection, then attempt to connect again:
      connectToServer();
    }
  }
  else if (millis() - lastAttemptTime > 14400000){//if four hours has passed since last feeding
    justFed = 1;
  }
}


void testing(){
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  
}

  

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.println("connecting to server...");
  if (client.connect(serverName, 80)) {
    Serial.println("making HTTP request...");
  // make HTTP GET request to twitter:
    client.println("GET /1/statuses/user_timeline.xml?screen_name=nomnomnomfeeder&count=1 HTTP/1.1");
    client.println("HOST: api.twitter.com");
    client.println();
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
}   
  

You will need to make a two edits before this firmware is ready to use.

1. Insert your IP address in the following line at the top of the firmware:
IPAddress ip(190,298,34,132); //<< ENTER YOUR IP ADDRESS HERE!!!
if you don't know your IP address open File>>Examples>>Ethernet>>DhcpAddressPrinter, upload this code to your arduino with the ethernet shield plugged in (and ethernet cable connected), and open the serial monitor Tools>>SerialMonitor

2. Change the username of your twitter account in the following line (from the function connectToServer():
client.println("GET /1/statuses/user_timeline.xml?screen_name=nomnomnomfeeder&count=1 HTTP/1.1");

Upload firmware on your arduino board, plug in the ethernet modem/router. Tweet "feed me!" from your twitter account and you should see your pet feeder dispense food in a minute or less. The feeder will not receive any further tweets for four hours (to prevent over feeding), during this time, tweet another message to replace "feed me!" as your most recent message.

Try It Out

peanut.jpg
Connect the Ethernet shield to an Ethernet cable connected to the internet.  Turn on the feeder.
Set up a Twitter account and tweet the password you set in the firmware.  Within a minute you should see the pet feeder dispense food.