RFID Card Reader Apps

Blank RFID (Radio Frequency ID) cards along with a USB based RFID card reader can offer an easy and low cost solution for your Pi security projects.

For under $10 we were able use blank RFID cards (5 for $3) and a generic USB based RFID card reader ($6).

Using some simply Python code it is possible to make projects for security systems, door entry systems or control of remote devices.

powerswitch

RFID Cards and Readers

The RFID cards and readers need to work at the same frequency. For us we used the lower cost 125 KHz equipment.

The blank 125 KHz RFID cards have a predefined RFID number, this number is typically written on the card. These blank cards are be used directly, so no programming and writing to the card is required.

card

The USB card reader will momentarily light up and beep when it reads a card. The USB card reader act like a USB keyboard and it will pass the card’s RFID number as a series of key strokes. An <ENTER> key is sent at the end of the sequence.

Get RFID numbers and Build a Lookup Table

To verify the cards RFID number, open a terminal session and start swiping the cards. The cards ID numbers should appear at the command line  (and your system won’t know what to do with the numbers):


pi@raspberrypi:~ $ 0006241052
bash: 0006241052: command not found
pi@raspberrypi:~ $ 0003617750
bash: 0003617750: command not found

The next step is to create a simple text file (card_id.txt) with the valid RFID card numbers:

0006241052
0003617750
...

Create a Test Setup

For a simple test setup we used some Lego to security the card reader, Pi and a small breadboard.

setup

A simple LED circuit was used, with the LED wired to GPIO 7 (BCM pin 4), and the other side to GND.

circuit

Python Application

A simple Python application can be written to:

  • read the RFID card that is swiped
  • check it against a lookup fire (card_ids.txt)
  • if the card is valid do some action (like toggle an LED).
#
# swipecard.py - read swipecard and toggle a Pi output
#
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
LEDpin = 4
GPIO.setup(LEDpin,GPIO.OUT)
while True:
print "Swipe RFID card to toggle I/O"
card_id = raw_input()
print "card id is:", card_id
id_file = open("card_ids.txt","r")
for line in id_file:
if (card_id == line.strip()):
GPIO.output(LEDpin, not GPIO.input(LEDpin))
print "Valid Card"

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s