Wireless RFID Door Lock Using Nodemcu

29,381

92

23

--- Main Function ---

This project was build as part of a Network Communications class at Universidade do Algarve in collaboration with my colleague Luís Santos. Its main purpose is to control the access of an electric lock through wireless with the use of RFID tag cards or key rings.

Although this project was designed to work with a door lock, it can be easily modified to support any kind of solenoid switch (this will be referred further during this tutorial).

--- Present Version ---

This first version will be done with the support of a server and a simple txt file. In future work, there'll be added different variants that will suit different needs and present a more secure alternative.

--- Future Work ---

When I find some free time I'll try to update the following features:

  • Special Administrator card to add other users
  • Access the file through the router's USB mounted storage
  • Encrypt the file with a simple binary key
  • Connect a real solenoid lock to the relay and update the Instructables with a working video
  • Connect to a DBMS for ease control and maintenance of multiple locks and users
  • Add a local MicroSD file to backup the information in case of Wireless unavailability
  • Connect through a GSM GPRS Communications Module
  • Make it working with a solar panel to be absolutely wireless

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Components Required

The components needed for this project are:

  • NodeMCU ESP8266 WIFI Development Board
  • DC 5V 1 Channel Relay Module
  • RC522 Chip IC Card Induction Module RFID Reader
  • RFID Tag Cards or Key Rings
  • Solenoid Switch Door Lock
  • One Diode from 1N4001-1N4007
  • Cables
  • Breadboard

Extra:

  • RGB 3 Color Led Module 5050 or:
    • A Red LED and a Green LED accompanied by 220ohms resistor
  • 0.96 Inch 4Pin Blue Yellow IIC I2C OLED Display Module

Curiosity: NFC is a subset within the RFID family and operates at the same frequency (13.56 MHz).RC522

Step 2: Connecting the Nodemcu to a Wi-fi Network

There are already good tutorials that can help you connect the NodeMCU to any 802.11 wireless networks. The one we followed was:

Installing ESP8266 Into Arduino IDE Tutorial by Mybotic

Note: Beware that the pin layout on the NodeMCU is different from the Arduino, and so, if you use p.e.: #define Led 5 is actually connected to D1 on the board, as it can be seen in the above figure.

One solution is the inclusion of a library that already does this association. We simply followed the image to guide us. Later in this tutorial there'll be an image with all the connections done.

Step 3: Connect the RFID Reader

Go to Manage Libraries... inside the Include Library under Sketch in the Menu Bar.

On the text box with the "Filter your search..." insert MFRC522 and choose to install the one that is by GithubCommunity, with the designation Arduino RFID Library for MFRC522 (SPI).

--- Reading RFID Cards ---

If you wish to test the RFID reader, go to Examples under File in the Menu Bar and search for MFRC522 and choose the ReadNUID to tried it.

Step 4: Setting Up the Base Configuration

First, we'll assembly the base configuration following the circuit's diagram shown above (if you click on the image there's additional information about the pin layout).

Then, connect the NodeMCU and open the Arduino IDE and copy the code bellow.

Don't forget to replace the ssid and password for the ones of your network, and your server host address on the code.

Step 5: Creating the Txt File With the Cards' Ids

If you already tested the previous step, it probably didn't happening anything when you tried approaching the cards to the RFID reader. That's OK! You still need to add the cards you desire to your server (there'll be other alternatives in the unforeseen future).

First, you'll need to have your server up and running. Create a .txt file anywhere you desire and open the Serial Console on your Arduino IDE. Run the code and copy the RFID MAC address that is presented, paste it to the .txt file and press Enter, so that there's always an empty line at the end. Save the .txt file and try it again.

Now it should work, you don't have to reset the NodeMCU or restart the server.

The ON LED color that comes with the relay is usually red and so, if the lock is open, it should shine red. On a further customization we'll try to change this LED to offer a permanent red status and a green status without the need to use additional ports on the NodeMCU board.

Note: don't forget to change the folder's location on the url inside the code.

Step 6: Connecting the Relay to a Solenoid Switch

Attention, this step is important.

Solenoid switches are but coils that with current create a magnetic field that pulls or push a piston. They may come like solenoid valves, door locks, switches, etc...

What you need to do carefully are two steps:

  • Connect your energy source and solenoid switch to the relay in the correct way, as shown above;
  • Connect a diode between the two pins of your solenoid switch for circuit protection.

Step 7: Extra: Adding RGB Leds

Just follow the above circuit's diagram and don't forget to add a 220 ohms resistor between the anode and ground.

If the light is too dim or too bright, you can change the value of the resistor (just don't jump from a 220 ohms resistor to a 1M ohm resistor and pretend to be perplex with the results).

Step 8: Extra: Adding a OLED Screen

As before, you just have to follow the circuit's new diagram above and the code bellow.

The future mais purpose of the OLED screen is not to simply replicate the RGB function, but to allow for additional informations to the user if required.

Step 9: Final Configuration

Above it's possible to see this project working though a video and a couple of images, running with the complete code, including the extras.

Invention Challenge 2017

Participated in the
Invention Challenge 2017

Be the First to Share

    Recommendations

    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest

    23 Discussions

    0
    None
    duka83

    Question 21 days ago

    HI,
    How can i see in Door_Lock_Leds_Oled.ino file, there is no code for OLED Display to display informations...? Could you upload file with OLED code?

    1
    None
    TSTOM

    1 year ago

    Need some help! Although i created the .txt file with the MAC adress iw still says "Not Authorized"!!!! Any solution?

    6 replies
    0
    None
    MaxS200TSTOM

    Reply 1 year ago

    The cards.txt file should have the following format:

    *************

    7F D4 BE 2F

    *************

    Not that there is a space before the first HEX number and a blank line at the end. Make sure the web server can read the file.

    0
    None
    wizworksMaxS200

    Reply 4 months ago

    Hi, this isn't working for me. I still get Card read: C9 5A 50 39 in the serial window. I see the hits on the webserver log. My file is formatted:
    **********
    C9 5A 50 39

    **********
    What am I doing wrong?

    0
    None
    usenet.j23wizworks

    Reply 2 months ago

    After line content.toUpperCase();
    add:
    content.trim();

    and after line line = client.readStringUntil('\n');
    add
    line.trim();

    0
    None
    MaxS200wizworks

    Reply 4 months ago

    Hi, did you add a space before the C9? As far as I can remember the space is required.

    1
    None
    jeff_1158TSTOM

    Reply 1 year ago

    I'm having the same problem. Also the OLED version just includes an OLED library. There does not appear to be any code for using the display.

    0
    None
    navjotsdjeff_1158

    Reply 10 months ago

    checkout Door_Lock_Base.ino

    the very first example sketch.

    however, i cant get my program to compile yet

    0
    None
    MartinK149

    Question 3 months ago on Step 9

    I want to toggle the relay with a hyterese of about 30seconds to avoid fast relais on and off behaviour. can you modify the code in that way?
    Background is enabling a electric car charging wallbox to avoid misuse by unauthrized people.

    0
    None
    rizkihasbiallah06

    Question 6 months ago on Step 9

    I want to ask, I tried to follow the procedure that you gave, and when I tried it, for the door lock base there was DISPLAY_WIDTH not declared, I tried to declare it but the result was only a question mark (??????) and I tried the program the ones that are led and oled are the same as the question mark (???) all ... how to fix it ??

    2 answers
    0
    None
    4PeterWrizkihasbiallah06

    Answer 5 months ago

    depending of your library try "display.width()/2,display.height()/2" instead

    0
    None
    rizkihasbiallah064PeterW

    Reply 4 months ago

    I've tried changing to display_width () / 2, display_height () / 2. but still can not display.drawString source code (display_width () / 2, 10+ (display_height () / 2) and the information was not declared in this scope ... how?

    1
    None
    FeysulahM

    Question 1 year ago

    I don't know why but there is an issue.
    #include "SSD1306.h" <- it happens at this point
    SSD1306.h: No such file or directory
    happens when I try to compile. I even tried adding the adafruit_ssd1306 library, and then added the adafruit_gfx and changed the parts where. Then the error occurs in display.init();.

    Would be very glad for some help.

    3 answers
    0
    None
    ocalle905FeysulahM

    Answer 4 months ago

    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    #define OLED_RESET LED_BUILTIN //4
    Adafruit_SSD1306 display(OLED_RESET);

    Void loop
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println("Some text");
    //display.println("http://xxxxx.xxx");
    display.display();

    0
    None
    wizworksocalle905

    Reply 4 months ago

    Ok with adafruit library I now get this unresolvable error:
    'SSD1306' does not name a type

    0
    None
    navjotsdFeysulahM

    Answer 10 months ago

    It worked with the adafruit library, shall share code soon

    0
    None
    ocalle905

    4 months ago

    Hey cool project thank you, can you say how can i add another extra reader?, will be great the connection diagram and some code. Regards

    0
    None
    pryan15

    1 year ago

    This could easily become the backbone of every makerspace in the world if you wanted. There is currently no good solution as to how to affordably verify that someone has been trained and cleared for a given piece of equipment. With very few tweaks and a little help your design could easily solve that problem.

    0
    None
    JánosG7

    Question 1 year ago on Step 9

    Hello.

    I've built your project a very nice job.

    But I can not connect to the server, can you send me body.txt what should look like?

    Thanks in advance.

    0
    None
    Swansong

    2 years ago

    Really good instructable, that's a neat setup :)