RFID door access powered with a Raspberry PI

Recently, we got our hands on one of these awesome RFID badboys.

RFID Reader

These things look horrible, are made in China, but hey, if life gives you lemons :) We also happened to have some Raspberry PI’s lying around. Fortunately, the RFID reader registers as an ordinary keyboard, and ‘types’ the scanned RFID tags, ending in a newline. Which makes things very easy to hookup.

Our office door was already equiped with an ancient Electric Strike from somewhere in the 80’s or so, which needs a 12V 2A input, so we could use that. It works by simply supplying it with a voltage. The coils will be charged, and the strike will open. Take away the voltage, and the strike will be closed again.

In technical terms, this is a NO gate, Normally Open, so the circuit is ‘open’ when the Strike is in rest. There are also Normally Closed (NC) gates.

Electric Strike

To switch the strike, we needed a relay, as the Raspi is 5v, and doesn’t provide anywhere near enough amperage on the GPIO ports. We ordered the PiFace Digital I/O Expander. You could just work with any relay via the GPIO ports, but this board also gives us the oppertunity to add more inputs later on.

PiFace

Wiring

PiFace connections

You can see that we placed the button for our receptionists in parallel to the (simple) circuit. So if the Raspberry or the software for whatever reason fails, they can still open the door with the push of a button. We used an old 12V laptop powersupply for the external power supply.

Making it work

You can checkout all the necessary files on the Github gist

Here is the main scanner file: We have to listen for the keyboard events. Once an enter is received, we check all previous characters for a valid key from the cards.json file (see the full gist).

Keeping it working

This is all fun and games, but a system like this needs to always work. If for whatever reason our script would crash, it would need to be restarted automatically. We used supervisord for that. Supervisord is like a nanny. Supervisord will keep your script in check. If it crashes, it will restart it again. If your raspberry pi reboots (power outage maybe?) it will make sure the scripts starts automically after booting.

Install supervisord with:

sudo apt-get install supervisord

Add the supervisor.conf file to the config directory, and reload supervisor:

sudo mv supervisor.conf /etc/supervisord/conf.d/.
sudo /etc/init.d/supervisord restart

Supervisord will then take over the loading and restarting. If you want to restart it forcefully, you can restart supervisord again, or checkout the supervisorctl command.

Other additions

After we got the basics working, we added some extra functionality like checking our local Active Directory for a valid user. And showing a greeting on one of the screens at our reception with the users fullname. We were thinking about firing a WOL packet to the computer of the coworker so he would be up and about as fast as possible. Or perhaps pour his or her favorite coffee recipe from the coffee maker. The options are endless, go hack something fun!