Lockitron Hardware Hookup Guide

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

Contributors: Shawn Hymel
Favorited Favorite 3

Lock It up

The Lockitron Mechanical Assembly from SparkFun is a perfect solution for the DIY home automation or Internet of Things (IoT) enthusiast, whether you want to make your life easier by not awkwardly fumbling with keys or add some extra security in your home with three-factor authentication.

The Lockitron

Lockitron, the company, offers a complete solution that includes the mechanical assembly, embedded electronics that can connect to the Internet via Wifi or your phone over Bluetooth, and apps to control your deadbolt. That is definitely the easy, done solution to your automated locking needs.

But, you're not here for easy, are you? What we have is the mechanical assembly, including motor and battery pack, to help you complete the automated security in your evil lair. An off-the-shelf solution just won't cut it.

Covered in This Tutorial

In this guide, we will go over the guts of the Lockitron assembly and show you how to connect it to an Arduino Pro Mini. The Pro Mini, by itself, has no wireless capabilities. How you ultimately control your Lockitron will be up to you, whether it's a tap sensor or through a WiFi connection.

Materials Used

In addition to the Lockitron Mechanical Assembly, you will need a few additional components:

Recommended Reading

Before getting started with the Lockitron, there are a few concepts that you should be familiar with. Consider reading some of these tutorials before continuing:

Lockitron Overview

Before we connect the Lockitron to anything, we should take a look at its internals to get an idea of what it does. Remove the black, plastic cover, and take a look at the inside.

Lockitron annotated internals

  • Motor Housing - This section contains the motor and gears necessary for rotating the outer ring.
  • Motor Wires - The + and - wires for controlling the motor.
  • Outer Ring - This ring has teeth around the edges so it can be turned via the motor. It also contains a number of "bumps" that the 2 bottom limit switches can use to determine its position. Additionally, it holds the inner ring in place and allows it to freely spin 90º.
  • Inner Ring - The inner ring can freely spin 90º within the outer ring. If the outer ring spins past this 90º stop, the inner ring will begin to spin with the outer ring (in either direction). This free spinning motion allows a user to manually lock and unlock the deadbolt.
  • Rubber Insert - This piece fits over the deadbolt's thumbturn. It can be removed so that you can install the Lockitron on your door first before fitting the rubber insert onto the thumbturn.
  • Battery Holder - A place to put 4x AA batteries and power the rest of the Lockitron (and possibly your electronics).
  • Battery Wires - These wires (red for + and black for -) connect to the 4x AA batteries.

If you plan to wire up the limit switches (a good idea), now is a good time to remove the battery holder. Unscrew the two black Phillips screws from the bottom of the battery holder (underneath where the batteries would go), and carefully remove the holder.

Limit switches and button hole

  • Limit Switches - There are 4 limit switches that are pressed whenever one of the "bumps" on the rings moves by. The top 2 switches coincide with the "bumps" on the inner ring (orange), and the bottom 2 switches look for "bumps" on the outer ring (black).
  • Button hole - On the original Lockitron, a button stuck out of this hole that allowed you to configure the Lockitron's wireless properties. Since we don't have the original electronics, we are going to use the hole to route wires out of the Lockitron housing.

Lockitron annotated limit switches

We are going to assign arbitrary names to the limit switches so that we know what to call them in our code. We also recommend labeling the wires (e.g. with a piece of tape and a pen) that are connected to the limit switches. When we put the battery housing back in the Lockitron, it will be very difficult to see which wire connects to which switch.

  • 1A - First to be hit when the inner ring (orange) spins counterclockwise.
  • 1B - First to be hit when the inner ring (orange) spins clockwise.
  • 2A - First to be hit when the outer ring (black) spins counterclockwise.
  • 2B - First to be hit when the outer ring (black) spins clockwise.

Hardware Hookup

Hook up Wires

We first want to connect a set of wires to the limit switches, motor, and battery compartment. In the end, we should have something like the picture below. The following steps will show you how to get there.

Lockitron annotated wires

Connect Wires to the Switches

Unscrew the battery holder, and set it aside (if you have not done so already). Examine the limit switches.

Lockitron switch annotated

  • COM - Common terminal
  • NO - Normally open. The COM and NO terminals are connected when the switch is engaged.
  • NC - Normally closed. The COM and NC terminals are connected when the switch is not engaged.

Cut, strip, and tin 8x 6-8 inch wires (I used 4 green and 4 yellow wires). Solder them to the outermost terminals on the limit switches. We will be using the COM and NC terminals.

Solder wires to Lockitron limit switches

We recommend you label the wires so you know to which switch it is connected. In this instance, I tagged all the yellow (COM) wires with their respective switch (1A, 1B, 2A, 2B). I plan to connect the green wires (NC) all to ground and the yellow wires (COM) to individual Arduino pins.

Tags on wires for limit switches

Extend the Motor Wires

Cut, strip, and tin another 2x 6-8 inch wires for the motor. Use your favorite wire splicing technique (here are some good ones: 1, 2, 3) to connect to the motor wires. I used red and black to keep with the + and - theme.

Wires to Lockitron motor

Extend the Battery Wires

Once again, cut, strip, and tin another set of wires for the batteries. You will need 2x 6-8 inch wires. Use your favorite splicing technique to connect to the battery wires. I used red and black wires to connect to + and -, respectively.

Wires to Lockitron battery compartment

Route Wires out of the Housing

Carefully pull all the wires through the button opening in the housing.

Routing wires through Lockitron button hole

Solder Headers

Solder headers onto the Pro Mini and Motor Driver board. Don't forget to add headers to the programming port of the Pro Mini (the part where you attach the FTDI breakout).

Arduino Pro Mini and motor driver board

Attach Everything to a Breadboard

Attach the Pro Mini, Motor Driver board, and 2 buttons to the breadboard. Connect the wires from the Lockitron to the breadboard and add additional wires as shown.

Lockitron Fritzing diagram

Replace Battery Holder

Screw the battery holder back in place, making sure that the limit switch wires do not get caught underneath. Do not add batteries at this time.

Lockitron battery compartment

Example Code

With all of the wires connected, we can upload some code to the Pro Mini.

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE.

If you have not previously installed an Arduino library, please check out our installation guide.

Example Sketch

Plug in the FTDI breakout to your Pro Mini, and connect a USB cable from it to your computer. Copy and paste the code into your Arduino IDE.

Shawn Hymel @ SparkFun Electronics
July 7, 2015

Controls the lock and unlock functions of a Lockitron motor with 
2 buttons. Note that on boot, the Arduino will attempt to rotate 
the motor to a "home" position. This might be bad if the 
Lockitron in on a door.

This code is beerware; if you see me (or any other SparkFun 
employee) at the local, and you've found our code helpful, please
buy us a round!

Distributed as-is; no warranty is given.

// Debug mode. 0 = Motor functional. 1 = Serial output only.
#define DEBUG 0

// Constants
const uint8_t LOCK_OPEN = 0;
const uint8_t LOCK_CLOSED = 1;
const uint8_t MSG_LOCK = 0x10;
const uint8_t MSG_UNLOCK = 0x11;
const uint8_t MSG_STATE_REQ = 0x12;

// Motor speed and direction definitions
const uint8_t MOTOR_SPEED = 200;
const uint8_t MOTOR_CW = 0;
const uint8_t MOTOR_CCW = 1;

// Pin definitions
const uint8_t BTN_UNLOCK_PIN = 2;
const uint8_t BTN_LOCK_PIN = 3;
const uint8_t SW_1A_PIN = A0;
const uint8_t SW_1B_PIN = A1;
const uint8_t SW_2A_PIN = A2;
const uint8_t SW_2B_PIN = A3;
const uint8_t AIN1_PIN = 7;
const uint8_t AIN2_PIN = 8;
const uint8_t PWMA_PIN = 9;

// Button states
uint8_t btn_lock;
uint8_t btn_unlock;
uint8_t prev_btn_lock;
uint8_t prev_btn_unlock;

// Switch state variables
uint8_t sw_1a;
uint8_t sw_1b;
uint8_t sw_2a;
uint8_t sw_2b;

// Lock state
uint8_t lock_state;

void setup() {

  // Set up motor pins
  pinMode(AIN1_PIN, OUTPUT);
  pinMode(AIN2_PIN, OUTPUT);
  pinMode(PWMA_PIN, OUTPUT);

  // Set up switch and button pins

  // Reset the lock to unlocked position
  lock_state = LOCK_OPEN;
  prev_btn_lock = 1;
  prev_btn_unlock = 1;

void loop() {


  // Read pins
  sw_1a = digitalRead(SW_1A_PIN);
  sw_1b = digitalRead(SW_1B_PIN);
  sw_2a = digitalRead(SW_2A_PIN);
  sw_2b = digitalRead(SW_2B_PIN);

  // Print results
  Serial.print(" 1B:");
  Serial.print(" 2A:");
  Serial.print(" 2B:");



  // Read button states and lock or unlock on push
  btn_lock = digitalRead(BTN_LOCK_PIN);
  btn_unlock = digitalRead(BTN_UNLOCK_PIN);
  if ( (btn_lock == 0) && (prev_btn_lock == 1) ) {
  if ( (btn_unlock == 0) && (prev_btn_unlock == 1) ) {
  prev_btn_lock = btn_lock;
  prev_btn_unlock = btn_unlock;

void resetLock()
  // Move motor to reset its position
    sw_1a = digitalRead(SW_1A_PIN);
    sw_1b = digitalRead(SW_1B_PIN);
    sw_2a = digitalRead(SW_2A_PIN);
    sw_2b = digitalRead(SW_2B_PIN);
  while ( !((sw_2a == 1) && (sw_2b == 1)));

void lock()
  // Move motor to lock the deadbolt
    sw_1a = digitalRead(SW_1A_PIN);
    sw_1b = digitalRead(SW_1B_PIN);
    sw_2a = digitalRead(SW_2A_PIN);
    sw_2b = digitalRead(SW_2B_PIN);
  while ( !((sw_1a == 0) && (sw_1b == 1) && 
            (sw_2a == 0) && (sw_2b == 1)) );

  // Move motor back to starting position
    sw_1a = digitalRead(SW_1A_PIN);
    sw_1b = digitalRead(SW_1B_PIN);
    sw_2a = digitalRead(SW_2A_PIN);
    sw_2b = digitalRead(SW_2B_PIN);
  while ( !((sw_2a == 1) && (sw_2b == 1)) );
  lock_state = LOCK_OPEN;

void unlock()
  // Move motor to lock the deadbolt
    sw_1a = digitalRead(SW_1A_PIN);
    sw_1b = digitalRead(SW_1B_PIN);
    sw_2a = digitalRead(SW_2A_PIN);
    sw_2b = digitalRead(SW_2B_PIN);
  while ( !((sw_1a == 1) && (sw_1b == 0) && 
            (sw_2a == 1) && (sw_2b == 0) ));

  // Move motor back to starting position
    sw_1a = digitalRead(SW_1A_PIN);
    sw_1b = digitalRead(SW_1B_PIN);
    sw_2a = digitalRead(SW_2A_PIN);
    sw_2b = digitalRead(SW_2B_PIN);
  while ( !((sw_2a == 1) && (sw_2b == 1)) );
  lock_state = LOCK_CLOSED;

void moveMotor(uint8_t spd, uint8_t dir)
  boolean ain1;
  boolean ain2;

  // Define direction pins
  if ( dir )
    ain1 = HIGH;
    ain2 = LOW;
    ain1 = LOW;
    ain2 = HIGH;

  // Set motor to GO!
  digitalWrite(AIN1_PIN, ain1);
  digitalWrite(AIN2_PIN, ain2);
  analogWrite(PWMA_PIN, spd);

void stopMotor()
  analogWrite(PWMA_PIN, 0);


Once the program has successfully uploaded to your Pro Mini, disconnect the FTDI breakout from the Pro Mini. Add 4x AA batteries to the battery holder, and the motor should rotate to a "home" position.

Lockitron controlled with an Arduino

Try pushing the two buttons to mimic the "lock" (top button) and "unlock" (bottom button) functions.

Running the Lockitron Arduino demo code


The fine folks at Lockitron made a fantastic video showing how to install the Lockitron device. We skipped past the first 1:14 of the video, which shows how to connect the Electric Imp in the housing to WiFi (we don't need that; we made our own electronics!).

If you want to mount the breadboard next to the Lockitron, you can use the sticky tape on the back of the breadboard or add your own tape/glue.

Lockitron and breadboard mounted on a door

We're using an RFduino in this picture, but the idea is the same.

Once you have everything working, you can always enclose the electronics for added security.

Resources and Going Further

The Lockitron is a great way to add some advanced technology to your door and venture into the world of home automation. This guide, hopefully, helped show you how to use the Lockitron Mechanical Assembly. From here, the possibilities are endless on how you want to control your door:


Other Tutorials

Need inspiration on how to interact with the Lockitron? Check out these tutorials:

Bluetooth Basics

An overview of the Bluetooth wireless technology.

SparkFun RFID Starter Kit Hookup Guide

Learn the basics of how to get started with the SparkFun RFID Starter Kit.

BC118 BLE Mate 2 Hookup Guide

Hooking up and using the BLE Mate 2, which uses the BC118 BLE module from BlueCreations.

ESP8266 Thing Hookup Guide

An overview of SparkFun's ESP8266 Thing - a development board for the Internet of...Things. This tutorial explains the circuitry driving the board, and how to get it up and running in an Arduino environment.