RFID Reader! Identify Anything With RFID From Credit Cards to License Plates

by simonfrfr in Circuits > Arduino

31413 Views, 87 Favorites, 0 Comments

RFID Reader! Identify Anything With RFID From Credit Cards to License Plates

IMG_0816[1].JPG
Hey guys today I just got an RFID Reader module from Parallax! I tried it out and made this program which identifies cards and other RFID products! All you need is a computer, an Arduino, a breadboard, and the Parallax RFID Reader Module! Please share your experiences, I am in wonder of what may have happened to you while building it or something like that! Thanks.

The Circuit!

Arduino Module.PNG
This is a very simple circuit which only needs four wires! (besides the usb) Down below is a diagram!

The Code and Have Fun Scanning Cards and Getting Their IDs

DICE PROG.PNG
//RFID Reader Module Read and indentify by simonfrfr
#define RFID_ENABLE 2 //to RFID ENABLE (connect pin 2 to the /Enable)
#define CODE_LEN 10 //Max length of RFID tag
#define VALIDATE_TAG 1 //should we validate tag?
#define VALIDATE_LENGTH 200 //maximum reads b/w tag read and validate
#define ITERATION_LENGTH 2000 //time, in ms, given to the user to move hand away
#define START_BYTE 0x0A
#define STOP_BYTE 0x0D

char tag[CODE_LEN];

void setup() {
Serial.begin(2400); //fequency needed becuase the used frequency on the RFID Reader Module
pinMode(RFID_ENABLE,OUTPUT);
}

void loop() {
enableRFID();
getRFIDTag();
if(isCodeValid()) {
disableRFID();
sendCode();
delay(ITERATION_LENGTH);
} else {
disableRFID();
Serial.println("Error: Unable to complete process!");
}
Serial.flush();
clearCode();
}

/*
Clears out the memory space for the tag to 0s.
*/
void clearCode() {
for(int i=0; i<CODE_LEN; i++) {
tag[i] = 0;
}
}

/*
Sends the tag to the computer.
*/
void sendCode() {
Serial.print("TAG:");
for(int i=0; i<CODE_LEN; i++) {
Serial.print(tag[i]);
}
}

/*

RFID Functions
*/

void enableRFID() {
digitalWrite(RFID_ENABLE, LOW);
}

void disableRFID() {
digitalWrite(RFID_ENABLE, HIGH);
}

/*
Blocking function, waits for and gets the RFID tag.
*/
void getRFIDTag() {
byte next_byte;
while(Serial.available() <= 0) {}
if((next_byte = Serial.read()) == START_BYTE) {
byte bytesread = 0;
while(bytesread < CODE_LEN) {
if(Serial.available() > 0) { //wait for the next byte
if((next_byte = Serial.read()) == STOP_BYTE) break;
tag[bytesread++] = next_byte;
}
}
}
}

/*
Waits for the next incoming tag to see if it matches
the current tag.
*/
boolean isCodeValid() {
byte next_byte;
int count = 0;
while (Serial.available() < 2) { //there is already a STOP_BYTE in buffer
delay(1); //probably not a very pure millisecond
if(count++ > VALIDATE_LENGTH) return false;
}
Serial.read(); //throw away extra STOP_BYTE
if ((next_byte = Serial.read()) == START_BYTE) {
byte bytes_read = 0;
while (bytes_read < CODE_LEN) {
if (Serial.available() > 0) { //wait for the next byte
if ((next_byte = Serial.read()) == STOP_BYTE) break;
if (tag[bytes_read++] != next_byte) return false;
}
}
}
return true;




Have fun scanning all of your objects! I had fun too! It is a very cool module! When the reader is waiting for a RFID Tag then the LED is RED. Look at some of my other projects at https://www.instructables.com/id/Candy-Drop-dispenser/
https://www.instructables.com/id/Password-protected-Secret-Telling-Arduino/
https://www.instructables.com/id/Arduinik-The-HumanoidBiped-Robot/