Introduction: Scure Lock With RFID Tag and PIN
You checked in a hotel and given a RFID tag to access your room. If you lost your card and someone else had the lost card can access to your room. Wouldn't it be more secure if another piece of information like PIN is required to open the door?
I have made a simple system using Arduino, RFID reader, display panel and keypad just to demonstrate that. Here I use a LED as a metaphor of a door lock.
Step 1: The Components
Follow are the list of hardware and software component required to build this project:
Arduino UNO & Genuino UNO
RFID-RC522
LCD-LCM1602 IIC
Generic Keypad
Jumper wires (generic)
Male/Female Jumper Wires
Arduino IDE
Some RFID/NFC cards
Step 2: Connect the LCD Display
Connect to LCD-LCM1602 IIC according to the following:
LCD GND pin to GND
LCD VCC pin to 5V
LCD SDA pin to analog 4
LCD SCL pin to analog 5
Please note that I am not able to find a 4-pin LCD-LCM1602 IIC item in fritzing, you need to match the above connection accordingly.
Step 3: Connect the LED
Connect the LED to pin 7.
Step 4: Connect the Keypad
Connect keypad according to the following configuration:
Keypad pin 1 to digital pin 5
Keypad pin 1 to digital pin 4
Keypad pin 1 to digital pin 3
Keypad pin 1 to digital pin 2
Keypad pin 1 to digital pin 14
Keypad pin 1 to digital pin 15
Keypad pin 1 to digital pin 16
Keypad pin 1 to digital pin 17
Please note that digital pins 14, 15, 16,and 17 are extended by analog pins A0, A1, A2, and A3.
Step 5: Connect the RFID Card Reader
I am using the RFID-RC522 card reader. Connect the card reader to match the following configuration:
RFID pin Reset to pin 9
RFID pin SS/SDA to pin 10
RFID pin MOSI to pin 11
RFID pin MISO to pin 12
RFID pin SCK to pin 13
RFID pin GND to pin GND
RFID pin 3.3V to pin 3.3V
Step 6: The Schema
This is the final schema.
Step 7: The Codes
Setup the cards, user names and passwords.
// init paralle arrays
byte knownCards[NR_KNOWN_CARDS][CARD_SIZE] = {
{0x93, 0x47, 0xe0, 0x00},
{0xe5, 0xa2, 0x9c, 0x2c}
};
char name[NR_KNOWN_CARDS][10] = {
"James",
"Richard"
};
char password[NR_KNOWN_CARDS][5] = {
"1234",
"8888"
};
Setup the keypad.
// define for keypad
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {14, 15, 16, 17};
Setup the LCD display.
// define for lcd
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
The main event loop.
void loop() {
init_lcd();
scan_new_card();
key_in_password();
}
Attachments
Step 8: Demo: a Welcome Prompt
A welcome greeting!
Step 9: Demo: Tag a RFID Card and Enter PIN
Tag a RFID card to the reader. You will see a greeting and be asked to key in a PIN. If you key in a wrong PIN or do not manage to key in a PIN within 30 seconds, it will show the welcome prompt again.
Step 10: Demo: Door Unlocked
If you key in a correct PIN, the red LED light will light up indicating that door is unlocked.

Participated in the
Automation Contest 2016

Participated in the
Internet of Things Contest 2016

Participated in the
Sensors Contest 2016
10 Comments
Question 2 months ago
Sir will you please share the circuit diagram
5 years ago
hi, i have a doubt: what kind of data should be written in the tag? I save the name "James" as plain text but it give the message "user not found"
5 years ago
hi.i can not undrestand that where should i write rfid tag id.please help me and answer me to my email
sforati@yahoo.com
6 years ago
having problems with the code, getting the error: 'digitalPinToBitMask' was not declared in this scope, i don't really know how to fix it, would love to get a bit of help with it
6 years ago
can you give me the complete code please!! here's my email alfredviray0@gmail.com A huge thanks!!
Reply 6 years ago
see my earlier comment below.
6 years ago
please can you give me the complete code
Reply 6 years ago
can you give me the complete code, please!
thnguyen.ict@gmail.com
Reply 6 years ago
the code is at the end of step 7: secure_lock_rfid_pin.c
Reply 6 years ago
thankyou very much