[tutorial] RFID

RFID Tutorial from codebender on Vimeo.

RFID is an Arduino library for interfacing RFID readers that communicate with either a UART or a Wiegand protocol. The library receives data coming from an RFID reader, does some processing to extract the available information, performs a validity check on that data, and then offers all that information back to you.


The library has two accompanying examples that demonstrate, respectively, how you can use the library in UART and Wiegand mode.


If you have an ID Innovations RFID reader, make the following connections with your Arduino and the reader.


To use your RFID reader you have to create an RFID instance with the mode of operation, RFID_UART, and the pin to which you have connected the TX line of the reader. After that, you declare an RFIDTag struct that will hold the information of the tags. The available fields of the struct are the manufacturer's code, the card code, the checksum, a validity flag, and a raw field that holds all the information as received from the reader.

You can then check if there is a tag available to read with the available() method, and then read it by calling getTag().

There is one more method you can use, if you need to parse the data of the tag in a way other than the one provided by the library. Perhaps you want a number that will include both the manufacturer's code and the card code. Then, you can call hex2dec(char *, byte, byte) with arguments a char array, and the index of the start and end byte in the char array of the field you need.

Wiegand Mode

Make the following connections with your Arduino and the reader.


Again, you create an RFID instance with the mode of operation, RFID_WIEGAND, but this time you provide as a second argument a constant for the specific type of the Wiegand protocol. The library supports the 26bit format and the 35bit HID Corporate 1000 format. So, on the constructor you will have to write as a second argument either W26BIT or W35BIT.
Just notice that in the 26bit format, you only receive 26 bits, and this is less than what you would get with a UART reader... so now, you can only read the card code, but not the manufacturer's code, "lessening" that way the security of your system.

The rest is the same. Declare an RFIDTag struct, and use available() and getTag() to check and read the data from the tag, respectively.

That's all folks. We hope you enjoy the library, and if you have any comments or suggestions you can contact us at girder [at] codebender [dot] cc

Sounds are from freesound.org. Schematics were based on Fritzing.