I modified some code so that the Arduino will light an LED in the event of the proper RFID tag being presented. It doesn't work, and I can't fix it. The problem seems to be at the line : if (bytesread == 10, code == tagOne)
Can anyone help?
char tagOne[12] = "0415ED3917"; // put the values for your tags here
int rstPin = 2;
int ledPin = 13;
int val = 0;
char code[10];
int bytesread = 0;
void setup() {
Serial.begin(2400);
pinMode(rstPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(2, LOW);
}
void loop() {
// read in and parse serial data:
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, code == tagOne) { // if 10 digit read is complete
digitalWrite(ledPin, HIGH);
Serial.print(code);
}
}
}
}