Introduction: Raspberry Pi - SMS Garage Door Butler

Picture of Raspberry Pi - SMS Garage Door Butler

Most Raspberry Pi garage door remotes had open ports, or other features I wasn't too fond of. So I created my own that contains much more security, logging of who opens the garage, video capture, garage status and more.


  • 100% secure garage door operation, with access control lists. Only authorized family members can open.
  • Ability to monitor or control garage anywhere in the world from a controlled website, with no open router ports
  • Full video capture of who's coming into the garage, uploaded securely to your website for later perusal
  • Ability to remotely stop or kill the process in case of malfunction or abuse
  • Email notifications when a family member arrives or leaves the house
  • Cheap SMS solution (3/4 a cent per text), with no GSM card purchases or any cell contracts
  • Standard Linux code, easily setup on a new Pi, and quickly portable to other platforms like BeagleBone or whatever future Linux technology arrives. Basically, I wanted the ability to restore this system on a fresh device within 30 minutes or less

Step 1: Requirements

Picture of Requirements

You will need:

  • A Raspberry Pi or BeagleBone Black setup with base configuration. I use Raspbian Wheezy
  • Wireless connectivity via a wireless dongle (or just plug in a network cable)
  • A camera (compatible webcam or PiCam)
  • A relay board. I use "SainSmart 5V 2-Channel Solid State Relay Board", because it defaults to LOW instead of HIGH
  • Enough wire to access your garage door opener, or just break apart a spare remote
  • A website with hosting. You can get a small amount of space on DropBox or Google Drive and use that, or you can create a random website from a cheap hosting service like, which will provide 100gb of space for only $11 PER YEAR. You won't need to keep these files anyhow, since they're just logs.
  • If using the PiCam, a little poster putty

Step 2: Install Required Libraries on Your Raspberry Pi

You first need a Twilio account (free, go to, a Twilio phone number ($1 per month) and some money in your account.

Once setup, install necessary libraries into your Raspberry Pi:

sudo apt-get install -y python-pip mysql-server python-dev libmysqlclient-dev

sudo pip install MySQL-python twilio

And create two directories:



Step 3: Create SQL Databases, Users, Permissions

Next, login to your new MySQL localhost server, and then add a user + set privs + create the database and tables needed:

mysql -pYourSQLPassword -u root -h localhost

create database GarageDoor;

use GarageDoor;

create table Door(sSid CHAR(40));

create table Authorized(sPhone CHAR(20));

create table Log(sPhone CHAR(20), sAction CHAR(10), dDate datetime);

-- put your phone number, with a +1 before it if you're inside the USA

insert into Authorized (sPhone) values ('+12145551212');

CREATE USER 'garage'@'localhost' IDENTIFIED BY 'garagepassword';

GRANT ALL PRIVILEGES ON * . * TO 'garage'@'localhost';



Step 4: Hookup a Relay and Garage Door Opener

Picture of Hookup a Relay and Garage Door Opener

For this step, we'll be hooking up your Raspberry Pi's GPIO pin 23 (physical pin 16) to a relay. I like the SainSmart 4-Channel Relay Module off Amazon for about $9. Now either break apart a spare garage door remote, or just wire the relay directly to your garage door. Consult your garage manual how to do this.

You can see my spare garage remote has an obvious button that I soldered two wires to, and jammed into my relay.

Next, connect all the proper wires from your Raspberry Pi to the relay. Pin 2 = 5v. Pin 6 = Ground, and Pin 16 controls the relay. Now ensure your relay is ACTIVE LOW, which means sending a HIGH signal opens the garage. This relay off Amazon was the proper fit for me: SainSmart 5V 2-Channel Solid State Relay Board

Step 5: Add a Camera

Picture of Add a Camera

In this example, I used the Raspberry Pi camera. You can use a webcam if you're on BeagleBone Black or some other Linux computer. Click here for a list of Raspberry Pi compatible webcams

Mount the camera using some stiff wire + poster putty. You can mount on either your Raspberry Pi case, or the shelf your device is sitting on. You alternatively CAN make a fancy 3D printed larger case to house all of this inside, but I'm cheap.

Step 6: Grab the SMS Butler Code, and Install

Picture of Grab the SMS Butler Code, and Install

Grab my code from here:

and copy it to your Raspberry Pi, any directory is fine. Change the variables up top to your own Twilio account's phone number, and your personal cell number. Plus the Twilio authentication codes you can obtain from your account's main screen on

And run:

sudo chmod 755


Then text your Twilio phone number the word "status" (without quotation marks), and you should receive a status message back, with the last person who opened your garage door.

Step 7: Open Garage, and See the Results on Your Website

Picture of Open Garage, and See the Results on Your Website

Command reference for the SMS Garage Butler:

OPEN - sends a HIGH signal to the relay for 0.5 seconds, thus activating the spare remote (or the door operner, if you chose direct connection) and opening the garage door. This will also upload a movie of who opened the door, to your website.

STATUS - see who last opened the garage door, and if the service is ENABLED or DISABLED. This will also upload a picture of your garage door status (

DISABLE - stops listening for garage opening commands

ENABLE - re-enables the service, if disabled

KILL - completely exits the application. No further commands will be processed

Now go and add your own commands!

Step 8: Questions and Answers

Picture of Questions and Answers

Why not use Motion for video capture?

Motion captures MOTION, which means it'll grab movies of me cleaning my garage, or changing the oil in my lawn mower. I only want to know who's entering my garage when it opens, not have a video blog of my garage activities. Plus this limits the video to only 60 seconds, which is enough time to see who's coming in, and who they are with.

In addition, I don't want to setup that huge file and configure all sorts of little options, including a live stream. Does anybody really want to stare at a live stream of their garage? No.

Why use a website for video uploads?

Most website providers offer a $11 per year plan for the first year of a new site. AND they'll give you about 100gb of free space. So I just created a site called or whatever, and upload my videos there. Now I can view them online from anywhere.

If you're married to DropBox, Google drive, or Amazon hosting then replace my code with the freely available Python sources for using those services.

Why not use WebGPIO, host a Pi website and all that?

I dislike open ports to my home network. Sorry, it's a security issue. I've seen people do it (plus have a live stream to their garage - really? You want to stare into your garage all day?), but not for me.

Can't you just use Adafruit's FONA or some other SMS device?

Sure, if you want. Scanning Twilio for new texts for 3/4 a cent per text is much cheaper than doing FONA, and enrolling yourself in a cell contract.

Step 9: Credits

Picture of Credits

THANK YOU ADAFRUIT for selling me all these goodies. I haunt that store for new products daily.

This guy's garage idea got me started:

However I disliked his open port for doing the WebGPIO, and a live webcam of my boring garage seemed useless. I also didn't use a ULN2003APG chip, since I'm only connected to a CR2032 battery with the relay.

Greg's magic tricks alerted me to Twilio, and all the possibilities there:


tpitcher0528 (author)2016-08-16

Has anybody tried this with 2 separate garage doors?

dbagioni (author)tpitcher05282016-08-26

Yes I did and have it working complete with position sensors.

dbagioni made it! (author)2016-08-26

I made an enhanced version of this with controls for both doors, door position sensors and voice to text control....These awesome instructions helped me get it off the ground. I'll post mine soon.

DonaldChapman (author)2016-04-09

Can anybody comment if the GMail emailing part still works? I am trying to get the software to run, but it appears to crash while sending an email. I am using 2 factor authentacation however I created a special password for this already.

Angi1 (author)DonaldChapman2016-08-06

As of June 2016. Google has phased out SSL V3 encryption. Good look finding another email client that supports SSL V3

qsdqsd (author)2016-04-12

Congrats for this instructables !!
Can I avoid the use of the raspberry and only use an arduino with gsm kit ? What is the interest of using raspberry here ? (except for the camera module)

AndyS11 (author)2015-07-11

Can someone please explain how to add phone numnber to the authorized list?

DonaldChapman (author)AndyS112016-04-10

Replace the phone number on the below line between the **** I think I copied and pasted it verbatim the first time. I went back and logged in, use GarageDoor, insert into Authorized (sPhone) values ('+MY CELL NUMBER'); Hope it helps!

mysql -pYourSQLPassword -u root -h localhost

create database GarageDoor;

use GarageDoor;

create table Door(sSid CHAR(40));

create table Authorized(sPhone CHAR(20));

create table Log(sPhone CHAR(20), sAction CHAR(10), dDate datetime);

-- put your phone number, with a +1 before it if you're inside the USA


insert into Authorized (sPhone) values ('+12145551212');


CREATE USER 'garage'@'localhost' IDENTIFIED BY 'garagepassword';

GRANT ALL PRIVILEGES ON * . * TO 'garage'@'localhost';



KeefN (author)2015-12-23

Hey does this have capability for "automatic garage door close after x minutes" feature?

I'm looking to buy that as seperate piece but looks like this would be straightforward to instead write in code.....


andrew76092 (author)2015-11-17

This is such a slick operation, thanks for posting. I’m wondering if anyone has made this with the latest Raspberry Pi 2? Before I start working on this, I’d like to see if there have been any issues with the latest RP? Thanks in advance!

TheKirkwoods (author)2015-10-27

Fella, this is going on my list of junk to accomplish before Spring!

paulp21 (author)2015-07-19

Is there a log file so I can tell where my errors are coming from? The py runs for about 30 seconds and aborts saying an error.

rdrye (author)2015-02-10

Great project - built it your way and everything worked great! I didn't want to continue with the email and video parts so have commented those functions out.

Instead, I added a magnetic switch on the garage door and used GPIO IN (BCM: Pin 18) to monitor switch state. Added a function in to get status of door (Open, Closed). Called this function with "Status" SMS. Also added 30 second sleep timer after OPEN or CLOSE to send a second SMS showing door's status.

jerryasmith (author)rdrye2015-02-27

I've been working on the same status idea as well. However, I can't get the function to work properly as the script continues to print my own error message - here's what I have. I'm calling the function down in the status section. Any thoughts?

# Get the status of the garage door (open or closed)

def GetDoorStatus():


if GPIO.input(18):

state = 'open'


state = 'closed'

return state


print "Error inside function GetDoorStatus"


scott-w (author)jerryasmith2015-03-15


I do not have an answer for you. But I have a similar setup.I used a second program I found.

This way I knew if the garage is open by the wall mount or butler.


garydark (author)2015-02-10

Hi! How do I add my authorized phone number in "" file.

jumrm (author)2014-12-15

Hey so everything is up and running pretty well, minus the shut-downs and I don't really know how to write the code to remove mysql list.. But my main question is, is there any way to hook this into the garage directly without compromising the existing door opener buttons that are also hardwired to the system? If my relay is hooked up to the opener directly, it kills the physical buttons. I tried installing in line further away from the unit as well, and it compromises all three buttons as well. Is there any way to fix this? Would a relay work without a data source telling it to activate? I have a second relay and could use a 5v power source from somewhere else to hook other three buttons to a relay if that would do anything?

scott-w (author)jumrm2014-12-16


Sounds like you want a setup like I have. Hardwired to the wall mounted switch.
I needed to change the pin setup to board.

Here is what I have


Need to make sure you change the GPIO_PIN to match what you are using.

Once I changed to board All worked correctly


scott-w (author)2014-12-11


I am having the same issues. I believe something needs to setup on Twilio website, just not sure what. I also have see that butler is eating up to process time. I found that when the process time gets over 50 mins Butler does not work well.

I have created tow simple scripts that run from cron to help this out. I do want to fix correctly. Just learning python now.


# 11/20/2014
# Check if is running, if not start it

ps -ef |grep butler |grep -v grep |grep -v vi >/dev/null
if [ "$?" -ne "0" ] ;
python -t /usr/local/etc/ &
echo " " >/dev/null


# SMS Butler Seems to be a runway procces/leak Nov.28.2014

F1=`ps -ef |grep mod |grep -v grep |awk '{print $7}' | cut -d : -f 1`
F2=`ps -ef |grep mod |grep -v grep |awk '{print $7}' | cut -d : -f 2`

if [ "$F1$F2" -ge "0050" ];
PS=`ps -ef |grep mod |grep -v grep |awk '{print $2}'`
kill $PS
sleep 2
sh /usr/local/etc/

echo " " > /dev/null


*/5 8-23 * * * sh /usr/local/etc/
29,59 8-23 * * * sh /usr/local/etc/


AkiraFist (author)scott-w2014-12-11

Scott: Try removing the database entirely, and just use the array for tracking
previous messages. Add a few lines to fill the array at startup with
all existing Twilio messages.

scott-w (author)AkiraFist2014-12-14


Thank you for the info. However I am very new to python. Could you give more info ?

Thank you.


al_carr (author)2014-10-06

Very nice, great idea. I am going try it when I get my pi back. :-( Borrowed to a friend.

About this:

Continuously scan Twilio's incoming SMS list

?? Should there be a 10-20 second sleep or something in there, seems a little intrusive/abusive.

Thanks for the instructable,


AkiraFist (author)al_carr2014-12-11

Al_carr: Twilio offered to host this on their page, so apparently it's ok with them.

crsherman (author)2014-10-13


Great work by the way.

I installed the pi with the software and made modifications to the code for it to work with the PiFace board (just modified the GPIO commands).

Everything was working great for a while, but I have now started to receive the following error message when texting "Status" to the pi.

The error I receive is the following:

"Error while inserting SID record to database"

Eventually this will cause the program to bail and shut down. I then have to reboot or restart the program for it to work again.

I have made sure that the program is receiving an actual SID number from Twilio but for some reason that I cannot work through it is not able to save the record to the database.

Any thoughts on what could be causing the error?


AkiraFist (author)crsherman2014-12-11

Crsherman: Remove the database entirely, and just use the array for tracking previous messages. Add a few lines to fill the array at startup with all existing Twilio messages.

scott-w (author)crsherman2014-11-17

Hello Crsherman,

Where you able to work trhu this and come out with a fix ?


yukonjack11 (author)2014-12-09

Why not just use email and look for passphrase or keyword and sender ID? You can send pics, datalogs, video even to that email address. Then you won't need a non-free twillio account or website.

AkiraFist (author)yukonjack112014-12-11

Sure, design it how you'd like. Can use a phone card from Adafruit, email, bluetooth, anything that's fun.

JulianM1 (author)2014-12-11

Hey scott-w, i sent you a PM :)

JulianM1 (author)2014-12-09

My twilio was syncing for a day, and then all of a sudden stopped responding back with confirmation messages.. any idea why that would happen?

wjeiv (author)2014-11-11

Did you ever figure this one out scott-w? I'm in the same boat. I had a normally-closed relay on there first and it worked fine (with the exception of all the drawbacks of the program or pi shutting down). With this sainSmart relay, the relay seems to stay closed after the relay LED shuts off. Seems like if I disconnect and reconnect the garage door switch wires, it resets. Still tinkering.

scott-w (author)wjeiv2014-11-12


Had to change to

GPIO_PIN = 18 change to matched pin hardware


wjeiv (author)scott-w2014-11-12

Thanks! I soldered in an old garage remote and had the relay control that, and it worked great.

scott-w (author)wjeiv2014-11-12

I am wired to the wall mount. Which is why I think it was not breaking the signal.

scott-w (author)2014-10-12


I think I have all the software setup correctly. However one out of the 8 sPhone I have setup does not get anything back or I see Unauthorized user tried to access system: +1xxxxxxxxxx
I have tried 3 of the others in the list at they seem to work.

WORKED: 2 Galaxy S4 mini 4.2.2, 1 iPhone 5S iOS8


Thanks for the help


scott-w (author)scott-w2014-10-14

I was able to get working on my galaxy S5. Need to type the word out completely and not use the suggestion bar to complete the word


mrwilder (author)2014-09-15

Got it wired up over the weekend but it only stays running for 5-10 minutes before it errors out. Works fine otherwise...

Any idea where the twilio setting is to make it not respond with a confirmation that it received a message?

AkiraFist (author)mrwilder2014-09-25

Hey Mr. Wilder! You can remove all the "SendSMS" lines and see if that fixes. If not, comment out the email portion, remove the SQL portion, and just see when it starts working again. Once you identify the culprit, email me and I'll give you a workaround.

JessicaB3 (author)2014-08-30

Believe you have a typo on Step 2.

It should be

mysql-server, not


AkiraFist (author)JessicaB32014-08-30

Good catch, Jessica, thank you! I just fixed the typo.

AkiraFist (author)2014-08-27

Jliberman, yes! You can use Amazon Simple Notification services:, or any other method you choose. Your Pi has an internet connection, so whatever API you can find, or internet JSON call you can use would work great.

Adafruit has a great example page here using SNS:

jliberman (author)2014-08-26

Could You use a different Texting provider? Such as WhatsApp or another compatible with the Pi?

AkiraFist (author)2014-08-26

Hi Scumm7, yes you need wireless or wired connectivity from the Raspberry Pi to communicate with Twilio.

Scumm7 (author)2014-08-25

So is it still using ethernet or Wifi to send the SMS message? I assume it must be, but I thought maybe I missed something.

wilgubeast (author)2014-08-25

This is awesome. Wish it had a garage livestream. What's happening in there all day? Is it like Toy Story, but for tools?

About This Instructable




Add instructable to: