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:


// Sketch code based on the one found in "Reading RFID Tags in Processing" chapter
// of the book Making Things Talk published by O'Reilly

import processing.serial.*;

Serial myPort;
String tagID="";

void setup() {
size(350,150);
myPort = new Serial(this, "COM4", 2400);
myPort.buffer(12);

PFont myFont = createFont(PFont.list()[2], 24);
textFont(myFont);
}

void draw(){
background(0);
text(tagID, width/4 + 12, height/2 - 24);
}

void serialEvent(Serial myPort) {
tagID = trim(myPort.readString());
}

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 as rfid1.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:

// Sketch code based on the one found in "Reading RFID Tags in Processing" chapter
// of the book Making Things Talk published by O'Reilly
// Library TTSLib from GuruBlog found at http://www.local-guru.net/blog/pages/ttslib is required

import processing.serial.*;
import guru.ttslib.*;

TTS tts;
Serial myPort;
String tagID="";

void setup() {
size(350,150);
myPort = new Serial(this, "COM4", 2400);
myPort.buffer(12);

PFont myFont = createFont(PFont.list()[2], 24);
textFont(myFont);
smooth();
tts = new TTS();

}

void draw(){
background(0);

if (tagID.equals("34009EA5AF")) {
PImage b;
b = loadImage("tayeb.jpg");
image(b, 20, 20);
text(tagID, width/2 - 6, height/2 - 24);
text("TAYEB", width/2 - 6, height/2);
}
else {
text(tagID, width/4 + 6, height/2 + 12);
}
}
void serialEvent(Serial myPort) {
tagID = trim(myPort.readString());
if (tagID.equals("34009EA5AF")) {

tts.speak("Hi! Welcome Tayeb!");
}

else {
tts.speak("Invalid Card!");
}
}

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.

Advertisements

About Tayeb

Electronics engineer, part-time webmaster and owner of "Aliatron", a tech-oriented company registered in Portugal and Mozambique.
This entry was posted in Electronic Projects, Information Technolody, Programming and tagged , , , , , . Bookmark the permalink.

4 Responses to Access Control with RFID Tags

  1. sirish says:

    hi.. im very much interested in doing project on RFID tags… im studying btech 4th year now… so can u please provide me with the circuit diagram and other main details which are required to build these project.. please

    • Tayeb says:

      Welcome to my blog Sirish,

      I have a used a PC and with USB port, USB RFID reader and Processing. There is no much circuit in it.

      You could perhaps use a micrconcontroller, instead of a PC and some sort of storage say in EEPROM of microcontroller, or other memory system. T

      he objective of my experiment was to show how easy it is read RFID cards.

      In the article I have added a link to a project using C# and sql. May be you could a much more sophisticated project than one I have shown, as your is a course project and has to be with more substantive.

  2. Elex says:

    Thanks for your kindly shared!!!
    Its pretty useful & helpful!

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s