Hello everyone,
I am new to this forum and i need some guidance on how to add more than one RFID UID tag so that whenever i tap valid UID tag it will print “Access granted” without manually add each card UID tag for same condition.
Below are my full coding:
// Include required libraries
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <Ultrasonic.h>
// Create instances
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
Ultrasonic ultrasonic(6,7);//Define pins ultrasonic(trig,echo)
String tagUID = "89 ED 52 D3";
int distance;
int count = 5;
void setup()
{
lcd.init(); // LCD screen
lcd.backlight();
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Welcome ");
lcd.setCursor(0, 1);
lcd.print(" Show Your Tag ");
}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Reading from the card
String tag = "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
tag.concat(String(mfrc522.uid.uidByte[i], HEX));
}
tag.toUpperCase();
//Checking the card
if (tag.substring(1) == tagUID)
{
// If UID of tag is matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access Granted");
lcd.setCursor(0, 1);
lcd.print(" Hello ");
delay(3000);
lcd.clear();
}
else
{
// If UID of tag is not matched.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Invalid Tag ");
lcd.setCursor(0, 1);
lcd.print("Access Denied");
delay(3000);
}
}
I need to add one more UID tag code here so that both card is valid for same condition.
Anyone help me on this
String tagUID = "89 ED 52 D3";
Thank you.