dark mode light mode Search Menu

How I Taught My Dog to Text Me Selfies

Greg Baugues on Twilio

A few weeks after we got our puppy, we taught her how to turn on a light.

Turns out Kaira will do just about anything if you can clearly communicate your desires and have a treat in your hand. There’s an Ikea lamp in our bedroom that’s activated by stepping on a floor switch. We started her training by placing her paw on the switch, saying “Light,” and giving her a treat. Once she got that, we’d press on her paw and withhold the treat until she heard a click. Eventually, we could say “Light” from across the room and Kaira would run over and do the job.

Shortly afterwards I started thinking, “I’ve got a dog that can press a button. What can I do with that?”

Doggy Selfies

When Twilio launched Programmable MMS, I started to wonder if we could teach Kaira to send selfies. I’m pleased to say that thanks to the Arduino Yun and a big red button, the answer is a resounding “Yes!”

What you’re seeing in the video is a cigar box housing a massive arcade button and an Arduino Yun. The second box serves as a stand for a webcam that’s plugged into the Yun. (My local cigar shop sells empties for $2 which make for sturdy and stylish hardware enclosures).

The WiFi enabled Arduino Yun has two microprocessors: one does all the pin interaction you typically associate with an Arduino. The second runs a stripped down version of Linux called OpenWRT which can run programs in your favorite scripting language (Python comes pre-installed, but you could put Ruby or Node on there if you so please). This project has one program running on each processor. Together, they are less than 60 lines of code.


What’s most exciting to me about this project, aside from the sheer novelty of my dog sending selfies, is how simple each component is. The button press is literally the second example from Massimo Banzi’s Getting Started with Arduino. The Python script is practically cut-and-paste from the Dropbox getting started guide and the Twilio SMS and MMS quickstart.

Hardware hacking can be intimidating if you’ve never done it before, but remember that the most impressive hacks are often just simple building blocks stacked on top of one another. Wifi enabled devices like the Arduino Yun have drastically lowered the barrier to entry for web developers to dip their toes into the Internet of Things.

So let’s say you had a box that could interact with both the physical world and any web-based API using the programming language you already know. What could you do with that?

The Code

Here are the two scripts used for this project:

Arduino Sketch Code

#include <Bridge.h>
#include <Process.h>
const int BUTTON = 7;
void setup() {
  pinMode(BUTTON, INPUT);
void loop() {
  if (digitalRead(BUTTON) == HIGH) {
void takePicture() {
  Process p;
  p.addParameter("-r 640x480");
void uploadAndSend() {
  Process p; 

upload-and-send.py Script Code

import datetime
import dropbox
from twilio.rest import TwilioRestClient
dropbox_access_token = "YOURDROPBOXTOKEN"
twilio_phone_number = "YOURTWILIOPHONENUMBER"
twilio_account_sid = "YOURTWILIOACCOUNTSID"
twilio_auth_token = "YOURTWILIOAUTHTOKEN"
cellphone = 'YOURCELLPHONE'
timestamp = datetime.datetime.now().strftime("%h-%m-%S")
filename = "kaira-" + timestamp + ".jpg"
f = open("/mnt/sda1/pic.jpg")
dropbox_client = dropbox.client.DropboxClient(dropbox_access_token)
response = dropbox_client.put_file(filename, f)
url = dropbox_client.media(response['path'])['url']
twilio_client = TwilioRestClient(twilio_account_sid, twilio_auth_token)
  to = cellphone,
  from_ = twilio_phone_number,
  body = "Woof.",
  media_url = url)

These tutorials describe the entire process from Arduino Yun unboxing to sending MMS:

Learn More

How I Taught My Dog to Text Me Selfies