Access Control with RFID Tags


Introduction
It is quite easy to read IDs of RFID tags, using Parallax’s serial or USB RFID card reader. If you have two RFID cards at least, and of course Parallax RFID reader, you can set up, without hassle, the below described project. This blog contains several articles that show how easy it is, to control and communicate with electronic devices with Processing.
Objectives
Read RFID cards, using serial communications of Processing and Parallax RFID Card Reader, and show  useful information on-screen with user interaction.
Pre-Requirements
Installed Processing environment, RFID Card Reader USB #28340 from Parallax, at least 2 RFID Cards, and a USB cable for connecting between RFID Card Reader and PC.

The Experimental Set

Connecting to PC
The RFID Card Reader when correctly installed will be shown as a serial device.  Check the port number where the RFID reader is connected in Control Panel - > System – >Hardware tab -> Device Manager button -> Ports (COM and LPT)In this experiment the serial port was COM4. After cheking the port number you just need to take note of it to be introduced into next Processing sketch.
The Processing Sketch
Start a new sketch in Processing, and save it as rfid.pde.
The code for rfid.pde:
01// Sketch code based on the one found in "Reading RFID Tags in Processing" chapter
02// of the book Making Things Talk published by O'Reilly
03 
04import processing.serial.*;
05 
06Serial myPort;
07String tagID="";
08 
09void setup() {
10size(350,150);
11myPort = new Serial(this, "COM4", 2400);
12myPort.buffer(12);
13 
14PFont myFont = createFont(PFont.list()[2], 24);
15textFont(myFont);
16}
17 
18void draw(){
19background(0);
20text(tagID, width/4 + 12, height/2 - 24);
21}
22 
23void serialEvent(Serial myPort) {
24tagID = trim(myPort.readString());
25}
Make the adequate COM port changes in your sketch line 8 myPort = new Serial(this, “COM4″, 2400);
to your PC’s installed RFID Card COM port number. Run the sketch and check the TagIDs of both cards. In this case the codes obtained were 34009EA5AF and 0F00296C9FF. The former was chosen as valid card for next sketch. In your case it will be another number.
We will next produce our final sketch. Start a new Sketch in Processing and save it asrfid1.pde
TTS library is required to add voice to the project. TTSLib from GuruBlog is used. Install the unzipped file into your libraries folder of Processing. The library will be imported by Processing. Add image (in this case 100×100 tayeb.jpg is used) to your Processing projects folder, usually found under my Documents\Processing.
Our folder here will be rfid1.
So here is the code for our final rfid1.pde sketch:
01// Sketch code based on the one found in "Reading RFID Tags in Processing" chapter
02// of the book Making Things Talk published by O'Reilly
03// Library TTSLib from GuruBlog found at http://www.local-guru.net/blog/pages/ttslib is required
04 
05import processing.serial.*;
06import guru.ttslib.*;
07 
08TTS tts;
09Serial myPort;
10String tagID="";
11 
12void setup() {
13size(350,150);
14myPort = new Serial(this, "COM4", 2400);
15myPort.buffer(12);
16 
17PFont myFont = createFont(PFont.list()[2], 24);
18textFont(myFont);
19smooth();
20tts = new TTS();
21 
22}
23 
24void draw(){
25background(0);
26 
27if (tagID.equals("34009EA5AF")) {
28PImage b;
29b = loadImage("tayeb.jpg");
30image(b, 20, 20);
31text(tagID, width/2 - 6, height/2 - 24);
32text("TAYEB", width/2 - 6, height/2);
33}
34else {
35text(tagID, width/4 + 6, height/2 + 12);
36}
37}
38void serialEvent(Serial myPort) {
39tagID = trim(myPort.readString());
40if (tagID.equals("34009EA5AF")) {
41 
42tts.speak("Hi! Welcome Tayeb!");
43}
44 
45else {
46tts.speak("Invalid Card!");
47}
48}
Make the adequate changes as shown below in following images:

Port number of installed RFID reader

Other required changes

Now run the sketch. If you read the cards you will hear voice. In this case “Invalid card!” or “Hi Welcome Tayeb!”., or whatever name you have chosen. In our project with sketch code as above, the follow results were drawn on the PC’s screen:

Valid card

Invalid card

In fact any other RFID card, besides the chosen one, will be considered invalid.
Conclusions
Though this actual project is quite simple and the code is not neat, bub it can ve improved. As something extra and quite simple one could add a serial controlled relay or another micrcontroller controlled device.
Of course projects with Visual C#, and other programming languages, can be made to talk to RFID cards, and be quite sophisticated. Some useful RFID projects can be attendance control, stock control, livestock identification, etc.
RFIDs are here to stay, and are everywhere these days. It is quite important to learn to work with them.
Acknowledgements
A special thanks is due to Tom Igoe, author of O’Reilly’s  book“Making Things Talk” for the code with Processing.

No comments:

Post a Comment