How to connect Arduino and RFID

 by otaviousp
Featured
DSC05298.JPG
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
 
Remove these adsRemove these ads by Signing Up

Step 1: What you gonna need?

- Arduino Board
- RFID Sensor from seeedstudios
- Wires
- Protoboard
- RFID tags (125kHz) from seeedstudios
1-40 of 85Next »
epidemicz says: Oct 13, 2009. 4:30 AM
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.
otaviousp (author) in reply to epidemiczOct 13, 2009. 5:16 AM
Nice, thank you for the positive feedback. xD
cmalivoire says: Apr 10, 2013. 6:14 AM
Great guide, however I do need some help. I've followed this guide connecting the module to my Arduino UNO that I have just downloaded the libraries for. However when I run the code, it downloads, but shows no response when a card is passed over the antenna. I have tried this with another module and 10 different cards to check if its faulty equipment, but all have the same result. Any help would be greatly appreciated.
otaviousp (author) in reply to cmalivoireApr 10, 2013. 1:14 PM
Hey,
Can you send me pics of your circuit and your code?
I did not try this conde with UNO. With any one here make it works with this arduino please help us.
Cya
otaviousp (author) says: Apr 10, 2013. 1:12 PM
Hey,
Can you send me pics of your circuit and your code?
I did not try this conde with UNO. With any one here make it works with this arduino please help us.
Cya
balljoe says: Mar 4, 2013. 10:53 AM
I just want to say my experience on my testing. The sketch (RFID_arduino_version_1.0.1.txt),
Tx from RFID board goes to Digital PIN 5 on Arduino Board, not PIN 2.
But the old sketch is point at PIN 2, so I think that why some people said that's not work.
balljoe says: Mar 4, 2013. 4:48 AM
I forget to say the model for my arduino is uno.
arcraven says: Dec 28, 2012. 6:49 AM
Will a low frequency reader like this one pick up high frequency tags? Is there any advantage to using a high frequency reader instead?
otaviousp (author) in reply to arcravenJan 2, 2013. 2:52 PM
Sorry men, I have no idea.
billgeo says: Dec 13, 2012. 3:03 PM
Very nice instructable!

I am interested in winding my own antenna for 125Khz RFID.
Any ideas or links about the physical properties of the antenna?

Thank you
otaviousp (author) in reply to billgeoJan 2, 2013. 2:48 PM
Sorry men, no idea, I try once but I give up.
3tuxedo says: Dec 28, 2012. 5:52 PM
I can't quite get it to work though, and I think this is why. On my Arduino the RX is pin 0. I saw that pin 2 is RX for you, what do I have to change for that code to work with my project?
Petushka says: Oct 31, 2012. 2:09 PM
I had modified authors code to work with Arduino 1.0.1
otaviousp (author) in reply to PetushkaNov 1, 2012. 4:46 AM
If you can send me the code I will upload and keep the credits to you.
otaviofedrizze@gmail.com
Regards
Otavio
Petushka in reply to otaviouspNov 1, 2012. 11:19 AM
Send sketch on email. Check...
otaviousp (author) in reply to PetushkaNov 5, 2012. 3:53 AM
Thank you very much Petushka.

Instructable update and code uploaded.
karabey says: Nov 2, 2012. 12:52 PM
Here is the working Code with Arduino 1.0 and over

#include

#define ADD_TAG_CODE "200537982AA" //change this ID with your own card TAG
#define DEL_TAG_CODE "20057370C6E"

SoftwareSerial mySerial(2, 3); // RX, TX
String msg;
String ID ; //string to store allowed cards

void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");

mySerial.begin(9600);
Serial.println("RFID Ready");
}

char c;

void loop(){

while(mySerial.available()>0){
c=mySerial.read();
msg += c;
//Serial.println(msg); //Uncomment to view your tag ID
//Serial.println(msg.length());
}
msg=msg.substring(1,13);
if(msg.indexOf(ADD_TAG_CODE)>=0) add();
else if(msg.indexOf(DEL_TAG_CODE)>=0) del();
else if(msg.length()>10) verifica();
msg="";

}

void add(){
Serial.print("What TAG do you wanna grant access?: ");
msg="";
while(msg.length()<13){
while(mySerial.available()>0){
c=mySerial.read();
msg += c;
}
}
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()<13){
while(mySerial.available()>0){
c=mySerial.read();
msg += c;
}
}
msg=msg.substring(1,13);
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(){
msg=msg.substring(1,13);
if(ID.indexOf(msg)>=0) Serial.println("Access granted.");
else
Serial.println("Access denied.");
}
karabey says: Nov 2, 2012. 5:23 AM
Somehow the Code has Errors.. Sorry but i am not a Coder :(


sketch_nov02a:5: error: 'NewSoftSerial' does not name a type
sketch_nov02a.cpp: In function 'void setup()':
sketch_nov02a:14: error: 'RFID' was not declared in this scope
sketch_nov02a.cpp: In function 'void loop()':
sketch_nov02a:22: error: 'RFID' was not declared in this scope
sketch_nov02a.cpp: In function 'void add()':
sketch_nov02a:40: error: 'RFID' was not declared in this scope
sketch_nov02a.cpp: In function 'void del()':
sketch_nov02a:66: error: 'RFID' was not declared in this scope
Meca242 says: Jan 19, 2012. 10:28 AM
When I try and verify the sketch it says "it says error "RFID" was not declared in the scope."

Please help me fix this!
otaviousp (author) in reply to Meca242Jan 19, 2012. 12:05 PM
Did you add the newsoftserial library?

You can find here: http://arduiniana.org/libraries/newsoftserial/
Meca242 in reply to otaviouspJan 23, 2012. 10:40 AM
Yup, I do have the newsoftserial library and it is still giving me the same error as before.
Petushka in reply to Meca242Nov 1, 2012. 11:29 PM
if you read more carefully http://arduiniana.org/libraries/newsoftserial/

you can find words:
*****************************************************************************************
"The latest version of NewSoftSerial is available here: NewSoftSerial12.zip. Note: don’t download this if you have Arduino 1.0 or later. As of 1.0, NewSoftSerial is included in the Arduino core (named SoftwareSerial)."
*****************************************************************************************
This means that on Arduino 1.0 and later this library named SoftwareSerial!
Thats why your program does not work...
macdja38 says: Aug 17, 2012. 11:31 PM
I would love 3 led's
1.Green excepted
2.red denied
3.yellow ready for an RFID card reprogramming

This would also make it easier for for people like me to connect a motor to the place the led was.

Thank you very much.
suadrif says: Jul 23, 2012. 3:18 AM
sir the connection still same if using arduino Uno ?
hissamu says: May 15, 2012. 7:46 PM
Olá Otavio! Parabéns pelo projeto, porém não estou conseguindo compilar o projeto. Adicionei a NewSoftSerial12 e tentei usando a versão 0021 da IDE do Arduino, só que fica dando erro no NewSoftSerial.cpp. Poderia me ajudar por favor? Obrigado!
mgerboni says: May 7, 2012. 8:23 PM
Friend, would you can send me this java application that is displaying the readings on the screen?
jayduino says: Apr 15, 2012. 10:31 PM
Hey Guys, this little board comes pre programmed with code.. Just hook it up to your computer if you don't want to mess around with arduino. You also have the option to program it if you want to be more creative. Just though I would share it.

http://www.jayconsystems.com/product_detail.php?prod_id=283
txmg says: Mar 19, 2012. 6:34 AM
sorry! when i put code in arduino 1.0
it with this problem
sketch_mar19a.cpp:1:27: error: NewSoftSerial.h: No such file or directory
sketch_mar19a:5: error: 'NewSoftSerial' does not name a type
sketch_mar19a.cpp: In function 'void setup()':
sketch_mar19a:14: error: 'RFID' was not declared in this scope
sketch_mar19a.cpp: In function 'void loop()':
sketch_mar19a:22: error: 'RFID' was not declared in this scope
sketch_mar19a.cpp: In function 'void add()':
sketch_mar19a:40: error: 'RFID' was not declared in this scope
sketch_mar19a.cpp: In function 'void del()':
sketch_mar19a:66: error: 'RFID' was not declared in this scope
does it mean needing head file "NewSoftSerial.h"
txmg in reply to txmgMar 19, 2012. 7:57 AM
may be i know
Mark3rr says: Jun 24, 2011. 5:03 PM
Hello,
Im a newbie, but I like to play araund with arduino and cool stuff like the rfid reader.
My problem is the code.

i used the little part of code from mwp

to make the arduino`s serial monitor speak to me. But the only thing it says is:
access denied
access denied
access denied
access denied
no matter what a Tag i use it ever gets this failure..

What can I do now..
please help me :)
wfelix in reply to Mark3rrFeb 19, 2012. 5:06 AM
have you change the id cards in the code?
pmason3 says: Dec 5, 2011. 1:17 AM
Hi, I am very new to the whole arduino thing, so I may have jumped in too deep for this one. I am having troubles using the NewSoftSerial library, i keep getting errors when attempting to compile;

In file included from FY1Z49MGH89ZZ95.cpp:1:
C:\Users\joker\Downloads\arduino-1.0-windows\arduino-1.0\libraries\NewSoftSerial/NewSoftSerial.h:71: error: conflicting return type specified for 'virtual void NewSoftSerial::write(uint8_t)'
C:\Users\joker\Downloads\arduino-1.0-windows\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)

Am I missing other libraries? Any help at all would be greatly appreciated!
wfelix in reply to pmason3Feb 19, 2012. 5:05 AM
Also, you should read this in "newsoftserial"page: "The latest version of NewSoftSerial is available here: NewSoftSerial12.zip. Note: don’t download this if you have Arduino 1.0 or later. As of 1.0, NewSoftSerial is included in the Arduino core (named SoftwareSerial)."
wfelix in reply to pmason3Feb 19, 2012. 5:02 AM
Actually, arduino 1.0 has a LOT of incompatibilities with old libraries... try to downgrade to 0023 or 0022

When you got more expertise, you can adapt the old libraries to work with new 1.0 arduino SDK ;)
otaviousp (author) in reply to pmason3Dec 5, 2011. 5:36 AM
Try to update your arduino IDE.
psicopato says: Oct 1, 2011. 11:40 AM
Hi,


I'm a nooby to RFID and as well to arduino stuff.

I'm trying to keep the accepted cards in arduino's EEPROM and I managed to do so but it is getting difficult to know which way to grant access by comparing the read card number and stored card number. How can I do that??
danieljcooper says: Jul 16, 2011. 8:44 AM
How do I stop the reader from reading a card once it has read one?
I am having problems with the reader reading the add and delete cards twice. Hope that makes sense. Cheers
mwp says: Mar 19, 2011. 9:32 AM
i have just been trying this code on a Duemilanove with an ATMEGA328, and was not seeing any response to the RFID tags.

When I uncommented the println statements in the reading loop it worked as expected, so it seems that the program was trying to read the bytes too fast. After the first byte is read it loops back to test if another byte is waiting, and if it is not, then the loop exits with the string 'msg' just one byte long.

It works when the println is executed, because then there is always time for the next byte to arrive before RFID.available is called.

The solution is to add an explicit delay:

while(RFID.available()>0){
c=RFID.read();
msg += c;
delay(1); //allow time for another byte to arrive
//Serial.println(msg); //Uncomment to view your tag ID
//Serial.println(msg.length());
}
devondo says: Feb 10, 2011. 3:48 PM
What is you code? i can't download it here its just a Tmp file
otaviousp (author) in reply to devondoFeb 10, 2011. 5:46 PM
rename it to .pde
1-40 of 85Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!