Hi, gues , I try to use this code and its working very well.
But this way the maximum number of tags that I can use is 83, but I need to use more like 150 or so...
btw. Im using Arduino Uno, lcd 16x2,relay, RFID reader, for door lock for my Building
How can I do it... when I put more RFID Card Code than 83 its stop reading them properly and code going crazy if add one more card ... w warning message i see when verify Sketch uses 9364 bytes (29%) of program storage space. Maximum is 32256 bytes.
Global variables use 1783 bytes (87%) of dynamic memory, leaving 265 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#define SS_PIN 5
#define RST_PIN 9
#define RELAY 3
//#define BUZZER 2
#define ACCESS_DELAY 100
#define DENIED_DELAY 1000
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal lcd(A5, A4, A3, A2, A1, A0);
const char* authorizedUIDs[] = {
"A1 65 1B 1C",
"81 EC 1A 1C",
"46 78 4B 40",
"B1 E8 1D 1C",
"46 4A 34 40",
"D6 37 4B 40",
"56 64 41 40",
"D0 99 73 40",
"62 05 57 C0",
"F0 89 A5 40",
"A0 79 86 40",
"B0 07 71 40",
"C1 3D 1B 1C",
"46 A9 41 40",
"66 74 35 40",
"01 23 1D 1C",
"D0 C2 4B E9",
"21 AF 21 1C",
"C1 CA 19 1C",
"01 74 22 1C",
"51 6E 1D 1C",
"41 1E 20 1C",
"31 04 1F 1C",
"96 12 3B 40",
"76 AB 41 40",
"96 99 3A 40",
"96 5A 35 40",
"C6 43 3C 40",
"36 83 4B 40",
"46 65 41 40",
"46 39 4C 40",
"16 AF C8 B4",
"06 7F 41 40",
"26 BF 3C 40",
"46 38 34 40",
"00 6D 8D 40",
"20 58 6E E9",
"E6 0C 4B 40",
"72 93 CB 9A",
"F6 65 3D 40",
"F6 3C 35 40",
"26 61 3B 40",
"36 9F 34 40",
"32 31 E7 91",
"D2 39 DC BF",
"F6 0B 39 40",
"51 28 1C 1C",
"F0 58 AB 40",
"11 A6 22 1C",
"40 50 84 40",
"E2 AE E0 BF",
"A6 37 35 40",
"56 AE 41 40",
"C6 1E 3A 40",
"E6 E6 39 40",
"06 66 36 40",
"96 0E 38 40",
"86 51 3B 40",
"C6 B6 40 40",
"66 EB 3C 40",
"70 D0 76 40",
"E1 C7 20 1C",
"C1 91 20 1C",
"90 E7 52 E9",
"F6 E0 3A 40",
"B0 7E 66 E9",
"50 D6 70 40",
"20 3D 6C E9",
"96 3D 48 40",
"94 6F 78 6B",
"F6 12 38 40",
"C0 68 91 40",
"11 5B 19 1C",
"E1 C0 1C 1C",
"10 79 6A E9",
"90 B8 68 40",
"50 86 86 40",
"62 0C 95 91",
"46 76 4C 40",
"B0 40 B0 40",
"D0 2C 53 E9",
"41 52 20 1C",
"F0 61 78 40",
"90 E6 AE 40",
"F2 7E C5 91",
"66 0C 37 40",
"66 20 37 40",
"26 3D 4B 40",
"E1 44 DC 06",
"A0 5E 4F E9",
"96 2E 3D 40",
"53 1F A1 98",
"E0 1D 8B 40",
"46 9D 41 40",
"D0 E0 53 E9",
"70 9E 83 40",
"D1 3D 1C 1C",
"11 AB 20 1C",
"F3 A6 A8 BB",
};
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(RELAY, OUTPUT);
// pinMode(BUZZER, OUTPUT);
// noTone(BUZZER);
digitalWrite(RELAY, HIGH);
lcd.begin(16, 2);
lcd.print("TPCB Factory ");
lcd.setCursor(0, 1);
lcd.print("Put Your Card");
}
void loop()
{
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent())
{
return;
}
if (!mfrc522.PICC_ReadCardSerial())
{
return;
}
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();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("UID tag:");
lcd.setCursor(0, 1);
lcd.print(content);
// Check if the UID is authorized
bool isAuthorized = false;
for (const char *authorizedUID : authorizedUIDs)
{
if (content.substring(1) == authorizedUID)
{
isAuthorized = true;
break;
}
}
if (isAuthorized)
{
Serial.println("Authorized access");
lcd.clear();
lcd.print("Authorized");
delay(500);
digitalWrite(RELAY, LOW);
lcd.clear();
lcd.print("Access granted");
delay(ACCESS_DELAY);
digitalWrite(RELAY, HIGH);
lcd.clear();
lcd.print("Welcome To ");
lcd.setCursor(0, 1);
lcd.print(" ....");
}
else
{
Serial.println("Access denied");
lcd.clear();
lcd.print("Access denied");
// tone(BUZZER, 300);
delay(DENIED_DELAY);
// noTone(BUZZER);
lcd.clear();
lcd.print("Access denied");
lcd.setCursor(0, 1);
lcd.print("");
}
}