Nathan Reid     About     Archive     Feed

Life, Software, and the Pursuit of Everything

This automated life: unlocking a door with your voice and Arduino

Home automation is another long-time interest of mine. A few months ago, I decided to automate the locking/unlocking of our apartment door. I'd been looking for a good reason to get an Arduino, and this settled it. A quick search online turned up some other peoples experiences doing this, and away I went.

Parts List:

Assembly was pretty straightforward; first I got the servo up and running following the Knob tutorial. Then I hooked up the WiFi following SparkFun's CC3000 hookup guide and whipped up the iOS apps.

There were a few crucial things I learned along the way:

  1. If your servo power supply is separate from your Arduino power supply, be sure to connect the grounds together! I didn't do this at first, and it caused a lot of crazy behavior (such as the Arduino resetting and the servo motor jumping around).
  2. Use a power supply that allows you to use get the max torque from your servo. Initially, I ran my servo off 5V, but that wasn't enough for it to consistently lock or unlock my door. Once I got a 6V power supply, the servo performed as expected.
  3. Get a pigtail or barrel jack to connect your power supply to your servo. This saves you from having to cut off a good power supply end.
  4. Customize the servo control code to your servo. If you get the one above, that means changing the min and max pulse widths to 700 and 2300, respectively. If you don't, you servos will stutter when they get towards the limits of their turning capabilities.
  5. Solder the CC3000 connectors on. At first, I just hooked wires through the holes (I couldn't find my soldering gun). It was a pain to keep stable though, and I wasn't sure if the issues I was experiencing were caused by faulty code or my jenky wiring.
  6. Update the CC3000 pinout code to match your layout. The samples I got used a different layout, so my CC3000 didn't work at first. Here are the correct pins after following the SparkFun guide for the UNO:
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   2  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  7
#define ADAFRUIT_CC3000_CS    10

Now, my end goal is for the door to both lock and unlock by voice command. This particular lock is unfortunately asymmetrical, which has added complexity to getting both functions working. The minimum viable product, however, was that the door unlock when I want it to (so I can unlock it coming down the hallway laden with groceries and my 15-month old daughter). Therefore I currently only have unlocking in place, but will hopefully soon have the free time to get the locking function working as well.

The HTTP server was ridiculously easy to set up due to a working example from Adafruit. I just had to plug in a handler for my URL paths (/unlock and /lock) and it was ready to be attached to the door. I first tried using Instamorph to mold a "handle" around the lock servo, but it was pretty big and ugly. Then I tried wrapping string around the lock base and connecting that to the servo, as another person had done - but the servo wasn't able to generate enough torque this way. I'd like to take another look at this, as it solves the asymmetry issue, but in the meantime I have instead wrapped the string around the lock handle:

Video - Unlocking the door with Arduino

For unlocking the door, I whipped out a quick Cordova application that just sends a GET request to the /unlock endpoint on the Arduino. Thanks to jailbreaking, I can use "Hey, Siri" while walking around and easily launch the app with just my voice:

Video - Unlocking the door with my voice

Since taking the video, I've modified the app to talk back with a confirmation or failure message. At this point, the app is just the sample Cordova application with tect-to-speech added and the following method called on launch:

function execute() {
        .done(function () {
            texttospeech.speak("OK, I unlocked the door.");
        .fail(function () {
            texttospeech.speak("Get it yourself!");

My next step is to set up a Node.js web server with secure access, and use that to make enable unlocking via the Internet. I'll be sure to post an update detailing that when I get the chance.

The Arduino source code is on GitHub:

comments powered by Disqus