Introduction: RFID Reader! MK: II, Card Identifiers
Hey guys I'm back with a second version of the code for an RFID scanner! This scanner is a great way to use your cards by holding values, balances, securities and many different things for RFID cards!
Entry Robot Challenge age group 13-17
Entry Robot Challenge age group 13-17
Step 1: Supplies
one RFID made circuit (version one) or you could follow the circuit diagram here. Read the big box which is a note, it is important.
Step 2: The Code!!!!!!!
This is a very simple code for comparision, it is actually a bit confusing of how to get your card number to be compared.
#include <SoftwareSerial.h>
#include <avr/interrupt.h>
int val = 0;
char code[10];
int bytesread = 0;
#define rxPin 8
#define txPin 9
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8
void setup()
{
Serial.begin(9600); // Hardware serial for Monitor 9600bps
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
}
void loop()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.read();
if((val == 10)||(val == 13))
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
if(bytesread == 10)
{ // if 10 digit read is complete
Serial.println("TAG code is: "); // possibly a good TAG
Serial.print(code); // print the TAG code
validateRFID(code);
}
bytesread = 0;
delay(500); // wait for a second
}
}
void validateRFID(char* i) {
if( strncmp(i,"12000C9DBF", 10) == 0) {
// if 10 digit code equals "12000C9DBF"
digitalWrite(13, HIGH);
Serial.println(" Correct Tag");
delay(1000);
digitalWrite(13, LOW);
} else {
digitalWrite(13, LOW);
}
}
#include <SoftwareSerial.h>
#include <avr/interrupt.h>
int val = 0;
char code[10];
int bytesread = 0;
#define rxPin 8
#define txPin 9
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8
void setup()
{
Serial.begin(9600); // Hardware serial for Monitor 9600bps
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
}
void loop()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.read();
if((val == 10)||(val == 13))
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
if(bytesread == 10)
{ // if 10 digit read is complete
Serial.println("TAG code is: "); // possibly a good TAG
Serial.print(code); // print the TAG code
validateRFID(code);
}
bytesread = 0;
delay(500); // wait for a second
}
}
void validateRFID(char* i) {
if( strncmp(i,"12000C9DBF", 10) == 0) {
// if 10 digit code equals "12000C9DBF"
digitalWrite(13, HIGH);
Serial.println(" Correct Tag");
delay(1000);
digitalWrite(13, LOW);
} else {
digitalWrite(13, LOW);
}
}
Step 3: Enjoy.
Thanks for the comments and PMs, they helped me decide what to include in version 2. Thanks so much, feel free to post comments, have questions, or share your experience. Thanks, Simon