I have a problem with my mfrc522

Everytime i upload my sketch, my mfrc522 didn't read my card.I upload the DumpInfo sketch from mfrc522 example and i uploaded my code to my arduino UNO.It works well for a second and then it didnt work again after that.

My code:

/* RST/Reset   RST          9            
 * SPI SS      SDA(SS)      10   
 * SPI MOSI    MOSI         11
 * SPI MISO    MISO         12 
 * SPI SCK     SCK          13
*/

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

MFRC522 reader(10, 9);

int counter;
int relay  = 3;

void setup() {

 pinMode(relay ,OUTPUT);
 pinMode(7, OUTPUT);
 reader.PCD_Init();
 delay(4);
 reader.PCD_DumpVersionToSerial();
 while(!Serial);
 SPI.begin();
 Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

 Serial.println(counter);
 delay(500);


 String card = "";

 if(counter == 1){
  digitalWrite(3 ,HIGH);
  Serial.println("true");
  delay(100);
 }

if(counter == 0){
  digitalWrite(3 , LOW);
  Serial.println("false");
  delay(100);
 }
 
 if ( ! reader.PICC_IsNewCardPresent()) {
   counter = 0;
   return;
  }


  // Select one of the cards
  if ( ! reader.PICC_ReadCardSerial()) {
    return;
  }

  reader.PICC_DumpToSerial(&(reader.uid));

 for(byte i = 0; i < reader.uid.size; i++){
  Serial.print(reader.uid.uidByte[i] < 0x10 ? " 0" : " ");
  Serial.print(reader.uid.uidByte[i], HEX);
  card.concat(String(reader.uid.uidByte[i] < 0x10 ? " 0" : " "));
  card.concat(String(reader.uid.uidByte[i], HEX));
 }
 
 Serial.println();
 card.toUpperCase();

 if(card.substring(1) == "05 22 A3 AC"){
  counter = 1;
  digitalWrite(7,HIGH);
  delay(100);
  digitalWrite(7, LOW);
 }
 
 else{
  digitalWrite(7, HIGH);
  delay(1000);
  digitalWrite(7, LOW);
  delay(1000);
 }

 
 
}

I know its not the best but please lend me a help on this project

Try moving Serial.begin above the while statement.

The original version of "DumpInfo" has no relay.

" rfid/examples/DumpInfo/DumpInfo.ino at master · miguelbalboa/rfid · GitHub

What relay is this?

How is it connected to your arduino?

To facilitate our help post a schematic of your project.

It works really well.Thank you very much for your help!

Thanks for telling. Please mark it as "solution".