Ever wish you could video chat with your dog during the day, and remotely feed them treats? Probably not, but now you can with just an old laptop, an arduino and entirely too much time on your hands!

DogFeeder (1 of 1)

Basically, my wife and have an unhealthy love for our dog, Copper.  We play with him, take him on long walks and runs, and he may sleep in the bed more often than I am comfortable admitting.  However, during the day, he is mostly by himself.  I had joked many times that I should build a puppy cam and treat machine to feed him, but when a friend jokingly shared a puppy cam with us on facebook, I knew I had to act.

 

 

The easy part is the video chat. Take an old laptop and turn off all screen locks and hibernation (you can leave a screensaver or screen dim on).  Install skype, create a new account for your dog and set it to automatically answer with video and automatically answer calls from friends. Then, add yourself to the friend list.  Call in anytime to check in on a video of your pooch.

The next part is to use a servo and arduino to dispense the food.  I am not a mechanical engineer, and most of my solution was thrown together in a few minutes using duct tape, old cardboard boxes and an upside down cd container to hold food above his crate.  The CD container has a hole about the size of a half dollar in it that is covered by a cardboard piece connected to an arm on a small servo motor. The arduino has code so that when it receives a 0xff byte from the serial port, it moves the arm (connecting to pin 9 of the arduino) 60 degrees and then back into place to let some kibble fall out and then cover the hole again.

The only part left is to control the arduino from the internet outside of our home.  I found a lot of tutorials controlling an arduino using processing, but that seemed clunky to me.  I found the serial library in python lets me write directly to the serial port.  Being familiar with the Pyramid web framework, I was able to create a simple website that would send the 0xff byte to the serial port from the web (use any web framework you are familiar with).  After that, set up port forwarding on your home router to send the webpage being served from your old laptop to your IP address from your ISP.  You can use other services to connect this to a domain name if you wish, but I just left it connecting to the IP address knowing it may change periodically. This is a basic overview of my approach, as a step-by-step of each part would be pretty long if you are unfamiliar with the technology included.  Post any questions in the comments and I'll do my best to answer them.

Important Python Code:
import serial
 
ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write(chr(0xff))
ser.close()
 
 
Arduino Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  if (Serial.available()) {
    if (Serial.read() == 255 && pos == 0){
      for(pos = 0; pos < 55; pos += 1)  // goes from 0 degrees to 180 degrees
        {                                  // in steps of 1 degree
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
        for(pos = 55; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
        {
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
    }
  }
}