title: Arduino RC-522 RFID reader - comparing values in a byte array
body: <p>I'm using the following code to successfully read IDs from MIFARE cards to the serial monitor.</p>
  
  <pre><code> #include &lt;SPI.h&gt;      
  #include &lt;MFRC522.h&gt;
  #include &lt;Wire.h&gt;
  #include &lt;LiquidCrystal_I2C.h&gt;
  
  int readflag;
  byte readCard[4];           
  
  #define SS_PIN 10
  #define RST_PIN 9
  MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.
  
  ///////////////////////////////////////// Setup ///////////////////////////////////
  void setup() {
  
    Serial.begin(9600); 
    SPI.begin();         
    mfrc522.PCD_Init();   
    mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); 
  
  lcd.begin(20, 4);
  
      }
  
  ///////////////////////////////////////////////////////////////////////////////
    // Main loop
  ///////////////////////////////////////////////////////////////////////////////
  void loop () {
  
   do {                                                               
     readflag = checkread(); 
    }
      while (!readflag); 
  
  //If card detected do this
  
         recordid();
    }
  
  ///////////////////////////////////////////////////////////////////////////////
    // Stores the ID of the card that's been detected in readCard byte array
  ///////////////////////////////////////////////////////////////////////////////
  void recordid() {
      mfrc522.PICC_IsNewCardPresent();
      mfrc522.PICC_ReadCardSerial();
     lcd.clear();
      for (int i = 0; i &lt; 4; i++) { 
          readCard[i] = mfrc522.uid.uidByte[i];  
               Serial.print( mfrc522.uid.uidByte[i], HEX);  
  
          }
      Serial.println("");
      mfrc522.PICC_HaltA();
    }
  
  
  /////////////////////////////////////////////
    // Returns 1 if a card has been detected
  /////////////////////////////////////////////
  int checkread() {
     if ( ! mfrc522.PICC_IsNewCardPresent()) { 
      return 0; }                                        //no card detected
  
      mfrc522.PICC_HaltA(); 
      return 1; }                                       //card detected
  </code></pre>
  
  <p>I have 12 cards and the serial monitor is telling me that their ID's are (hex):</p>
  
  <p>3278CE3F
  F5C9FD29
  2FC640
  82BA7A3F
  2BD7A3F
  52B77A3F
  B2E5640
  F2DD640
  E2ECCC3F
  22B3640
  2FD640
  73D5B7AC</p>
  
  <p>I understand these are being stored in the readCard byte array.</p>
  
  <p>I would like to compare the current value of this byte array to a known value to determine whether an instruction is run (e.g. a blink of an LED)</p>
  
  <p>Something like this:</p>
  
  <p>If (readCard = 2FD640) {
      turn on LED
  }</p>
  
  <p>I have been able to do this successfully using this if statement:</p>
  
  <p>if ( <em>(uint32_t</em>)readCard == 0x3FCE7832)</p>
  
  <p>for example card one. However, it will not work with the cards with IDs that are not 8 digits long i.e. card 11 (2FD640).</p>
  
  <p>Can anyone help me implement this in code?</p>
  
  <p>Many thanks.</p>