RFID Reader
Last updated
Last updated
An RFID reader can be used to read ID numbers (or other data) stored in RFID tags, labels, and chips. RFID stands for "radio-frequency identification" – radio waves of a specific frequency are used to read the data from a distance.
RFID is used extensively by industries and stores to keep track of inventory. Some companies give their employees RFID cards for access to buildings and other purposes. Some people have their pets embedded with a RFID microchip to help identify the pet if it gets lost and is found by someone.
Near-Field Communication (NFC) is a type of RFID. For example, the Apple Pay and Android Pay features in certain smartphones use NFC.
The RFID reader kit comes with an RFID reader (the black reader module has pins that plug into to the female pins on the reader board) plus two RFID cards, which look blank but actually have a tag embedded in them that stores a unique ID number.
When an RFID card is brought within about 2 inches of the reader, it will be automatically identified. The RFID reader has a buzzer that beeps and a small green LED that lights up to verify that the card has been identified.
The RFID reader board has 8 different pin holes, but only 3 of these have to be connected. The easiest way to connect the RFID reader is to use a 3-wire JST connector. Connect the 3 wires (black, red, blue) to the corresponding pin holes, and then plug the male JST connector into different numbered rows on a breadboard. Then use jumper wires to connect the rows to the Photon. To make it easier to remember which wire is which, use corresponding black, red, and blue jumper wires to match the JST wires.
The RFID reader will send the card ID data to the Photon board over a serial data connection using the Photon RX pin.
NOTE: For serial data connections, the RX pin of one device connects to the TX pin of the other device. (RX = receive, TX = transmit)
FYI: The RFID reader also has a Mini-USB port, which can be used to connect it directly to a computer (instead of wiring it to a Photon or other microcontroller device). However, you will not use this port. (Also this Mini-USB port is different from the Micro-USB cable included with your Photon kit.)
The RFID reader does not require any special code library. (It does use a serial data connection, but serial data functions are built-in to the Particle firmware on your Photon device.)
Each RFID card has a code consisting of 16 characters (combination of numbers and letters): 12-character unique ID code + 4 special characters (that are not unique). When we read the RFID card, we only want to keep the unique ID code.
In the global variables, you should declare an array variable of 13 characters, which will be used to store the unique ID code from the RFID card. (The array will include 1 extra character at the end, which will always be zero. This is needed for converting the character array to a String.) The example below declares an array variable called "RFID" (but you could use a different variable name).
You will probably want to also declare a String variable that will simply be a text version of the RFID (the array is separate pieces of data, while the String is the same data stored as one piece). This String variable will be easier to use for purposes such as comparing the ID to a set of known IDs, sending the ID to your web app, etc. The example below declares a String variable called "idCard" (but you could use a different variable name).
You need to include a statement within the setup()
function to start a serial data connection (which will activate both the RX and TX pins on the Photon). This will allow the Photon to receive data from the RFID reader. The RFID reader communicates at a baud rate of 9600 bps.
Code for reading an RFID card should probably be placed within its own custom function, which can then be called within the loop()
function.
Inside the readRFID()
function, you will have to insert additional code to do something with the ID after it has been read (such as compare the ID to a set of known IDs, send the ID to your web app as an event notification, etc.).
RFID Reader
Photon Pin
VCC - Power (Black)
3.3V
TX - Data (Red)
RX
GND - Ground (Blue)
GND