Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Arduino-based RFID door lock

By Nikhil Agnihotri January 25, 2022

Electronic door locks are safer than conventional door locks. There is no possibility of lock picking in such door locks as the entire mechanism is electronic. Such door locks have an underlying embedded access control system which is generally impenetrable. Several access control systems are used in electronic door locks. The most common access control systems used in electronic locks are PIN (Personal Identification Number), fingerprint, and RFID.

The fingerprint access control systems are preferred only for high security or personal security solutions, are highly personalized, and are costly. The PIN and RFID are cost-effective solutions applicable to public access systems like hotel rooms, classrooms, and offices. Of these two, RFID access control systems come with higher security and offer wider applications. For example, RFID solutions can be used simultaneously for access control as well as attendance in school/college classrooms.

In this project, we are designing an RFID door lock system and will explore how the locking mechanism can be built in different ways.

Components required

  1. Arduino UNO/Arduino Mega x1
  2. RC522 RFID Reader x1
  3. MFRC522 RFID cards/tags x2
  4. SSD1306 OLED display x1
  5. Relay module & solenoid lock or Servo motor x1
  6. Connecting wires/jumper wires

 Circuit connections
The door lock system consists of two critical circuits – the access control system and a locking mechanism. For the access control system here, an RFID is used. This door lock uses an RC522 RFID reader to read MIFARE and NTAG compatible RFID cards. Each lock passes access to only one RFID card, so all other cards are denied access. The system can also be programmed to provide additional access to a master card, which may be used instead of a lost card. The user interface is designed using an SSD1306 OLED display. Therefore, the complete access control system is designed by interfacing the RC522 RFID reader and SSD1306 OLED display with Arduino UNO.

The RC522 RFID reader is interfaced with Arduino using SPI protocol. The following circuit connections are made for interfacing the RFID reader with Arduino UNO. To learn more about reading RFID cards using RC522, check out this link.

The SSD1306 OLED is interfaced with Arduino using the I2C protocol. To learn more about interfacing SSD1306 OLED display with Arduino using serial I2C, check out this link. For interfacing SSD1306 with Arduino, the following circuit connections are made.

Circuit Diagram of Arduino-based RFID Access System

The locking mechanism can be built in two different ways. A do-it-yourself lock can be designed using a servo motor in one method. If the locking mechanism is built using a servo motor, it requires a PWM pin on Arduino for control.

It is recommended that servo is provided separate power supply using batteries as power fluctuations from the servo motor can damage the Arduino board.

In the second method, the lock can be designed using a solenoid lock. In this case, the lock can be controlled using any GPIO on Arduino via a relay module.

Circuit Diagram of Arduino-based RFID Door Lock with the servo.

The relay itself separates the power supplies of Arduino and the solenoid.

Arduino sketch (RFID Access Control)

How RFID access system works
The RFID reader used to design this door lock is RC522. This RFID reader can read MIFARE and NTAG compatible RFID cards. The RFID cards either have a 7-byte long Unique Identity Number (UID) or 4-byte long Non-Unique Identity Number (NUID). Even if NUID cards are used, there is almost no possibility of getting two cards with the same NUID. The locking systems are designed such that the ID number of scanned cards is not disclosed in the process of access control. Even if the ID of a card is accessed from a different device, it is far from possible to get an RFID card of the same ID number.

When an RFID card is scanned through the RC522, it reads the NUID/UID of the particular card. The scanned NUID is compared against a pre-stored ID number for the door lock system. If the ID of the scanned card matches with the programmed ID, a welcome message is displayed on the OLED display. If the ID of the scanned card does not match with the programmed ID, the door remains unlocked, and a message denying access is displayed on the OLED display. At the same time, the door is unlocked either by rotating the servo in case of DIY servo lock or activating the relay in case of solenoid lock. The lock is programmed to pass access to only one RFID card.

The code
The sketch begins with importing SPI and MFRC522 library for working with the RC522 reader. The library used in this project is Arduino MFRC522 Library from miguelbalboa, available at Github. Download the library as a ZIP file. Navigate to Sketch->Include Library->Add .ZIP Library in Arduino IDE. Select the rfid-master.ZIP, and the library for RC522 is added to the Arduino environment.

This is followed by importing Wire, Adafruit_GFX, and Adafruit_SSD1306 libraries for working with SSD1306 OLED. These libraries can be easily found in the library manager.

Next, constants are defined for circuit connections with the OLED display, and an object of the Adafruit_SSD1306 class is instantiated. The constants for circuit connections with RC522 are defined, and an object of the MFRC522 class is instantiated. A variable to store the MIFARE key is defined. A byte array ‘ nuidPICC[]’ is defined to store 4 bytes of RFID NUID. Variables are declared to store string representations of the NUID in decimal and hexadecimal formats. Similarly, a variable to store a string representation of the MIFARE key is defined. A bitmap is stored in PROGMEM for site loge, and an array is defined for the same.

In the setup() function, the baud rate for serial communication is set to 9600 bps. The OLED display is initialized by calling display.begin(SSD1306_SWITCHCAPVCC) method and display is flashed by calling display.display() method. The SPI protocol is initialized by calling SPI.begin() method. The RFID module initializes the PCD_Init() method on the RFID object. The MIFARE key bytes are set to FF and stored in an upper-case string representation. The MIFARE key is published on the Serial Monitor. The OLED display is cleared, and the site logo is flashed.

In the loop() function, some initial messages are first flashed on the screen. RFID card/key/tag is detected by calling PICC_IsNewCardPresent() method on the RFID object. Next, the card NUID/UID is read by calling the PICC_ReadCardSerial() method on the RFID object. The MIFARE card type is detected using the PICC_GetType(rfid.uid.sak) method and displayed on the Serial Monitor. Next, the individual bytes of the NUID are accessed using the rfid.uid.uidByte[] property. First, the bytes are serialized in decimal format and converted to a string object. The string containing a decimal representation of NUID is published on the Serial Monitor. Next, the bytes are serialized in hexadecimal format and converted to a string object. The string containing a hexadecimal representation of NUID is published on the serial monitor.

The read bytes of NUID are stored in a character array. This character array is compared to a predefined NUID using user-defined compareNUID() function. The function returns a boolean value used to determine access control. If the scanned NUID is matched with the programmed ID, a message granting access is displayed on the OLED screen. If the scanned NUID does not match the programmed ID, a message denying access is displayed on the OLED screen.

The reader is stopped from reading the card by calling PICC_HaltA() method on the rfid object. Finally, the encryption is stopped by calling PCD_StopCrypto1() method on the RFID object.

The loop() function uses two user-defined functions – printtext() and compareNUID(). The printtext() function is defined to display messages on the OLED screen. The compareNUID() function is defined to compare scanned cards with a programmed ID.

Building and controlling locking mechanism
The electronic locking mechanism can be designed in several ways. Here, we discuss two ways. In the first method, we can create a DIY servo lock. The servo remains at zero degrees in an unlocked position and rotates by 90 degrees in the locked position. Its data pin must be connected to an Arduino PWM pin to control the servo. The servo is controlled via pin D3 of the Arduino UNO in the circuit diagram above.

Servo for electronic door lock

The second method is done by attaching a solenoid lock to the Arduino via a relay module. A 5V relay can be controlled from any GPIO of the Arduino UNO. The pin D3 of Arduino is also a digital input/output, so it can also be used to control the relay.

Arduino sketch for DIY servo lock

Arduino set for solenoid lock

You may also like:

  • pollution monitoring
    Arduino-based portable pollution monitor with OLED display

  • Arduino-based walking steps and distance calculator

  • Arduino-based altitude meter using BMP180 sensor

  • Arduino-based multicolour LED chaser

  • Arduino-based electronic leveling device

  • Arduino-based heartbeat monitor with graphical heartbeat display

Filed Under: Arduino Projects, Electronic Projects, Featured
Tagged With: Arduino, Arduino MFRC522 RC522 RFID Reader, Arduino MFRC522 RFID Reader, Arduino MIFARE RFID Tags, Arduino projects, Arduino RC522 RFID Reader, Arduino RFID Access Control System, Arduino RFID door lock, Arduino RFID door lock servo, Arduino RFID door lock solenoid
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Voltage mode pushpull is a nonsense SMPS?
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe