Hi folks,
I am working on a basic RFID project. When I hold my ID-12 reader up to a known card, I should be able to find out which card it is over the serial monitor.
I've found some helpful sketches online but can't get my code to produce the right effect. The serial monitor's readout always declares that I'm holding up "TAG2" and only shows the card being read as 8 characters long. My cards hold 10 characters. I've fiddled around with both the number of digits in the known tag arrays and in the length of the char strings to no avail.
Thanks in advance for all of your help.
Here's the readout when I scan both cards:
TAG code is: 5100FEA6
TAG1 code is: 5100FEA6F6
TAG2 code is: 5100FE9BA2
Tag 2
TAG code is: 5100FEFB
TAG1 code is: 5100FEA6F6
TAG2 code is: 5100FE9BA2
Tag 2
and here's the code I modified from andrethegiant: RFID cat door and http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1266771881:
int val = 0;
char code[11];
int bytesread = 0;
char tag1[11] = {'5','1','0','0','F','E','A','6','F','6'}; // Tag 1
char tag2[11] = {'5','1','0','0','F','E','9','B','A','2'}; // Tag 2
void setup() {
Serial.begin(9600);
}
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
Serial.print("TAG code is: ");
Serial.println(code);
Serial.print("TAG1 code is: ");
Serial.println(tag1);
Serial.print("TAG2 code is: ");
Serial.println(tag2);
{
if(strcmp(code,tag1) == 0) //compare tag1 to the tag read
{
Serial.println("Tag 1");
}
if(strcmp(code,tag2) == 0);
{
Serial.println("Tag 2");
}
}
bytesread = 0;
delay(1000); // wait for a second
}
}}}