The Smart Secure Entry System: a model door that checks your card AND your code
A miniature door lock that takes real security seriously. Tap an RFID card, and if it's recognized, the screen asks for a PIN on a keypad. Get both right, and a servo motor swings the lock open — get either one wrong, and the buzzer and screen let you know, with a lockout after too many failed tries.
What you're building
A model access-control system that teaches two-factor authentication and locking mechanisms.
The Smart Secure Entry System mounts onto a small door model or box lid. Tap a programmed RFID card against the reader, and the screen checks it instantly against an approved list. If it's recognized, the screen asks for a 4-digit PIN, which you type on the keypad. Only when both the card and the code are correct does the servo-driven lock swing open — and it automatically locks itself again a few seconds later. Enter the wrong PIN too many times, and the system locks out new attempts for a short cooldown, just like a real security system.
RFID Authentication
The reader checks every tapped card's ID against the list of approved cards.
Keypad PIN Entry
A second layer of security asks for a 4-digit code before anything unlocks.
Auto Lock / Unlock
The servo swings the lock open on success and locks itself again automatically.
Materials list
Most electronics can be reused from a beginner Arduino sensor kit.
Electronics
- 1x Arduino Uno
- 1x RFID-RC522 module + at least one RFID tag or card
- 1x 4x4 membrane matrix keypad
- 1x 16x2 LCD display with I2C backpack
- 1x micro servo motor (the lock)
- 1x small buzzer
- Jumper wires + breadboard
- USB cable or 5V power supply
Build supplies
- A small box or cardboard door model
- A thin wooden or plastic latch/bolt for the servo to move
- Hot glue gun
- Craft knife (adult use only)
- Small screwdriver
- Paint or sticker labels for a "finished product" look
Wiring reference table
| Component | Component Pin | Arduino Pin |
|---|---|---|
| RFID-RC522 | RST | D9 |
| RFID-RC522 | SDA (SS) | D10 |
| RFID-RC522 | MOSI | D11 |
| RFID-RC522 | MISO | D12 |
| RFID-RC522 | SCK | D13 |
| RFID-RC522 | VCC | 3.3V (not 5V) |
| Keypad | Row pins | D2, D3, D4, D5 |
| Keypad | Column pins | D6, D7, D8, A0 |
| Lock Servo | Signal | A1 |
| Buzzer | Signal | A2 |
| 16x2 LCD (I2C) | SDA / SCL | A4 / A5 |
| All components | GND | Common GND rail |
Step-by-step build instructions
Work through these in order — get each part working on the breadboard before mounting anything on the door model.
-
Wire the RC522 module
Connect the RC522's SPI pins and RST as shown in the wiring table, double-checking VCC goes to 3.3V, not 5V.
-
Read your card's ID
Upload a simple RFID test sketch first (most RC522 libraries include one) to read and note down the unique ID number printed on your card or tag.
-
Wire the keypad
Connect the keypad's 8 pins to D2 through D5 (rows) and D6, D7, D8, A0 (columns) as shown in the table.
-
Add the LCD, servo, and buzzer
Wire the LCD to A4/A5, the lock servo to A1, and the buzzer to A2.
-
Update the code with your card ID and PIN
Paste your card's ID number from step 2 into the code below, and choose your own 4-digit PIN in place of the default.
-
Upload and test on the bench
Upload the sketch, tap your card, enter your PIN on the keypad, and confirm the servo moves and the screen shows "Access Granted."
-
Build the door latch mechanism
Attach a small latch or bolt to the servo horn so that when the servo turns, it physically slides the latch out of a slot on the door frame.
-
Mount everything on the door model
Fix the RC522 near where someone would tap a card, the keypad and LCD at an easy-to-reach height, and the servo-latch mechanism inside the door frame.
Arduino code
Copy this into a new sketch in the Arduino IDE. Install the MFRC522, Keypad, Servo, and LiquidCrystal_I2C libraries first from the Library Manager.
#include <SPI.h>
#include <MFRC522.h>
#include <Keypad.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// ---- RFID pins ----
#define RST_PIN 9
#define SS_PIN 10
MFRC522 rfid(SS_PIN, RST_PIN);
// ---- Keypad setup ----
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8, A0};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// ---- Other components ----
#define SERVO_PIN A1
#define BUZZER_PIN A2
Servo lockServo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ---- Security settings: change these for your own system ----
byte approvedUID[4] = {0xDE, 0xAD, 0xBE, 0xEF}; // replace with YOUR card's ID
String correctPIN = "1234"; // replace with YOUR own PIN
String enteredPIN = "";
int wrongAttempts = 0;
bool cardApproved = false;
enum State { WAIT_CARD, WAIT_PIN, LOCKED_OUT };
State currentState = WAIT_CARD;
unsigned long lockoutStart = 0;
const unsigned long LOCKOUT_TIME = 10000; // 10 second cooldown
void setup() {
SPI.begin();
rfid.PCD_Init();
lockServo.attach(SERVO_PIN);
lockServo.write(0); // locked position
pinMode(BUZZER_PIN, OUTPUT);
lcd.init();
lcd.backlight();
showWaitingScreen();
}
void loop() {
switch (currentState) {
case WAIT_CARD:
checkCard();
break;
case WAIT_PIN:
checkKeypad();
break;
case LOCKED_OUT:
checkLockout();
break;
}
}
void checkCard() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) {
return;
}
if (compareUID(rfid.uid.uidByte, rfid.uid.size)) {
cardApproved = true;
enteredPIN = "";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Card OK! Enter");
lcd.setCursor(0, 1);
lcd.print("your PIN: ");
currentState = WAIT_PIN;
} else {
denyAccess("Unknown Card");
}
rfid.PICC_HaltA();
}
bool compareUID(byte *scannedUID, byte size) {
if (size != 4) return false;
for (byte i = 0; i < 4; i++) {
if (scannedUID[i] != approvedUID[i]) return false;
}
return true;
}
void checkKeypad() {
char key = keypad.getKey();
if (!key) return;
if (key == '*') {
enteredPIN = ""; // clear entry
} else if (key == '#') {
submitPIN();
} else if (enteredPIN.length() < 4) {
enteredPIN += key;
}
lcd.setCursor(0, 1);
lcd.print("PIN: ");
lcd.print(enteredPIN);
lcd.print(" ");
}
void submitPIN() {
if (enteredPIN == correctPIN) {
grantAccess();
} else {
wrongAttempts++;
if (wrongAttempts >= 3) {
startLockout();
} else {
denyAccess("Wrong PIN");
currentState = WAIT_CARD;
}
}
enteredPIN = "";
}
void grantAccess() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Access Granted!");
tone(BUZZER_PIN, 1800, 200);
lockServo.write(90); // unlocked position
delay(5000);
lockServo.write(0); // re-lock automatically
wrongAttempts = 0;
cardApproved = false;
currentState = WAIT_CARD;
showWaitingScreen();
}
void denyAccess(String reason) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(reason);
tone(BUZZER_PIN, 400, 400);
delay(1500);
showWaitingScreen();
}
void startLockout() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Too many tries");
lcd.setCursor(0, 1);
lcd.print("Locked out...");
tone(BUZZER_PIN, 400, 800);
lockoutStart = millis();
currentState = LOCKED_OUT;
}
void checkLockout() {
if (millis() - lockoutStart > LOCKOUT_TIME) {
wrongAttempts = 0;
currentState = WAIT_CARD;
showWaitingScreen();
}
}
void showWaitingScreen() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tap your card");
lcd.setCursor(0, 1);
lcd.print("to begin...");
}
Beginner tip
The easiest way to find your card's ID bytes is to run the MFRC522 library's "DumpInfo" example sketch first, tap your card, and copy the four ID numbers it prints into approvedUID.
Safety notes for young makers
Ask an adult to help with wiring, especially double-checking the RC522's 3.3V connection. Keep the servo's latch mechanism free of fingers while testing, since it moves automatically. This is a learning model, not a substitute for a certified home security system.
Why this project works so well for learning
The Smart Secure Entry System introduces real security concepts through hands-on building. Checking both a card and a PIN before granting access is a first taste of two-factor authentication — the same idea behind banking apps and office badge systems. Using a state machine in code (waiting for a card, then waiting for a PIN, then possibly locking out) teaches how to structure a program around clear stages instead of one long tangle of if-statements. And adding a lockout after repeated failed attempts introduces thinking defensively about a system, not just making the "happy path" work.
Frequently asked questions
What age group is this robotics project best suited for?
Ages 11 and up can build this with an adult helping on wiring, especially the RC522's power connections. Ages 14+ with some Arduino experience can usually manage the full build independently.
Do I need to know how to code to build this?
Basic comfort with copying and lightly editing code helps, since you'll need to paste in your own card's ID and choose your own PIN. No programming knowledge beyond that is required to get it running.
Can I use more than one approved RFID card?
Yes. Store several approved UIDs in an array of arrays, and update compareUID() to check the scanned card against each one in turn.
Why does the RC522 need 3.3V instead of 5V like the rest of the parts?
The RC522 module's chip is only rated for 3.3V logic, and connecting it to 5V can permanently damage it. The Arduino Uno has a dedicated 3.3V pin specifically for modules like this.
Can I build this without the keypad, using just the RFID card?
Yes. Skip the keypad wiring and the PIN-checking logic, and call grantAccess() directly once the card matches — though you'll lose the second layer of security.

Comments
Post a Comment