How to connect Arduino and RFID by otaviousp
Featured

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
 
Remove these adsRemove these ads by Signing Up
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.
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) says: Jan 19, 2012. 12:05 PM
Did you add the newsoftserial library?

You can find here: http://arduiniana.org/libraries/newsoftserial/
Meca242 says: Jan 23, 2012. 10:40 AM
Yup, I do have the newsoftserial library and it is still giving me the same error as before.
Petushka says: Nov 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.
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!
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) says: Feb 10, 2011. 5:46 PM
rename it to .pde
paradox116 says: Jan 3, 2011. 4:21 AM
I can't get to the code you included here and I'm still learning the ins and outs of programming.. could you please send me the code in a private message? I have the same RFID reader and I'm stalled on my project until I can figure out how to get my code to work. Thanks!
otaviousp (author) says: Jan 15, 2011. 6:13 AM
Try to download the code and rename the file to rfid.pde.

If it does not work, plz tell me.
paradox116 says: Jan 16, 2011. 2:33 AM
It keeps downloading it as a .TMP file. It's probably some simple fix that I just don't know about.
Guibom says: Mar 22, 2010. 9:42 PM
Hey Man, thanks!! I thought my RFID was broken... I could get the LED to flash when I scanned a card, so I knew the antenna/etc was ok  But I couldn't read the card at all... Turns out using the old SoftwareSerial didn't really work out.
When I saw your example and changed to the NewSoftwareSerial, it instantly fixed the problem.

E vc e' Brasileiro ne'?! =D
vitizen says: Aug 17, 2010. 10:45 PM
how did u get the LED to flash, the LED connected from LED out to ground, does not flash when connected to a 5V DC supply. thanks
otaviousp (author) says: Mar 23, 2010. 6:26 AM
Opa, é nois, xD

Se precisar de algo, pede ae.

Abrass
nrodrigues says: Mar 26, 2011. 4:49 AM
boas, eu gostava de controlar os 8 leds via webrowser no arduino ( D2 a D9 )
ou seja uma pagina simples em que tenha um ON e OFF via ethernet atravez dele....

email : lx.nuno.rodrigues@gmail.com


OBS : Estou a usar o Arduino Uno + Ethernet Shield ( com MiniSD )
otaviousp (author) says: Apr 26, 2011. 8:02 AM
Ola,

Tente usar este tutorial, duvida me pergunta.

http://www.instructables.com/id/Ethernet-Shield-LED-WEB-SERVER/
arduinoer says: Jul 25, 2010. 11:22 AM
where can we get the WString library?
otaviousp (author) says: Jul 25, 2010. 1:07 PM
arduinoer says: Jul 25, 2010. 6:25 AM
where can we get the new library, without it it's worthless?
otaviousp (author) says: Jul 25, 2010. 8:51 AM
SubMicro says: Nov 2, 2009. 1:30 PM
where did you get the library?
otaviousp (author) says: Nov 3, 2009. 2:34 AM
(removed by author or community request)
SubMicro says: Nov 3, 2009. 9:57 AM
That is not the NewSoftSerial library.  Also I'm trying to use this RFID reader to create an automatic door lock, any help would be appreciated. 
otaviousp (author) says: Nov 3, 2009. 10:23 AM
sorry, my bad

http://arduiniana.org/libraries/NewSoftSerial/

cya
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!