RFID issue

Hello, I have been working on this door lock opener for the past year and everything works. The only
issue I am having is that it allows access to multiple cards even though I put in to allow access to only
two cards. Why is it allowing access to all cards?

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <IRremote.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(OLED_RESET);


 
#define SS_PIN 53 // Uno pin 10 Nano pin D10 of RFID
#define RST_PIN 5 // Uno pin 9 Nano pin D9 of RFID
#define SERVO_PIN 9    //servo pin 3
#define ACCESS_DELAY 2000
#define DENIED_DELAY 1000
#define LED_G 7     //led green pin 7
#define LED_R 6     //led red pin 6
#define BUZZER 4    //buzzer pin 4
#define pushButtonPin 8  //push button pin 2
int buttonPushed = 0;
decode_results results;
Servo myservo;
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int IRpin = 11;      //IR receiver pin 11
IRrecv irrecv(IRpin);
 
void setup()
{
  Serial.begin(9600); // Initiate a serial communication
  irrecv.enableIRIn();

 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();

 
  SPI.begin(); // Initiate SPI bus
  mfrc522.PCD_Init(); // Initiate MFRC522
  myservo.attach(SERVO_PIN);
 
  
 
 pinMode (SDA, OUTPUT);
 
  pinMode (LED_G, OUTPUT);
  pinMode (LED_R, OUTPUT);
  pinMode (BUZZER, OUTPUT);
  pinMode(pushButtonPin, INPUT_PULLUP);
}
void loop()
{
   display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  
  display.display();
  display.clearDisplay();
  //start of IR SKETCH
 
  if (irrecv.decode(&results))
  {
    irrecv.resume();
  }
  if (results.value == 3249146358)
  {
    delay(500);
    digitalWrite (LED_G, HIGH);  //led turns on
    digitalWrite(BUZZER, HIGH);  //buzzer turns on
    delay(500);                 // for half a second
    digitalWrite(BUZZER, LOW);   //buzzer turns off
    myservo.write( 0 );          //servo goes to 0 degrees
    
//plug here
display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Door open come in!");
  display.display();
 display.clearDisplay();
    
    delay(7500);                   //for 7 and a half seconds
    myservo.write( 100 );          //servo goes to 100 degrees
    digitalWrite (LED_G, LOW);   //led green turns off
  
 
  }
 
 
  /* start of pushbutton sketch
    Everytime you press pushbutton it will turn on green led and buzzer, then servo
    will go from 0 to 100 degrees for 7 and a half seconds.  Then the push button
    will go from 1 to 0 state (on/off).*/
  if (digitalRead(pushButtonPin) == LOW) {
    buttonPushed = 1;
     }
     
  if ( buttonPushed ) {
     
    digitalWrite (LED_G, HIGH);
    digitalWrite(BUZZER, HIGH);
    delay(500); 
   digitalWrite(BUZZER, LOW);
    myservo.write(0);


    //plug here
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Door open come in!");
  display.display();
 display.clearDisplay();
    delay(7500);
    myservo.write(100);
    digitalWrite (LED_G, LOW);
    buttonPushed = 0;
 
  
    
  }
  //start of RFID SKETCH
  // Look for new cards
 
  if
  ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
 
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  Serial.println("Put your card to the reader...");
  Serial.println();
 
  //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) == "5A 77 E2 81", "F9 31 75 9C") //change here the UID of the card
    {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    digitalWrite(BUZZER, HIGH);
    delay(300);
    digitalWrite(BUZZER, LOW);
    myservo.write( 0 );
//plug here
   display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Door open come in!");
  display.display();
 display.clearDisplay();
 
    delay(7500);
    myservo.write( 100 );
    digitalWrite(LED_G, LOW);
  }
else {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    digitalWrite (BUZZER, HIGH);
    delay(DENIED_DELAY);
    digitalWrite(LED_R, LOW);
    digitalWrite(BUZZER, LOW);
  }
  
  }

This part of the code should only allow access to two cards.

if (content.substring(1) == "5A 77 E2 81", "F9 31 75 9C")

When I delete one of the UID tags, it will allows access to only that specific card. When I have both tags it allows access to all cards, even cards not added to the code. Ideas?

if (content.substring(1) == "5A 77 E2 81", "F9 31 75 9C")

I think that you will need to make the comparisons separate.

if (content.substring(1) == "5A 77 E2 81" || content.substring(1) == "F9 31 75 9C")

Read up on what the comma operator does.

See RFID door lock with multiple keys

That worked groundFungus! Thanks alot!!! I will check out the link loT_hobbyist. Thanks fellas!!

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