How to Connect Arduino and RFID

420,361

398

184

Introduction: 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


1 Person Made This Project!

Recommendations

  • Battery Powered Contest

    Battery Powered Contest
  • Plywood Challenge

    Plywood Challenge
  • Plastic Contest

    Plastic Contest

184 Discussions

0
epidemicz
epidemicz

11 years ago on Introduction

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.

0
otaviousp
otaviousp

Reply 11 years ago on Introduction

Nice, thank you for the positive feedback. xD

0
GiovanniC84
GiovanniC84

Question 1 year ago on Step 1

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.

0
nugax1
nugax1

2 years ago on Step 3

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.");
}

0
SolomonB21
SolomonB21

Question 2 years ago on Step 4

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

0
John_03
John_03

2 years ago

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?:

0
TrầnÂ19
TrầnÂ19

2 years ago

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

can you help me ?

thanks.

0
greatescapeprops
greatescapeprops

3 years ago

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.

0
Gregory Akau
Gregory Akau

4 years ago

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

0
ShoaibH3
ShoaibH3

4 years ago

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

0
sweeth
sweeth

4 years ago

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

0
otaviousp
otaviousp

Reply 4 years ago

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

0
sweeth
sweeth

Reply 4 years ago

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

0
lef11
lef11

4 years ago

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?

0
otaviousp
otaviousp

Reply 4 years ago

send me your code and a pic of your schematic

0
lef11
lef11

Reply 4 years ago

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?

0
AroojZ
AroojZ

7 years ago on Introduction

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.

0
F-sidd142
F-sidd142

Reply 4 years ago

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

0
otaviousp
otaviousp

Reply 4 years ago

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

0
MandeepS1
MandeepS1

Reply 6 years ago on Introduction

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