#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN  9    //Pin 9 to do reset on RC522
#define SS_PIN  10   //Pin 10 (SDA) of RC522
MFRC522 mfrc522(SS_PIN, RST_PIN); //Create the object of RC522

void setup() {
  Serial.begin(9600); //Initialize Serial communication
  SPI.begin();        //Initialize SPI bus
  mfrc522.PCD_Init(); // initialize created object MFRC522
  Serial.println("UID reading");
}

void loop() {
  //Check if exist new cards. Condition is acomplised if
  // it is true
  if ( mfrc522.PICC_IsNewCardPresent())
  {
    //Select card
    if ( mfrc522.PICC_ReadCardSerial())
    {
      // Send UID via Serial
      Serial.print("Card UID:");
      //This for loop is used to join UID terms and then print them.
      for (byte i = 0; i < mfrc522.uid.size; i++) {
        //(relational expresion) ? (expresion1) : (expresion2)
        //It is the same than a if condition
        Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
        Serial.print(mfrc522.uid.uidByte[i], HEX);
      }
      Serial.println();
      // Finish the reading
      mfrc522.PICC_HaltA();
    }
  }
}