element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Project Videos
  • Challenges & Projects
  • element14 presents
  • Project Videos
  • More
  • Cancel
Project Videos
Documents ESP32 + RFID = Smart Access Control in a Simple DIY Build -- Episode 706
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Project Videos to participate - click to join for free!
Related
Recommended
Engagement
  • Author Author: cstanton
  • Date Created: 18 Mar 2026 5:58 PM Date Created
  • Last Updated Last Updated: 19 Mar 2026 11:36 AM
  • Views 134 views
  • Likes 2 likes
  • Comments 2 comments

ESP32 + RFID = Smart Access Control in a Simple DIY Build -- Episode 706

In this project, Mark builds a simple but effective RFID-based access control system using an ESP32 and MFRC522 reader. The system can be programmed to recognise a specific RFID tag and trigger a relay or solenoid lock, making it ideal for securing enclosures, doors, or equipment. The video covers the full process, from circuit design and component selection to firmware setup and real-world installation, including mounting the reader behind glass and integrating a locking mechanism.

Get Locked In and Watch the Project Build

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Building an RFID-Controlled Lock with ESP32

Mark’s project walks through a complete, working RFID access control system built around an ESP32 and a common MFRC522 reader. It’s positioned as a flexible foundation, something that can open a door, trigger a relay, or secure equipment, and the implementation reflects that balance between simplicity and practical use.

“Once you build it, you can use it to open a mechanical lock or control a relay… whatever you see fit.”

image

Parts Overview

At its core, the system combines:

  • An ESP32 as the controller

  • An MFRC522 RFID reader for tag detection

  • A relay or solenoid lock for actuation

  • A transistor + flyback diode to safely drive inductive loads

  • A push button to enter programming mode

The design is intentionally minimal. As Mark puts it:

“And that’s all there is to it.”

That simplicity is one of the strengths of the project, there’s no unnecessary abstraction, just the essential building blocks required to make a usable access system.

Hardware Design Considerations

The circuit reflects a standard embedded control pattern: low-power logic controlling a higher-power actuator.

  • The transistor acts as a switch, allowing the ESP32 GPIO to control a 12V load.

  • The flyback diode protects against voltage spikes from the relay or solenoid coil:

    “A diode that protects the transistor from the spikes that are generated by the coil.”

  • The button input enables runtime configuration without reflashing firmware.

Mark also explores different locking mechanisms,from small cabinet latches to larger solenoids, highlighting flexibility in real-world applications. Notably, all examples operate at 12V, which is a practical choice for readily available actuators.

image

Physical Build and Layout

Rather than staying on a breadboard, Mark moves quickly into a semi-permanent build using perfboard. He physically trims the board to size:

“I use a knife… and I should be able to simply break it.”

This step is easy to overlook but important,it signals a transition from prototype to deployable hardware. The layout decisions (like diagonal placement due to pin pitch) are practical, not aesthetic. This is typical of fast, functional builds.

There are also moments where routing issues appear and are corrected:

“We solve that in a minute.”

That kind of iterative adjustment is realistic and useful for viewers attempting to replicate the project.

image

Firmware Architecture and Behaviour

The firmware is straightforward but well structured. It uses the MFRC522 library stack and EEPROM for persistence.

Libraries and setup

The project relies on:

  • MFRC522v2 for RFID communication

  • SPI for hardware interface

  • EEPROM for non-volatile storage

Only one external install is required:

“You need to install… RFID MFRC522, version 2.”

Key logic and code breakdown

1. Pin configuration and mode selection

#define relais 14
#define pswitch 12
#define led 2
char programmode=0;

  • Relay output on GPIO 14

  • Programming switch on GPIO 12

  • LED used as a status indicator

At boot, the system checks the button:

if(digitalRead(pswitch)==0){
  programmode=1;
}

This is a simple but effective pattern: boot-time mode selection avoids needing serial commands or UI.

2. RFID detection loop

The main loop exits early if no card is present:

if (!mfrc522.PICC_IsNewCardPresent()) {
  return;
}

This keeps execution efficient and avoids unnecessary processing.

Once a card is detected, its UID is read and converted:

String uidString = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
  if (mfrc522.uid.uidByte[i] < 0x10) {
    uidString += "0"; 
  }
  uidString += String(mfrc522.uid.uidByte[i], HEX);
}

This conversion step is important, it ensures a consistent string format for comparison.

3. EEPROM storage and comparison

The system uses EEPROM to store a single authorised UID:

EEPROM.writeString(0,uidString);
EEPROM.commit();

And later compares it:

if (uidString == EEPROM.readString(0)){
  digitalWrite(relais, HIGH);
}

Mark summarises the behaviour clearly:

“If there is a match, then it will open the door or activate the relay.”

image

Design observations, Limitations and Future Improvements

  • Single UID storage keeps the logic simple but limits scalability

  • EEPROM use is appropriate for persistence across resets

  • The 3-second relay activation (delay(3000)) is fixed, this could be parameterised

The final application is a practical one: securing a 3D printer enclosure.

“I do have a curious kid… this way I can prevent her from opening it.”

Mark hints at broader applications but doesn’t extend the design further. There are several obvious next steps:

1. Multiple user support

Currently only one UID is stored. Expanding to a list would make this viable for shared access.

2. Security considerations

  • UID-based authentication can be cloned on some tags

  • No encryption or challenge-response mechanism

3. Feedback and UX

  • Add buzzer or LED patterns for success/failure

  • Serial output is useful but not user-facing

4. Power and enclosure

  • No dedicated enclosure or power regulation shown

  • Long-term installs would need proper housing

This project does exactly what it sets out to do: deliver a working RFID-controlled lock with minimal overhead. It’s approachable, adaptable, and grounded in real use rather than theory.

The combination of ESP32, MFRC522, and a simple transistor driver is well understood—but Mark’s implementation shows how quickly that can become something practical.

“Present my ring… and it will open.”

That direct cause-and-effect is what makes the project useful, and easy to build upon.

Supporting Files and Links

-  Episode 706 Resources  

Bill of Materials

Product Name Manufacturer Quantity Buy Kit
WURTH ELEKTRONIK Tactile Switch, WS-TATV Series, Top Actuated, Through Hole, Round Button WURTH ELEKTRONIK 1 Buy Now
Transistor BC517-D74Z Onsemi 1 Buy Now
Resistor 1K Multicomp pro 1 Buy Now
Diode 1n4001 Onsemi 1 Buy Now
RFID Tag KW9Z-T1X5B IDEC 1 Buy Now
Product Name Manufacturer Quantity
ESP32 Doit Devkit V1
RFID reader PCB develp. Kit RC522
USB cable and USB power supply
Lock mechanism 5V BADODO Security 1
 
  • rfid security project
  • rfid access control system
  • mfrc522 esp32 tutorial
  • embedded systems rfid project
  • rfid door lock diy
  • esp32 rfid project
  • solenoid lock control esp32
  • esp32 relay control
  • arduino rfid lock
  • diy electronic lock
  • esp32 home automation
  • friday_release
  • rfid reader esp32 code
  • Share
  • History
  • More
  • Cancel
Actions
  • Share
  • More
  • Cancel
  • Sign in to reply

Top Comments

  • donnersm
    donnersm 14 hours ago +1
    Remember, If you have questions or comments...let me know!
  • DAB
    DAB 10 hours ago

    Nice project.

    What about security?

    Can any RFID card open the lock or can someone spoof the RFID to open the lock.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • donnersm
    donnersm 14 hours ago

    Remember, If you have questions or comments...let me know!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube