How to Make an RFID Door Lock With a PN532 and D1 Mini

Publish date: 2024-07-20

RFID-based door access control is not new. There are several RFID-based systems available in the market that you can install for secure access. However, you can unlock most of the RFID door lock systems using a paper clip since the trigger switch is located within the module installed outside the door.

So let's instead build a completely secure DIY RFID-based door access control system using an ESP8266 and a PN532 RFID/NFC module that can be integrated with your existing electronic lock. Once installed, you can unlock your door using a registered RFID card/tag or smartphone.

Things You’ll Need

To build a DIY RFID-based secure door access control system, you will need the following:

Flash the Firmware to D1 Mini

We will use the ESP-RFID project on GitHub to build our DIY RFID door access control system. Follow these steps to download and flash the ESP-RFID firmware on your D1 Mini or NodeMCU.

  • Download the esp-rfid-1.0.2.zip file and extract the folder on your Desktop. It contains a few program files, including a generic.bin firmware file. Optionally, you may also download the latest v1.3.3 unstable build.
  • Download and run the ESPHomeFlasher tool.
  • Using a Micro USB cable, connect the D1 Mini or NodeMCU to your PC.
  • In the ESPHome Flasher tool, click the refresh icon and choose the COM port where your D1 Mini is connected.
  • Click the Browse button and choose the generic.bin file that we extracted in step 1.
  • Click Flash ESP.
  • This will take a few seconds to complete. Configure the RFID Settings
  • Configure the RFID Settings

    Once the firmware is flashed, reconnect the USB cable to D1 Mini and follow these steps to configure the RFID settings:

  • On your smartphone’s Wi-Fi settings, find and connect to the ESP-RFID-xxxxx access point. It’s an open access point, so it does not require a password to connect.
  • Once connected, switch off the mobile data on your Android and iOS smartphone, and then open the web browser.
  • Visit the IP address 192.168.4.1, and enter the password admin to log in.
  • Click Menu > HardwareSettings and choose the following options from the respective drop-downs:
  • Select PN532 from the Reader Type.
  • Choose GPIO-2 from SPI SS.
  • Keep Everything default and click Save
  • Go to Menu > Settings > General Settings
  • Change the Admin Password from the default admin to something complex. This is a critical step and you must use a long and complex password to protect the devices from unauthorized access.
  • You may also edit the Host Name and choose if you want the device to Auto Restart Every 24h, 7 days, or 30 days.
  • Go to Menu > WirelessNetwork and then enter a complex password to secure the access point. Again, use a strong password to prevent unauthorized access.
  • You may also choose the Client option and connect the device to a wireless network.
  • Click Save and then click on the text highlighted with yellow color at the bottom of the screen.
  • Click Save & Reboot.
  • The device will reboot.
  • Connect RFID Sensor to D1 Mini

    Disconnect the USB cable from D1 Mini or NodeMCU. Refer to the following table and diagram to connect the PN532 RFID/NFC sensor and the relay module to the D1 Mini or NodeMCU board.

    NodeMcu/WeMos D1 Mini Pins

    PN532 Pins

    Relay Module

    D8 (GPIO-15)

    SS

    D7 (GPIO-13)

    MOSI

    D6 (GPIO-12)

    MISO

    D5 (GPIO-14)

    SCK

    D4 (GPIO-2)

    INPUT

    Vin/5V

    VCC

    VCC

    G

    GND

    Ground

    Use the DuPont wires or Berg Strips to connect or solder the D1 Mini or NodeMCU pins to the PN532 and the relay module. If you never soldered any connection before, learn how to solder wires and electronics.

    Make sure to enable SPI protocol on PN532 by moving the DIP switch to 0 and 1 positions as shown below.

    Once the RFID module is connected to your NodeMCU or WeMos D1 Mini, you can start scanning the RFID card to register and add users to allow/disallow access.

    Add RFID Cards/Users

    After connecting the PN532 module to the D1 Mini or NodeMCU, follow these steps to add and register users’ RFID cards or tags.

  • Connect the USB power supply to the Wemos D1 Mini or NodeMUC.
  • Go to your Wi-Fi settings and connect to the esp-rfid access point using the password you set up under Wireless Network settings.
  • Visit the 192.168.4.1 IP address.
  • Click Menu > Users.
  • Take an RFID card or tag and put it against or near the PN532 RFID/NFC sensor. You will see a new Add a new User form with the scanned RFID tag ID.
  • Type the name of the person to whom the card or tag belongs.
  • Choose Access Type. You can choose between Always, Disabled, or Administrator. You should add one card for the admin (yourself).
  • Choose Valid until date till when you want to allow or disable the user access.
  • Click Save Changes to save the user details.
  • Unlock Door Using Web Interface

    Once you have added and saved the users’ RFID cards, you can scan them against the PN532 sensor. Scanning cards with Access Type: Always or Administrator will trigger the connected relay module. You can connect the wires of your electronic door lock power supply switch to this relay module to trigger the lock and unlock the door.

    Here’s a connection diagram you can refer to for connecting the electronic door lock trigger switch wires.

    Secure RFID Door Access Control

    Unlike RFID door access control systems available in the market that can be easily unlocked and have no UI, this DIY RFID door lock system is Wi-Fi enabled, smart, and offers an intuitive UI to manage users and revoke their access anytime.

    If you connect the DIY RFID module to your Wi-Fi network, you can access it on your network through IP address assigned by your router. You can assign static IP to this device and unlock the door by login into the web interface and clicking on the Test button under the Hardware Settings. You can use a LAN cable or any cable with 6-wires to separate the PN532 and the D1 Mini or NodeMCU relay module to prevent unauthorized access and secure your door lock.

    ncG1vNJzZmivp6x7rq3KnqysnZ%2Bbe6S7zGikmqOVYsawwdFmprCmXaiypMHRnmSdoaliv6e1w2abqKeiYrmwr8pmqrKrpJq6cA%3D%3D