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
i even changed the code and replaced your tag details with mine ..but still showing as access denied
otaviousp (author)  saiganesh_panchu2 years ago
Can you send me a video showing what are you doing and the messages that appear on the screen?
I have three cards with card id (6B0037E8398D) (6B0037E158E5 ) (0800692B5D17)

when i replace your cards with my card details , i get access denied in my serial monitor with the correct code of my tag displayed

display in serial monitor

Serial Ready
RFID Ready
Access denied.

otaviousp (author)  saiganesh_panchu2 years ago
On my example you gonna need 2 cards. 1 card to authorize other cards and another card to delete the authorized cards.
For example:
On the code replace ADD_TAG_CODE "210014DFE309" to ADD_TAG_CODE "6B0037E8398D"
and replace DEL_TAG_CODE "210014E2BD6A" to DEL_TAG_CODE "6B0037E158E5"

Recompile and restart your Arduino.

Now, Take the first card number 6B0037E8398D and approach to the sensor and take it away
Then take the third card number 0800692B5D17 and approach to the sensor. A message should appear telling you that for this card authorization has been granted,
And Now you can use it to have access.

Sorry for my bad english, hope that esxplanation can help you. Any problem please ask.
grocha32 years ago
Not work for me , I'm using RIFD R/W YHY502CTG 13.56 Mhz. I set it to 19200 bauds. but the same that code return characters not recognizable. Sorry for my English...
balljoe2 years ago
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.
macdja383 years ago
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.
hissamu3 years ago
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!
Meca2423 years ago
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)  Meca2423 years ago
Did you add the newsoftserial library?

You can find here: http://arduiniana.org/libraries/newsoftserial/
Yup, I do have the newsoftserial library and it is still giving me the same error as before.
Guibom5 years ago
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
otaviousp (author)  Guibom5 years ago
Opa, é nois, xD

Se precisar de algo, pede ae.

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)  nrodrigues4 years ago

Tente usar este tutorial, duvida me pergunta.

mwp4 years ago
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:

msg += c;
delay(1); //allow time for another byte to arrive
//Serial.println(msg); //Uncomment to view your tag ID
devondo4 years ago
What is you code? i can't download it here its just a Tmp file
otaviousp (author)  devondo4 years ago
rename it to .pde
paradox1164 years ago
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)  paradox1164 years ago
Try to download the code and rename the file to rfid.pde.

If it does not work, plz tell me.
It keeps downloading it as a .TMP file. It's probably some simple fix that I just don't know about.
arduinoer5 years ago
where can we get the WString library?
otaviousp (author)  arduinoer5 years ago
arduinoer5 years ago
where can we get the new library, without it it's worthless?
otaviousp (author)  arduinoer5 years ago
SubMicro5 years ago
where did you get the library?