A ₹964 card-operated latch for a cupboard, a box or a model door. An RC522 reader reads the card’s ID, the sketch compares it against a short list, and a servo moves the latch for five seconds. It is a good project for learning SPI and state handling, but the page is clear that a card ID check is a weak form of security.
Scope: intermediate. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The UID and lock-out figures below were computed by script. Do not use this to secure anything valuable. The card ID on common MIFARE Classic cards is sent in the clear and can be copied with cheap tools, so it is a convenience, not a lock. The reader runs on 3.3 V; connecting it to 5 V can damage it.
How it works
The RC522 reads 13.56 MHz cards and tags. The common cards give a 4-byte UID, which can take 2^32 = 4,294,967,296 values. That sounds big, but the UID is not a secret and many cheap cards let it be rewritten, so anyone who sees it can copy it. A UID check only keeps honest people out and lets you give family members their own cards.
The sketch compares the UID with a stored list. A match opens the latch for five seconds, then closes it. Three wrong cards in a row start a ten second lock-out where every card is ignored, which slows down guessing a UID by trying many cards.
Bill of materials
| Part | Qty | Unit | Total |
|---|---|---|---|
| Arduino Uno R3 (or compatible) | 1 | ₹550 | ₹550 |
| RC522 RFID reader module | 1 | ₹120 | ₹120 |
| RFID card or tag | 2 | ₹20 | ₹40 |
| SG90 micro servo | 1 | ₹120 | ₹120 |
| Green and red LEDs | 1 | ₹5 | ₹5 |
| 220 ohm resistors | 2 | ₹2 | ₹4 |
| Active buzzer module | 1 | ₹15 | ₹15 |
| Breadboard | 1 | ₹60 | ₹60 |
| Jumper wires | 1 | ₹50 | ₹50 |
| Parts total | ₹964 | ||
Scroll the table sideways to see every column.
Prices checked Nov 2026. Shipping and tools are not included.
Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.
The numbers
| Item | Value |
|---|---|
| UID length | 4 bytes |
| UID values possible | 4,294,967,296 |
| Open time | 5 seconds |
| Wrong cards before lock-out | 3 |
| Lock-out time | 10 seconds |
| Fastest guessing rate | about 14 tries a minute |
The lock-out arithmetic: each cycle allows 3 tries, then 10 seconds are ignored. Tapping as fast as possible, say one card per second, gives 3 tries in 3 seconds plus 10 seconds of lock-out, so about 3 tries per 13 seconds, or about 14 a minute. Against 4.3 billion possible UIDs this is no protection against someone who can copy a UID.
Power and wiring
| Part | Connects to | Note |
|---|---|---|
| RC522 3.3V and GND | 3V3 and GND | Not 5 V |
| RC522 SDA (SS) | D10 | |
| RC522 SCK / MOSI / MISO | D13 / D11 / D12 | Hardware SPI |
| RC522 RST | D9 | |
| Servo signal | D6 | Servo power from the 5V pin |
| Green and red LEDs | D2 and D3 | Through 220 ohm |
| Buzzer | D8 |
The sketch
// RFID door lock: Uno + RC522 + servo
// Design worksheet: a UID check is weak security. Do not protect valuables with it.
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
const int SS_PIN = 10, RST_PIN = 9, SERVO_PIN = 6;
const int LED_OK = 2, LED_BAD = 3, BUZ = 8;
const int LOCKED = 0, UNLOCKED = 90; // degrees
const unsigned long OPEN_MS = 5000UL, LOCKOUT_MS = 10000UL;
MFRC522 reader(SS_PIN, RST_PIN);
Servo latch;
// Replace with your own cards: print the UID to Serial to learn it.
const byte ALLOWED[][4] = { {0xDE, 0xAD, 0xBE, 0xEF}, {0x12, 0x34, 0x56, 0x78} };
const int N_ALLOWED = sizeof(ALLOWED) / sizeof(ALLOWED[0]);
int failures = 0;
unsigned long lockoutUntil = 0;
bool isAllowed() {
if (reader.uid.size != 4) return false;
for (int i = 0; i < N_ALLOWED; i++) {
bool same = true;
for (int b = 0; b < 4; b++) if (reader.uid.uidByte[b] != ALLOWED[i][b]) same = false;
if (same) return true;
}
return false;
}
void beep(int ms) { digitalWrite(BUZ, HIGH); delay(ms); digitalWrite(BUZ, LOW); }
void setup() {
Serial.begin(9600);
SPI.begin(); reader.PCD_Init();
latch.attach(SERVO_PIN); latch.write(LOCKED);
pinMode(LED_OK, OUTPUT); pinMode(LED_BAD, OUTPUT); pinMode(BUZ, OUTPUT);
}
void loop() {
if (!reader.PICC_IsNewCardPresent() || !reader.PICC_ReadCardSerial()) return;
Serial.print("UID:");
for (byte i = 0; i < reader.uid.size; i++) { Serial.print(' '); Serial.print(reader.uid.uidByte[i], HEX); }
Serial.println();
if (millis() < lockoutUntil) {
beep(300);
} else if (isAllowed()) {
failures = 0;
digitalWrite(LED_OK, HIGH); latch.write(UNLOCKED); beep(100);
delay(OPEN_MS);
latch.write(LOCKED); digitalWrite(LED_OK, LOW);
} else {
digitalWrite(LED_BAD, HIGH); beep(400); digitalWrite(LED_BAD, LOW);
if (++failures >= 3) { lockoutUntil = millis() + LOCKOUT_MS; failures = 0; }
}
reader.PICC_HaltA();
reader.PCD_StopCrypto1();
}Print each card’s UID to the serial monitor, then paste the bytes into the ALLOWED list. The sketch is blocking while the latch is open, which is fine for this one job. Keep the physical latch design in mind: a servo can be forced by hand, so a servo latch is for convenience only. The sketch has been proofread but not compiled on this site.
Test plan
- Reader check: tap each card and confirm the UID prints and is stable.
- Allowed card: confirm the latch moves and closes after five seconds.
- Wrong card: tap a card that is not on the list and check the red LED and beep.
- Lock-out: tap three wrong cards and confirm that even an allowed card is ignored for ten seconds.
- Range: note how close a card must be and whether a thick wallet blocks it.
- Power: check the servo moving does not reset the reader.
What usually goes wrong
| Symptom | Likely cause | Fix |
|---|---|---|
| Reader does not respond | Powered from 5 V or wrong SPI pins | Use 3.3 V and check D10, D11, D12, D13 |
| Card read once then ignored | Card not halted | Keep PICC_HaltA and StopCrypto1 |
| Servo jitters | Supply noise | Separate 5 V supply |
| Allowed card refused | UID typed wrongly | Print the UID and paste it exactly |
| Works at bench but not in the box | Metal near the antenna | Keep metal away from the reader |
Upgrades
- Logging: record each tap with a timestamp on an SD card.
- Master card: add a way to enrol new cards by tapping a master card.
- Stronger lock: use a solenoid bolt and a stronger authentication scheme.
- Door sensor: add a reed switch to detect whether the door is closed.
Cost and parts notes
The ₹964 total is an illustration and does not include shipping. Use the cost calculator to compare sellers.
Common questions
Is an RFID UID check secure?
No. UIDs of common cards are sent in the clear and cheap tools can copy them. It is fine for convenience, not security.
Why 3.3 V for the RC522?
The module is a 3.3 V part. Many boards tolerate 5 V logic on the data pins but not on the supply; check yours.
How do I add a new card?
Print its UID on the serial monitor and add it to the ALLOWED list, then upload again.
Can it unlock a real door?
Not with this design. It is a model or cupboard lock.
Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.