RFID

Hello all,

I copied some code from the arduino playground that worked just fine to take the code from my rfid tag. But when i try to use the data to compare it to already stored data it does nothing.

Here is the code

// RFID reader for Arduino 
// Wiring version by BARRAGAN 
// Modified for Arudino by djmatic


int  val = 0; 
char code[10]; 
int bytesread = 0;
String comp;

void setup() { 

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
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() { 

  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.println(code);
      

[center]THIS IS WHERE IT DOES NOT WORK[/center]
      if (code == "3600290C6D") {
      Serial.println("Welcome, Alan");
          }
          
      if (code == "0F03028718") {
      Serial.println("Welcome, Oli");
         }
      
      bytesread = 0; 
           delay(500);                       // wait for a second 
    } 
  } 
} 
}


// extra stuff
// digitalWrite(2, HIGH);             // deactivate RFID reader

everything compiles but even with the right card it does not print “Hello, Alan”

any ideas would be greatly appreciated, Thank you!

code is an array of characters. The array does not have an equality operator, so

      if (code == "3600290C6D") {

will never work. If code were a NULL-terminated array (it is not), you could use

      if (strcmp(code,"3600290C6D")) {

But, you will have to do it the hard way:

char good[] = "3600290C6D";
boolean match = true;
for(int i=0; i<10; i++)
{
   if(code[i] != good[i])
   {
      match = false;
      break;
   }
}

if(match)
   // They are the same