Regarding RFID

Submitted by Karthick S on

I have RFID card reader. It is working fine but I had added one additional functionality that when it finds invalid user it should turn on red led. It is not working if it is finding invalid card when I added additional Led. I dont know why. Can you please explain. If i remove the led code it is working otherwise it is not recongnising even if i show valid id card. 

This is the code. If I remove led it is working otherwise it does not.

const int buzzer = 46; //buzzer to arduino pin 9
#include <SPI.h>
#include <MFRC522.h>
#define F_PIN 48  // failure pin
#define P_PIN 47  // successful pin
#define RST_PIN         49          // Configurable, see typical pin layout above
#define SS_PIN          53         // Configurable, see typical pin layout above
byte data[4];
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
  pinMode(F_PIN,OUTPUT);
  pinMode(P_PIN,OUTPUT);
  pinMode(buzzer,OUTPUT);
  digitalWrite(F_PIN,LOW);
  digitalWrite(P_PIN,LOW);
  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
  Serial.println("Please scan your card");
}

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    delay(100);
    return;
  }
  else
  {
    Serial.println("Card is found");
    Serial.println("Authentication is in progress");
  }
   
  if ( ! mfrc522.PICC_ReadCardSerial())
    return;
     Serial.print("Please wait.");
     delay(500);
     Serial.print(".");
     delay(500);
     Serial.print(".");
     delay(500);
     Serial.print(".");
    delay(500);
    Serial.println(" ");
      Serial.print("Card No is : ");
  for(int i=0;i<4;i++){
    if(mfrc522.uid.uidByte[i]<16) 
     Serial.print("0");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
  }  Serial.println(" ");
     if((mfrc522.uid.uidByte[0])==0x41 && (mfrc522.uid.uidByte[1])==0xAD && (mfrc522.uid.uidByte[2])==0x34 && (mfrc522.uid.uidByte[3])==0x5B){
            Serial.println("Authentication is successful... Access Granted !!!");
            digitalWrite(P_PIN,HIGH);
            tone(buzzer,1000);
        }
          else if((mfrc522.uid.uidByte[0])==0x14 && (mfrc522.uid.uidByte[1])==0x46 && (mfrc522.uid.uidByte[2])==0x73 && (mfrc522.uid.uidByte[3])==0xE1){
              Serial.println("Authentication is successful... Access Granted !!!");
                
           }
               else {
                   Serial.println("Authentication is failed... Access Denied !!!");
                   digitalWrite(F_PIN,HIGH);
                   delay(1000);
                   digitalWrite(F_PIN,LOW);
               }
}