Join the discussion on Hacker News!

This tutorial is based on a workshop I gave at the Makerland conference in Poland. It will teach you how to wirelessly control a deadbolt lock without damaging or modifying the lock itself. We will be using an Arduino Uno, a servo, and Node.js to make it possible for you to lock and unlock your door via SMS. This is inspired by the amazing Twilio-powered Lockitron device which thankfully is not held together by cardboard and duct tape.

Step 1: Setup

Parts

1. A lock

2. Duct tape + Cardboard

3. Servo motor (I used the HS-322HD)

4. Arduino Uno + Programming Cable

Prepare Your System

1. Download and install the Arduino IDE from http://arduino.cc/en/Main/Software.

2. Install node.js from http://nodejs.org/

3. Install the ngrok utility from https://ngrok.com/download

We will be using the Arduino IDE to write and upload code to your Arduino board. We will then use a node.js script to communicate with your Arduino over a Serial connection and respond to Twilio requests using the express web server. And lastly, we will be using ngrok to expose your express web server to the world so that Twilio can send incoming SMS messages to your application.

Now we’re ready to dive in and start wiring up our Arduino and connect it to our lock.

Step 2: Wiring Up Your Arduino

We will be using a servo to control our lock. A servo is a type of motor that typically has a 180 degree movement radius, which makes it perfect for a lock which only turns back and forth.

A servo motor has three wires – power (red), ground (black), and control (frequently yellow or white). Connect the power wire to the 5V pinout on the Arduino and the ground wire to the GND pinout next to it. We can then connect the control wire to Digital Pin 12 on our Arduino as in the following diagram:

That’s it! Now that our servo is wired to our Arduino, we can mount it to our lock.

I prefer to use household items when prototyping these types of applications, though if you have access to a 3D printer I would recommend designing and printing your own lock mount.

For the purpose of prototyping, we will be using cardboard and duct tape to mount our servo to our lock – just like astronauts do!

Attach the two metal rods (or some other tall object) to your servo with screws and washers.

Now use a piece of cardboard (or other stiff material) to make a tighter bond between the servo and the lock:

Now you can tape the servo to the deadbolt lock. Make sure it is positioned on the correct side so that the direction that the servo turns in is aligned with the direction that the lock turns in:



And last but not least, we will tape our servo’s arms to the deadbolt itself:

Now you have your fully mounted (and fully impermanent) servo-controlled deadbolt:

Step 3: Writing Your Control Code

Once you have your Arduino wired up and your initial software installed (Node.js and Arduino), you can run the following command to install the necessary node.js modules for your script. Note that if you are on Windows, you will need to follow the node-serialport Windows installation instructions.

npm install serialport twilio express

Node-Serialport makes it easy to communicate with your Arduino via a Serial connection from a Node.js program. We will be using it to receive HTTP request for incoming text messages from Twilio, and passing instructions along to the Arduino to lock or unlock your deadbolt.

Express is a simple node.js web framework. And the twilio module makes it easy to communicate with the Twilio API.

First things first, we can set up our new Arduino sketch by opening the Arduino IDE.

To begin with, we need to open a 9600-baud Serial connection and attach to your servo (on pin 12).