Reading RFID/NFC and triggering an LED

Hello there!

I am really at a point where I don’t know how to continue. I am trying to read an RFID/NFC tag with a RC522 breakout board in conjunction with miguelbalboa’s library. I want a LED to light up while a tag/card is present.

Looking at basic examples around the web, it all starts with checking if there is a tag present and if a ID can be read. To do that there are two functions: PICC_IsNewCardPresent() and PICC_ReadCardSerial() with boolean returns.

Till now I am able to detect a tag/card without no problems but the LED is actually blinking instead of being on the whole time. It seems like the output pin is driven low everytime the main loop starts over. It seems like the part below the if-statement (which is supposed to be executed whenever no card is present) gets executed between successful readings. I wonder if someone could tell me what to do in order to have that LED turned on the whole time whenever a card is present.

The simplest version of my code (which also has that problem) looks like this so far:

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

boolean ledOn = false;

void setup()
{
  SPI.begin();
  mfrc522.PCD_Init();
  pinMode(5, OUTPUT);
}

void loop()
{
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
  {
    if (ledOn == true)
    {
      return;
    }
    else
    {
      digitalWrite(5, HIGH);
      ledOn = true;
      return;
    }
  }
  if (ledOn == false)
  {
    return;
  }
  else
  {
    digitalWrite(5, LOW);
    ledOn = false;
    return;
  }
}

Thanks,
V