Deadbolt NFC lock control using an Arduino.
Follow Adafruit's tutorial on wiring the PN532 NFC shield to the Arduino. Their tutorial also covers downloading necessary libraries for programming the hardware.
Before compiling and flashing the firmware, use an example sketch from the Adafruit library to read the code from your NFC device.
Create authorized-ids.h
and add the codes you'd like to authorize:
const unsigned long int authorizedIDs[] = {
1234567812345678, // Example NFC ID
8765432187654321 // Example NFC ID
};
// Use one of the Adafruit example NFC sketches to read your tags' IDs
Using the Arduino IDE, flash deadbolt.cpp and authorized-ids.h
to your Arduino.
- Arduino Uno Rev3
- PN532 NFC/RFID controller breakout board - v1.6
- Servo motor with strong torque (I use this)
- A pipe bracket that can fit onto your deadbolt knob, constructor set pieces, double-sided tape, hot glue, and some creativity
- Some kind of enclosure and double-sided tape for holding the circuitry on the inside of the door (I use this)
- A momentary pushbutton for easy locking and unlocking from inside (I use this)
- Particle Photon (optional, for web connectivity)
- One or more NFC tags
Wire the following:
Servo: 5v to 5v, ground to ground, and data to pin 9.
Pushbutton: One end to 5v, other end to pin 7.
LED: anode to ground and cathode to pin 13. (optional)
Here's where you'll need to get creative. For an apartment that you lease, I recommend mounting the back of the servo to the door with a non-damaging poster strip, then securing it with hot glue between the servo and the actual metal of the deadbolt.
You'll then need affix a pipe clamp to the deadbolt knob. Check your local hardware store for a "milford hanger" and another bracket that will fit your need. I used a combination of the bracket tension, hot glue, and wrapped steel wire to keep the contraption steadily holding the knob.
Bridge the connection between the milford hanger and the servo, using some kind of brackets. I used constructor set pieces bought from the cheapest set I could find online.
Open deadbolt:
Closed deadbolt:
If you'd like to be able to lock and unlock the deadbolt via the web, open deadbolt-lamprey.cpp and change line 5 to a secure password. Flash the firmware to your Photon board.
Wire the Photon's VIN to the Arduino's 3v pin, the Photon's pin D1 to the Arduino's pin 7, and ground to ground.
Follow the steps on how to call a Particle function.
Using your Photon's deviceId and auth token, call the function toggle
with your password as the argument.
With everything assembled, test that your deadbolt can still be unlocked with a normal key. It's highly recommended that you still carry normal keys in case of power or hardware failure! Also, you may want to leave a second door unlocked while testing, in case the servo jams and prevents unlocking the door from the outside.
Advanced - Pantheon Integration
This project has built-in support for Pantheon's custom state feature. Both the deadbolt state (locked and unlocked) and the door itself (ajar/closed) can be synced with a Pantheon instance.
Follow the Pantheon documention to configure your instance to track deadbolt and door state.
For the door state, you'll need to wire a magnet contact switch to ground and D4 on the Photon.
You'll also need to wire together 2 additional pairs of pins between the Arduino and Photon: 4 (Arduino) to D1 (Photon) and 3 (Arduino) to D2 (Photon).
Finally, create a Webhook through the Particle integrations app. Copy these form fields, substituting your unique Pantheon id
and address.
You may need to adjust the servo's open and closed rotations to your setup.
To do this, modify the LOCKED_POS
and UNLOCKED_POS
variables in deadbolt.cpp.