Introduction: Twitter Controlled Pet Feeder

About: I post updates on twitter and instagram: @amandaghassaei

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

Step 1: Open Pet Feeder

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.

Step 2: Unscrew Pcb

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.

Step 3: Schematic

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.

Step 4: Drill Holes in Pcb

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).

Step 5: Solder Wires to Pcb

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

Step 6: Screw Pcb Back Onto Enclosure

Screw the control pcb back onto the feeder enclosure.

Step 7: Solder Header Pins on Protoboard

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.

Step 8: Solder White LEDs and Current Limiting Resistors

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).

Step 9: Solder Resistors and Photoresistors to Protoboard

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.

Step 10: Attach to Feeder PCB

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.

Step 11: Attach Control Buttons

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).

Step 12: Wire Power

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.

Step 13: Attach Arduino and Ethernet Shield

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

Step 14: Drill Holes in Enclosure

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

Step 15: Connect USB and Ethernet

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.

Step 16: Reassemble Enclosure

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

Step 17: Batteries

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

Step 18: Firmware

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.

Step 19: Try It Out

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.