PRFID code isn't recognizing tags correctly

Ok so I’m working on a project with the black Parallax RFID reader/writer in which I need my arduino to scan RFID tags and be able to tell the difference between the right tag and the wrong tag. I basically just tried to add some of my own code onto the sample code.

//Code to read data from Parallax RFID reader/writer 28440 via Arduino
//Program reads data from the old EM4100-based tags and prints their value in the serial monitor.

//Writen by vgrhcp, uberdude, sebflippers and sixeyes

#include <SoftwareSerial.h>
#define txPin 6
#define rxPin 8
#define RFID_LEGACY 0x0F

SoftwareSerial mySerial(rxPin, txPin);
int  val = 0; 
char key[10] = {'010005DE48'};
char code[11];     //Note this is 11 for the extra null char?
int bytesread = 0;

void setup()

  pinMode(13, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(txPin, OUTPUT);     //pin 6
  pinMode(rxPin, INPUT);      //pin 8

  Serial.println("RFID Read/Write Test");

void loop()

  //mySerial.print(32, BYTE);

  if(mySerial.available() > 0) {          // if data available from reader 

    if((val = == 10) {   // check for header 
      bytesread = 0; 
      while(bytesread<10) {              // read 10 digit code 
        if( mySerial.available() > 0) { 
          val =; 
          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: ");   // possibly a good TAG 
        Serial.println(code);            // print the TAG code
       if(code == key){
         Serial.println("TAG IS VALID!!!");
      bytesread = 0;

      delay(500);                       // wait for a 1/2 second 

When I run my code and wave the correct tag in front of the reader, the serial monitor prints out the tag’s code, but it doesn’t print out the line “TAG IS VALID!!!”. What am I doing wrong!!!

Wrong kind of quotes on your key. This:

char key[10] = {'010005DE48'};

Should be:

char key[] = "010005DE48";

You can't use == to compare strings. Look up strcmp.

Thank you very much! Everything works fine now! You're the best!