0% found this document useful (0 votes)
12 views

Arduino - RFIDNFC Door Lock System Arduino Tutorial

Uploaded by

Ahmed Dridi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Arduino - RFIDNFC Door Lock System Arduino Tutorial

Uploaded by

Ahmed Dridi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

×

Ads by ArduinoGetStarted.com

Arduino - RFID/NFC

OOTOT
ArduinoGetStarted.com Door Lock System
ElectromagneticLock
765432
RESET
ITAL(PWM») 80
om
ICSP2

DUNO rte d.c


(Sta
TX1 圖ON
RXI
ARDJINO
m
ICSP

.co
rted
POADIMOVROR

t S ta 10150-005

Ge ®• DIY
POV ER ANALOGIN
Ardu wN
ables

12VDCPowerAdapter

Learn More

Advertisement: 0:15
 Now Playing

: (0:15)
Ad  

How Motion Sensor Works 


Fullsc… Share

Watch on

In this tutorial, we are going to learn how


to make Arduino RFID/NFC Door Lock
System using Arduino, RFID/NFC RC522 Kit,
and electromagnetic lock or solenoid
lock.

Advertisement

Buy 8 get the 9th


FREE all Authority wet
dog food

Shop Now

※ NOTE THAT:

We also have others Arduino - Door


lock system using keypad tutorials.

···

Hardware Required
1×Arduino UNO or Genuino UNO 

1×USB 2.0 cable type A/B 

1×RFID/NFC RC522 Kit (reader + tags) 

1×RFID Key Fob 

1×Solenoid Lock 

1×(Alternative) Electromagnetic Lock 

1×Relay 

1×12V Power Adapter 

1×DC Power Jack 

1×Jumper Wires 

(Optional) 9V Power Adapter for


1× 
Arduino

(Recommended) Screw Terminal


1× 
Block Shield for Arduino Uno

(Optional) Transparent Acrylic


1× 
Enclosure For Arduino Uno

Or you can buy the following sensor kits:

DIYables Sensor Kit (30


1× 
sensors/displays)

DIYables Sensor Kit (18


1× 
sensors/displays)

Please note: These are Amazon affiliate links. If


you buy the components through these links,
We will get a commission at no extra cost to
you. We appreciate it.

About RFID/NFC RC522


Module and Electromagnetic
Lock

If you do not know about RFID/NFC RC522


Module, Electromagnetic Lock and
Solenoid Lock (pinout, how it works, how
to program ...), learn about them in the
following tutorials:
Arduino - RFID/NFC RC522 tutorial
Arduino - Solenoid Lock tutorial
Arduino - Electromagnetic Lock tutorial

System Components

The door lock system includes two main


parts:

Door Lock: Arduino + RFID/NFC reader


+ Electromagnetic lock
Door Key: RFID/NFC tags

There are some types of RFID/NFC


readers that can work with Arduino. This
tutorial uses RFID-RC522 as an RFID/NFC
reader because it is cheap.

How RFID/NFC Door Lock


Works
Some tags that have UIDs set in Arduino
code acts as the authorized keys
User taps an RFID/NFC tag on RFID/NFC
reader
The reader reads UID from the tag.
Arduino gets the UID from the reader
Arduino compares the read UID with the
predefined UIDs
If the UID is matched with one of the
predefined UIDs, Arduino deactivates the
electromagnetic lock to unlock the door.

Wiring Diagram
RFID RC522 Door Lock with Solenoid Lock

This image is created using Fritzing. Click to enlarge image

RFID RC522 Door Lock with


Electromagnetic Lock

ArduinoGetStarted.com
OOTOT

ElectromagneticLock
765432
RESET
ITAL(PWM») 80
.com
ICSP2

TX1 DUNO 圖ON


ta rted
RXI
ARDJINO (S
.com
ICSP

POADIMOVROR

rted
Sta
10150-005

Get ®• DIY
Ardu POV ER ANALOGIN
wN
ables

12VDCPowerAdapter

This image is created using Fritzing. Click to enlarge image

To make it simple, the RC522 module's


pins are directly connected to the
Arduino's pins. However, this may cause
the Arduino to stop functioning properly
in certain cases since the output pins of
the Arduino produce 5V, whereas the pins
of the RC522 module function normally at
3.3V. Therefore, it is recommended to
regulate the voltage between the Arduino
pins and the RC522 module's pins. For
more detailed instructions, please refer to
the Arduino - RFID RC522 tutorial. The
diagram below illustrates how to regulate
5V to 3.3V using resistors:

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

The order of pins can vary according


to manufacturers. ALWAYS use the
labels printed on the module. The
above image shows the pinout of the
modules from DIYables
manufacturer.

Arduino Code - Single Key


1 /* 
2 * Created by ArduinoGetStarted.com
3 *
4 * This example code is in the public do
5 *
6 * Tutorial page: https://arduinogetstar
7 */
8
9 #include <SPI.h>
10 #include <MFRC522.h>
11
12 #define SS_PIN 10
13 #define RST_PIN 5
14 #define RELAY_PIN A5 // the Arduino pin
15
16 MFRC522 rfid(SS_PIN, RST_PIN);
17
18 byte keyTagUID[4] = {0xFF, 0xFF, 0xFF, 0
19
20 void setup() {
21 Serial.begin(9600);
22 SPI.begin(); // init SPI bus
23 rfid.PCD_Init(); // init MFRC522
24 pinMode(RELAY_PIN, OUTPUT); // initial
25 digitalWrite(RELAY_PIN, HIGH); // lock
26
27 Serial.println("Tap RFID/NFC Tag on re
28 }
29

Quick Steps

Because UID is usually not printed on


RFID/NFC tag, The first step we need to do
is to find out the tag's UID. This can be
done by:
Copy the above code and open with
Arduino IDE

···

Click Upload button on Arduino IDE


to upload code to Arduino
Open Serial Monitor
Tap an RFID/NFC tag on RFID-RC522
module
Get UID on Serial Monitor
COM6

Send

Tap RFID/NFC tag on reader


Access denied for user with UID: 3A C9 6

Autoscroll Show timestamp Newline 9600 baud Clear output

After having UID:


Update UID in the line 18 of the above
code. For example, change byte
keytagUID[4] = {0xFF, 0xFF, 0xFF,
0xFF}; TO byte keytagUID[4] = {0x3A,
0xC9, 0x6A, 0xCB};
Upload the code to Arduino again
Tap an RFID/NFC tag on RFID-RC522
module
See output on Serial Monitor
COM6

Send

Tap RFID/NFC tag on reader


Access is granted

Autoscroll Show timestamp Newline 9600 baud Clear output

Check the electromagnetic lock, it should


be unlocked
Tap another RFID/NFC tag on RFID-RC522
module
See output on Serial Monitor
COM6

Send

Tap RFID/NFC tag on reader


Access is granted
Access denied for user with UID: BD 1E 1
Autoscroll Show timestamp Newline 9600 baud Clear output

※ NOTE THAT:
To make it easy to test, the unlocked
time is set to 2 seconds, it should be
increased in practical
use/demonstration
It need to install MFRC522 library. See
Arduino - RFID/NFC RC522 tutorial

Arduino Code - Multiple Keys

Let's imagine that a room allows the


manager and secretary to unlock the

···
door only.

In this case, we need to use two RFID/NFC


tag: one for the manager and the other
for the secretary. We have to specify the
UIDs of two tags in the code
1 /* 
2 * Created by ArduinoGetStarted.com
3 *
4 * This example code is in the public do
5 *
6 * Tutorial page: https://arduinogetstar
7 */
8
9 #include <SPI.h>
10 #include <MFRC522.h>
11
12 #define SS_PIN 10
13 #define RST_PIN 5
14 #define RELAY_PIN A5 // the Arduino pin
15
16 MFRC522 rfid(SS_PIN, RST_PIN);
17
18 byte managerKeyUID[4] = {0x3A, 0xC9, 0
19 byte secretaryKeyUID[4] = {0x30, 0x01, 0
20
21 void setup() {
22 Serial.begin(9600);
23 SPI.begin(); // init SPI bus
24 rfid.PCD_Init(); // init MFRC522
25 pinMode(RELAY_PIN, OUTPUT); // initial
26 digitalWrite(RELAY_PIN, HIGH); // lock
27
28 Serial.println("Tap RFID/NFC Tag on re
29 }

Do the similar steps as the above, and


then tap one by one tag on RFID-RC522
module. The result on Serial Monitor looks
like below:
COM6

Send

Tap RFID/NFC tag on reader


Access is granted for secretary
Access is granted for manager
Autoscroll Show timestamp Newline 9600 baud Clear output

You can extend the above code for three,


four, or more tags.

※ NOTE THAT:

In the above code, the keys are


hard-coded. In the practice, it should
be able to add/delete keys
dynamically via a special mode. If so,
the keys should be saved on EEPROM
memory. The number of keys can be
saved depends on the EEPROM's size.
The code will become complicated. If
you want to build such system, we
provide a coding service. Please feel
free to contact us.

Video Tutorial

We are considering to make the video


tutorials. If you think the video tutorials
are essential, please subscribe to our
YouTube channel  to give us motivation
for making the videos.

The Best Arduino Starter Kit


See the best Arduino kit for beginner

···

See Also
Arduino - RFID/NFC
Arduino - RFID/NFC - Relay
Arduino - RFID/NFC - Servo Motor
Arduino - RFID - Solenoid Lock
Arduino - RFID - Electromagnetic Lock
Arduino - RFID MP3 Player

※ OUR MESSAGES
We are AVAILABLE for HIRE. See
how to hire us to build your
project

You might also like