I Have a an arduino Mega 1280 and am reading 10 digit RFID tags. The code is below. Is there a way to change the code to were i can read rfid tags were i dont know the length of the RFID ?
#define TAG_LEN 12
char tag[12] = {'0', '1', '0', '3', '6', 'A', 'F', '2', 'B', '1'};
char code[12];
int bytesread = 0;
int ledPin = 13; // Connect LED to pin 13
int rfidPin = 22; // RFID enable pin connected to digital pin 2
int val=0;
void setup() {
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(rfidPin,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(ledPin,OUTPUT); // Set ledPin to output
digitalWrite(rfidPin, LOW); // Activate the RFID reader
}
void loop() {
if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.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
if(strcmp(code, tag) == 0) {
Serial.print("Tag matches: ");
Serial.println(code);
blink();
}
else {
Serial.print(code);
Serial.println(" does not match");
digitalWrite(ledPin,HIGH);
}
}
bytesread = 0;
delay(500); // wait for a second
}
}
}
void blink() {
digitalWrite(ledPin, HIGH);
delay(250);
digitalWrite(ledPin, LOW);
delay(250);
}
// extra stuff
// digitalWrite(2, HIGH); // deactivate RFID reader