# RFID. True only worked once, but False worked many times

**URL:** <https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200>\
**Category:** Programming\
**Created:** [July 30, 2023, 12:40pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200 "2023-07-30T12:40:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimteodoro](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kimteodoro/32/989510_2.png) [@kimteodoro](https://forum.arduino.cc/u/kimteodoro)\
**Post date:** [July 30, 2023, 12:40pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/1 "2023-07-30T12:40:36Z")

</div>

Hi, everyone. Tried my hands on RFID technology. This is my reference: [Arduino RFID Door Lock System with LCD Display - YouTube](https://youtu.be/EJKUcGIfNDU)

My problem is this:

For the first few tries, it worked 3 times only on "Access granted" condition. Every time on every reset. On "Access denied", no problem. I can scan invalid cards/tags continuously and the loop still worked. Only after the true condition is met, and for just 3 times, then it wouldn't work.

However, when I tried it again later in the day, Access Granted only worked once and still no problem on access denied. What do you think is the problem?

This is their code:

```arduino
//Viral Science www.viralsciencecreativity.com www.youtube.com/c/viralscience
//RFID Door Lock System

#include <Wire.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h> 
LiquidCrystal_I2C lcd(0x27, 16, 2);
 
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 4 //define green LED pin
#define LED_R 5 //define red LED
#define BUZZER 2 //buzzer pin
#define lock 3
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int Btn = 6;
 
void setup() 
{
  Serial.begin(9600); // Initiate a serial communication
  SPI.begin(); // Initiate SPI bus
  mfrc522.PCD_Init(); // Initiate MFRC522
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  noTone(BUZZER);
  pinMode(Btn,INPUT);
  pinMode(lock,OUTPUT);
  Serial.println("Place your card on reader...");
  Serial.println();
  lcd.begin();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0,0); // column, row
  lcd.print(" Scan Your RFID "); 
  lcd.setCursor(0,1); // column, row
  lcd.print(" Door Locked ");

 }
void loop() 
{

if(digitalRead(Btn) == HIGH){
  
    Serial.println("Access Granted");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    lcd.setCursor(0,1); // column, row
    lcd.print(" Door Un-Locked ");
    tone(BUZZER, 2000);
    delay(100);
    noTone(BUZZER);
    delay(50);
    tone(BUZZER, 2000);
    delay(100);
    noTone(BUZZER);
    digitalWrite(lock,HIGH);
    delay(3000);
    digitalWrite(lock,LOW);
    delay(100);
    digitalWrite(LED_G, LOW);
    lcd.setCursor(0,1); // column, row
    lcd.print(" Door Locked ");
    tone(BUZZER, 2000);
    delay(100);
    noTone(BUZZER);
  delay(50);
  }

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();

  
 if ((content.substring(1) == "33 E8 C2 14") || (content.substring(1) == "5C 94 21 4A")) //change here the UID of card/cards or tag/tags that you want to give access
  {
    Serial.println("Access Granted");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    lcd.setCursor(0,1); // column, row
    lcd.print(" Door Un-Locked ");
    tone(BUZZER, 2000);
    delay(100);
    noTone(BUZZER);
    delay(50);
    tone(BUZZER, 2000);
    delay(100);
    noTone(BUZZER);
    digitalWrite(lock,HIGH);
    delay(3000);
    digitalWrite(lock,LOW);
    delay(100);
    digitalWrite(LED_G, LOW);
    lcd.setCursor(0,1); // column, row
    lcd.print(" Door Locked ");
    tone(BUZZER, 2000);
    delay(100);
    noTone(BUZZER);
    delay(50);
  }

else
{
    lcd.setCursor(0,1); // column, row
    lcd.print("Invalid RFID Tag");
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 1500);
    delay(500);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
    delay(100);
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 1500);
    delay(500);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
    delay(100);
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 1500);
    delay(500);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
    lcd.setCursor(0,1); // column, row
    lcd.print(" Door Locked ");
 }
 }

```

They originally used it on Nano, but I used Uno. When I press the reset button on Arduino Uno, it can work again. But once I scan a valid card/tag, it won't work on the second time now. Even if I scan an invalid card/tag afterwards.

Is it a power problem? Memory problem? Or something with my RFID reader? The cards/tags?

TIA

---

<div class="post-metadata">

**Author:** ![kimteodoro](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kimteodoro/32/989510_2.png) [@kimteodoro](https://forum.arduino.cc/u/kimteodoro)\
**Post date:** [July 30, 2023, 12:44pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/2 "2023-07-30T12:44:21Z")

</div>

UPDATE: Now it worked, but only after 30 mins of rest? (The time I spent writing my post). And then it goes back to not working again.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [July 30, 2023, 12:48pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/3 "2023-07-30T12:48:09Z")

</div>

> [@kimteodoro](#):
>
> ```arduino
> pinMode(Btn,INPUT);
> 
> ```

how is your button wired ?

can you share a picture of the full circuit and how things are powered?

did you try a basic example with your setup such as that one?

> <https://github.com/miguelbalboa/rfid/blob/master/examples/ReadNUID/ReadNUID.ino>

---

<div class="post-metadata">

**Author:** ![kimteodoro](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kimteodoro/32/989510_2.png) [@kimteodoro](https://forum.arduino.cc/u/kimteodoro)\
**Post date:** [July 30, 2023, 1:33pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/4 "2023-07-30T13:33:11Z")

</div>

I was able to do this and it worked. Tried again recently and it still works.

(Will post the wiring afterwards)

---

<div class="post-metadata">

**Author:** ![kimteodoro](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kimteodoro/32/989510_2.png) [@kimteodoro](https://forum.arduino.cc/u/kimteodoro)\
**Post date:** [July 30, 2023, 1:36pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/5 "2023-07-30T13:36:52Z")

</div>

![IMG_20230730_212301](https://europe1.discourse-cdn.com/arduino/original/4X/2/0/f/20f676b96802af5e5698e11700f7d410ab6b92a8.jpeg)  
 ![IMG_20230730_212338](https://europe1.discourse-cdn.com/arduino/original/4X/9/6/8/968d014b0cb80f35f766ffb969d06628643fbb21.jpeg)  
 ![IMG_20230730_212444](https://europe1.discourse-cdn.com/arduino/original/4X/b/8/8/b888b892bc2ac15b035aad35a9840126e6496abc.jpeg)

---

<div class="post-metadata">

**Author:** ![kimteodoro](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kimteodoro/32/989510_2.png) [@kimteodoro](https://forum.arduino.cc/u/kimteodoro)\
**Post date:** [July 30, 2023, 1:38pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/6 "2023-07-30T13:38:26Z")

</div>

![IMG_20230730_212542](https://europe1.discourse-cdn.com/arduino/original/4X/f/5/9/f59e6791366f65fa850ed3caa6c4dfa58ef78cb5.jpeg)  
 ![IMG_20230730_212831](https://europe1.discourse-cdn.com/arduino/original/4X/0/f/7/0f7e41e05d9f6f8c82cdf2ca7ab4df1bd8ca9fe2.jpeg)  
 ![IMG20230730213012](https://europe1.discourse-cdn.com/arduino/original/4X/9/b/0/9b0f4e1ca2efc9fae70a6aab11cf207a0b1859eb.jpeg)

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [July 30, 2023, 1:39pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/7 "2023-07-30T13:39:07Z")

</div>

the wiring is just so messy and I see you have an electromagnet too

I'd clean things up and make sure you have proper protection against electromagnetic perturbations and that the power is stable

---

<div class="post-metadata">

**Author:** ![kimteodoro](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kimteodoro/32/989510_2.png) [@kimteodoro](https://forum.arduino.cc/u/kimteodoro)\
**Post date:** [July 30, 2023, 1:40pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/8 "2023-07-30T13:40:22Z")

</div>

![Screenshot 2023-07-28 073625](https://europe1.discourse-cdn.com/arduino/original/4X/7/4/d/74d64d676fa0aaf815d8a90224faf4df0f164335.jpeg)

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [July 30, 2023, 1:45pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/9 "2023-07-30T13:45:15Z")

</div>

don't try to debug everything in one go.

Divide and conquer :

➜ just keep the Nano, the RFID reader and the Serial monitor. unplug everything else and see if that works fine (add serial prints to see what would be done)

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [July 30, 2023, 1:53pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/10 "2023-07-30T13:53:44Z")

</div>

> [@kimteodoro](#):
>
> What do you think is the problem?

If you are using the code from the video, and the circuit from the video, and your RFID reader has shown that it is functional…

…and sometimes it works and sometimes it does not, then I suspect you have some marginal connections amongst all your beautiful wiring that makes it sometimes work and sometimes not work.

Changes in observations come from changes in the observed. The code is not changing. The sensor works, so what can be changing?

Go over the wiring to be sure it is 100 percent correct and mechanically firm and stable.

a7

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [July 30, 2023, 2:04pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/11 "2023-07-30T14:04:54Z")

</div>

> [@J-M-L](#):
>
> Divide and conquer :

@kimteodoro plesae do divide and conquer.

In particular, temporarily removing from the circuit both the relay and the solenoid will eliminate the possibility of electrical interferences causing unwanted circuit and program behaviour.

Let the print statements, and any you might add, speak to what the relay, and hence the solenoid, woukd be doing if they were still in there.

Maybe: then your sketch works perfectly, albeit without the desired end goal of opening and closing the lock, and you'd have evidence of a problem with the way the relay and solenoid are exactly wired and supplied with power.

a7

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 26, 2024, 2:05pm UTC](https://forum.arduino.cc/t/rfid-true-only-worked-once-but-false-worked-many-times/1153200/12 "2024-01-26T14:05:46Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
