3

(coco) #1
FORGE

YOU’LL NEED
Raspberry Pi
USB NFC/RFID
reader + some
coded fobs
Electronic door
striker plate
12 V 1.5 A
power supply
Female DC
power jack
5 V relay switch
(single-channel)
3 × DuPont
jumper cables
(female/female)
1 × extra cable
(male/male)

‘+’ or ‘5 V’) needs connecting with a jumper wire to
a 5 V pin on your Pi, and the negative (labelled either
‘GND’ or ‘-’) can go to any ground pin. The signal pin
(labelled ‘S’ or ‘in’) needs to go to any numbered GPIO
pin. You can actually use any you like, but the code
examples later use the GPIO 13 pin, so you might as
well do the same, really.
The electronic door strike works with a little
electromagnet inside which pulls a small lever out of the
way when activated by a 12 V supply. As that is more
than the Raspberry Pi can supply, you need a separate
12 V power supply for this. A little DC power jack allows
you to easily connect to the positive and negative from
this supply’s cable. If you want, you can wire the striker
plate directly into the 12 V supply and test it out by
flicking the power switch and seeing how it allows you
to open it only when the 12 V is being supplied.


OPEN SESAME
To incorporate this into your circuit, wire the positive
supply from the 12 V socket into the middle terminal
(COMMON) of your relay switch. Then, connect the
final loose wire from the door strike into the Normally
Open terminal (usually labelled NO). Your striker plate is
now switched on/off by the relay switch connected to
your Raspberry Pi.
Now it’s time to get serious and write some simple
Python code to act as the brains between all of the


hardware components, switching the relay only when
a valid key fob is presented to the RFID reader.
The first thing to tackle is reading the data contained
in a key fob. Since we know that the newline
character is ‘typed’ when the fob’s code has finished
being entered, you can use that newline character’s
appearance as an event which will trigger some
decision-making in your code along the lines of: “is this
fob allowed to unlock the door?”
In order to get to that stage, you first need to write
some code to listen to the Input Device and capture
what’s being entered. This will involve using the evdev
module, so before you do anything else, type the
following into a Terminal window to ensure it’s installed
and available to use on your Raspberry Pi:
sudo pip install evdev

With that installed, create a new Python script called
lock.py in your favourite text editor. The first thing to
add to your script is the following lines:

Above
Each USB input device (e.g. mouse, keyboard) is
assigned its own ID by the Raspbian operating system.
You’ll need to know the ID your RFID reader has been
assigned so that you can listen to its input

To avoid having to run two separate power supplies,
consider using a dual-voltage power supply. If you
have an old computer PSU lying around, you can
easily make one yourself: simply use your multimeter
to find the 12 V and 5 V supply cables normally
delivered to a SATA hard drive. To make the PSU
power-up without needing an ‘On’ switch on the front
of a computer case, short out the green (signal) cable
to an unused black ground cable.

POWER SOURCE


12V


5V GND Pin 13


Left
A typical Raspberry
Pi setup with relay
switch powered by
pins 2 (5V) and 6
(GND) and switched
by the GPIO 13 pin
Free download pdf