How to Connect Arduino and RFID

428K400191

Intro: How to Connect Arduino and RFID

On this instructable I will try to show how to interface a RFID sensor with the Arduino. I am using the RFID sensor from seeedstudio the serial version of it. There are a few parts you will gonna need. I also bought some RFID keys.

UPDATE: Now it works with IDE 021

STEP 1: What You Gonna Need?

- Arduino Board
- RFID Sensor from seeedstudios
- Wires
- Protoboard
- RFID tags (125kHz) from seeedstudios

STEP 2: Plugging All Together

Connect the antenna on the appropriate pins like the first photo.

Plug the RFID sensor to the protoboard like the second photo above.

Only 3 wires are required to interface, 2 wires for supply and another for the serial line(communication)
The wires as connected as the third photo shows.
On RFID sensor: PIN 1 -> Tx
PIN 2 -> Rx (Not Used)
PIN 3 -> NC
PIN 4 -> GND
PIN 5 -> VCC (+5V)

Tx from RFID board goes to Digital PIN 2 on Arduino Board.

That is all you gonna need to wire.

Moving on to next step, the software.

STEP 3: The Code

I'm not a software guy, so this code is just for demonstration.

I don't make any kind of checksum at the tags code, but it seems to work fine.

The code is really simple. I used a new library for the serial, using software emulation.

With the two white cards you can deny or allow the access of others keys.

Any doubt, please ask me.

Edit (05/11/12):
code update for new Arduino version

STEP 4: Results!

There is no LED, sound or LCD for debug or visualization, just through the serial line.

The video demonstrate how to use the software. I didn't post any kind of explanation as text on the video. I hope that the images spokes more then words, xD

Any doubt or suggestion, feel free to ask, or correct me.

Please, if you like it, rate it,

thank you


184 Comments

Thanks for the instructable man, really appreciate it.  I've been wanting to do something with rfid and this is going to help me out big time.
Nice, thank you for the positive feedback. xD
Do yo know where I could find something similar for 134.2 kHz ? I have a Raspberry Pi and I would like to be able to clone the RFID in the key of my car.
Sorry, but the code doesn't work as expected.
Attached find my version which does what it should do.
/*########################################################################
## Modified code to work with Arduino 1.0.1 / ##
## Credits to Petushka, https://www.instructables.com/member/Petushka/ ##
## https://cdn.instructables.com/ORIG/FM4/KU9W/H91LGBA6/FM4KU9WH91LGBA6.txt
########################################################################*/
#include <SoftwareSerial.h>
#define ADD_TAG_CODE "bfbdbfa57de717a0" //change this ID with your own card TAG (2)
#define DEL_TAG_CODE "bfbdbfa5899d5420" //change this ID with your own card TAG (1)
SoftwareSerial rfid = SoftwareSerial(2, 3,true);
String msg;
String ID ; //string to store allowed cards
void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");
rfid.begin(9600);
Serial.println("RFID Ready");
}
char c;
int i;
void loop(){

while(rfid.available()>0){
i=rfid.read();

msg += String(i,HEX);
Serial.print(i,HEX);
Serial.print(" - ");
Serial.println(msg.length());
}
// msg=msg.substring(0,15);
if(msg.indexOf(ADD_TAG_CODE)>=0) add();
else if(msg.indexOf(DEL_TAG_CODE)>=0) del();
else if(msg.length()>10) verifica();
msg="";

}// Ende von Loop ----------------------------------------------------------------------------
void add(){
Serial.print("What TAG do you wanna grant access?: ");
msg="";
while(msg.length()<16){
while(rfid.available()>0){
i=rfid.read();
msg += String(i,HEX);
}
}
if(ID.indexOf(msg)>=0) {
Serial.println("\nAccess already granted for this card.");
msg="";
}
else{
Serial.print("Card: ");
Serial.println(msg);
ID += msg;
ID += ",";
//Serial.print("ID: ");
// Serial.println(ID);
msg="";
Serial.println("Access granted for this card.");
}
}//---------------------------------------------------------------------
void del(){
msg="";
Serial.print("What TAG do you wanna deny access?: ");
while(msg.length()<16){
while(rfid.available()>0){
i=rfid.read();
msg += String(i,HEX);
}
}
msg=msg.substring(0,15);
if(ID.indexOf(msg)>=0){
Serial.println(msg);
Serial.println("TAG found. Access for this card denied.");
//ID.replace(card,"");
int pos=ID.indexOf(msg);
msg="";
msg += ID.substring(0,pos);
msg += ID.substring(pos+15,ID.length());
ID="";
ID += msg;
//Serial.print("ID: ");
//Serial.println(ID);
} else Serial.println("\nTAG not found or already denied");
msg="";
}//--------------------------------------------------------------------
void verifica(){
Serial.println(msg);
msg=msg.substring(0,15);
if(ID.indexOf(msg)>=0) Serial.println("Access granted.");

else Serial.println("Access denied.");
}
What is the range of RFID reader you are using?? It must be around 1cm
How to increase the range upto 30 cm?
By increasing the coil loop of antenna can the range be increased?.. Instead of reading.. Just detecting the presence of rfid tag is possible right?.. Kindly answer my doubts. Thank you

Hello and Thank you for the post.

I have in serial output this:

Access already granted for this card.

1
8
2
86
3
860
4
8600
5
86008
6
860088
7
8600887
8
8600887B
9
8600887B5
10
8600887B53
11
8600887B53&
12
8600887B53&
13
What TAG do you wanna grant access?:

i connected module to arduino promini with your code but i can see my tag code in serial monitor.

can you help me ?

thanks.

Thanks for the tutorial. I have it all working but the cards do not read fast enough or not at all. I have to put the cards directly on the antenna. Any ideas on this? I have all 125Mhz cards with the correct reader and hookup is correct. Thanks.

Don't know why I'm having a multiple read for each card I swap

plz send me rfid code at this shoaibhassan031439@gmail.com
i need it urrgent...plz

Hi, This is really nice. Can we calculate distance also? if in case we would like to calculate distance as how much far or close the tag is with reader , is that possible?

Regard's

Hari

I don´t think it is possible to do that with this particular module.

Hi, Thanks for the kind response,

Can we measure distance via signal strength? Or can you please suggest me any other module? I have MLX 90109 with DVK 90109 and EVB 90109

I had the readers and they dont seem to be reading i have them hooked up the way you have it set up but how does your code work? there arent any comments throughout the code and i have been looking to use them for a school project. can you help?

send me your code and a pic of your schematic
Just figured it out now how can i get the id part out of whats being read? I also noticed that sometimes im reading double of the same part of the code?
Hi I have arduino Mega ADK, Here is a preview of it, http://arduino.cc/en/uploads/Main/ArduinoADK_R3_Front.jpg can you tell me where to connect the TX of RFID in the arduino board? I,m an extreme beginner so if my question is stupid please bear with me. Just tell me the exact pin number on which to attach from the arduino board's picture! Thanks in advance.

i have the same problem. please tell if someone have sorted out.

Send me your code and a pic or schematic of your conection

Have your been able to figure it out pl, I have the same question

More Comments