Home

Our Resinified Office Lock

If it's Friday, then it's usually time for Friday Hacks at resin.io! This means working on a project of our own interests - as long as it is connected to resin.io in some way. We have many dozens of hacking and maker ideas floating around in our team, there's always more to do than how many Fridays there are.

My most recent Friday Hacks project was adding an RFID lock system to our local office. It took a couple of Fridays to get it working and here are all the details, in case you want to set up your own system one day!

Hardware

Lock front

The design I ended up with is based on a Rasperry Pi 3, and uses an Adafruit PN532 NFC/RFID reader, a NeoPixel LED ring, a Grove relay from Seed and a couple of other small parts (see the full bill-of-materials on Github).

We can use a number of different RFID/NFC tags and cards as entry tokens, including (but not limited to) NFC Type 1 to 4, Oyster cards, contactless debit cards and Apple/Android Pay.

For the action of actually opening the door, I've modified the office buzzer system to allow operation via a relay, whilst the usual button press works too.

Buzzer debugging

The NFC reader, LED ring and the relay are all controlled by the Raspberry Pi through the GPIO pins.

The whole setup is placed behind one of our front windows and a poster, so it's not visible from the outside, but tags and cards can still be brought within reach of the reader.

Software

I chose to set up a Python script to implement the door lock logic. The source code is available on GitHub. The script has a straightforward (somewhat simplified) cycle of:

  • Setting up the external hardware through the GPIO
  • Loading the list of accepted card/tag IDs
  • Checking if there's a card to be read
  • If there is a card, check it against the list of accepted ones
  • If authorized, blink the LEDs for feedback and open the door

The script is deployed through resin.io, which allows some practical benefits. First, we can observe the logs from the lock script through an online dashboard and see entry attempts including tag IDs. This is handy when adding a new ID to the system as no additional equipment is needed: just scan and check the logs. Second, new card/tag IDs are authorized through adding environment variables in the dashboard (setting a series of variables such as CARD_1, CARD_2, ... containing the IDs), so no additional programming is required!

There are additional settings, such as how long to keep the door open, or how fast to blink the LEDs.

Finally, here's the complete setup at work:

Lessons and Notes

This project took longer than I expected, partly because I was trying a few different ways that would allow us to unlock the office door. One such attempt was using a Lockitron, but that would have meant that we couldn't unlock the door with a key anymore and that was just not going to work.

One enhancement that I wanted to add was support for encrypted key cards, such as Oyster, Apple/Android Pay and contactless bank cards. This required removing some checks from the Adafruit PN532 library. My version ignores invalid checksums instead of crashing with an error (which happens in the original library when reading these cards).

I plan to add a Flask server to the script, which can be exposed over a public device URL and would provide an API endpoint to open the door remotely. This can be combined with our Hubot such that the door could be opened by asking it on our company chat: hubot open the office (possibly adding some magic keywords for security, such as please - or something more secret)

I might also add a front-end that shows who is in the office, based on their card login - although this may be slightly Orwellian.

Do you have a project similar to this? Would love to hear about it, leave us a link in the comments!

comments powered by Disqus