DIY RFID Door Lock | Arduino Nano, Relay, and Solenoid Lock Guide

DIY RFID Door Lock | Arduino Nano, Relay, and Solenoid Lock Guide

Hello and welcome back! In this project, we will learn how to make a simple door lock system using RFID technology. This system is mainly built around the Arduino Nano board. For the locking mechanism, I chose a solenoid door lock, known for its reliability and ease of use. This type of lock is ideal for various door types. Previously, I created a similar system using a servo motor to control the lock, which was a more basic approach. In this project, I added a relay module and a solenoid lock for better performance. To indicate the lock state, I used an LCD screen, which shows whether the door is locked or unlocked. Also, a buzzer and an LED are used as indicators.

Additionally, I’ve included two RFID tags with this project, which you can change as needed. These tags allow you to control who can unlock the door. Whether you want to use it for your front door, office, or personal storage area, this system offers a versatile and secure solution. You can download all the codes and the circuit diagram below. If you’re interested in more door lock system projects, check out the links provided below.

Ok, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify the components.

Step 2

Next, place the Arduino Nano board on the breadboard. Then, position the buzzer and LED on the breadboard, connecting their cathode pins to the ground rail. Additionally, connect a resistor to the anode pin of the LED to limit the current and protect the LED.

Step 3

Thirdly, connect the GND pin of the Arduino Nano board to the ground rail of the breadboard. Next, connect the buzzer and LED to the appropriate pins on the Arduino Nano. You can refer to the circuit diagram below for detailed connections.

  • You can use jumper wires or a jumper kit for the connections.
DIY RFID Door Lock | Arduino Nano, Relay, and Solenoid Lock Guide

Step 4

Next, place the RFID module on the breadboard, then connect it to the Arduino Nano board. Refer to the circuit diagram above for the correct wiring.

Step 5

Afterward, connect the relay module and the LCD I2C module to the Arduino Nano board, following the connections shown in the circuit diagram.

Step 6

Now, connect the solenoid door lock to the relay module. For this connection, I used the NO (Normally Open) terminal on the relay to ensure the lock remains disengaged until activated. Additionally, I used a 12V DC power supply for the lock. Ensure the power is connected only after uploading the program to the Arduino Nano.

Step 7

Okay, now connect the Arduino Nano board to your computer. First, we will scan the RFID tags. To do this, copy and paste the following program into the Arduino IDE. Make sure to include the necessary libraries and setup code provided below.

/*RFID tag scan code
 * https://srituhobby.com
 */
 
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9
#define SS_PIN  10

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  while (!Serial);
  SPI.begin();
  mfrc522.PCD_Init();
  delay(4);
  mfrc522.PCD_DumpVersionToSerial();
  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

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

  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
  • Now, select the appropriate board and port in the Arduino IDE. Once selected, click the upload button to transfer the program to the Arduino Nano board.
  • Next, open the Serial Monitor and bring the RFID tags close to the RFID module. I used two tags for this project, but you can change the number of tags as needed. This means I can access the system using these two tags.
  • Now, copy and paste these RFID tag IDs to a safe place, as we will need to add them to the main code later.

Step 8

Next, copy and paste the main code into the Arduino IDE.

/*Door lock system with Arduino Nano
   
Home Page
*/ #include <SPI.h> #include <MFRC522.h> #include <LiquidCrystal_I2C.h> #define SS_PIN 10 #define RST_PIN 9 #define Buzzer 2 #define LED 3 #define Relay 4 String UID1 = "****************";//Enter your card ID String UID2 = "****************";//Enter your card ID byte lock = 0; MFRC522 rfid(SS_PIN, RST_PIN); LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { Serial.begin(9600); SPI.begin(); rfid.PCD_Init(); lcd.init(); lcd.backlight(); pinMode(Buzzer, OUTPUT); pinMode(LED, OUTPUT); pinMode(Relay, OUTPUT); digitalWrite(Relay, HIGH); } void loop() { lcd.setCursor(4, 0); lcd.print("Welcome!"); lcd.setCursor(1, 1); lcd.print("Put your card"); if ( ! rfid.PICC_IsNewCardPresent()) return; if ( ! rfid.PICC_ReadCardSerial()) return; lcd.clear(); lcd.setCursor(0, 0); lcd.print("Scanning"); //Serial.print("NUID tag is :"); String ID = ""; for (byte i = 0; i < rfid.uid.size; i++) { lcd.print("."); ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ")); ID.concat(String(rfid.uid.uidByte[i], HEX)); delay(300); } ID.toUpperCase(); if (ID.substring(1) == UID1 || ID.substring(1) == UID2 && lock == 0 ) { digitalWrite(Relay, HIGH); digitalWrite(Buzzer, HIGH); digitalWrite(LED, HIGH); delay(300); digitalWrite(Buzzer, LOW); digitalWrite(LED, LOW); //delay(100); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Locked"); delay(1500); lcd.clear(); lock = 1; } else if (ID.substring(1) == UID1 || ID.substring(1) == UID2 && lock == 1 ) { digitalWrite(Buzzer, HIGH); digitalWrite(LED, HIGH); delay(300); digitalWrite(Buzzer, LOW); digitalWrite(LED, LOW); digitalWrite(Relay, LOW); //delay(100); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Unlocked"); delay(1500); lcd.clear(); lock = 0; } else { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Wrong card!"); digitalWrite(Buzzer, HIGH); digitalWrite(LED, HIGH); delay(200); digitalWrite(Buzzer, LOW); digitalWrite(LED, LOW); delay(200); digitalWrite(Buzzer, HIGH); digitalWrite(LED, HIGH); delay(200); digitalWrite(Buzzer, LOW); digitalWrite(LED, LOW); delay(200); digitalWrite(Buzzer, HIGH); digitalWrite(LED, HIGH); delay(200); digitalWrite(Buzzer, LOW); digitalWrite(LED, LOW); delay(200); delay(1500); lcd.clear(); } }
  • Next, include your RFID tag IDs in the main code by pasting them into the appropriate section. Make sure to replace the placeholder IDs in the code with your own to ensure proper functionality.
  • Afterward, select the correct board and port in the Arduino IDE. Then, click the upload button to upload the main code to the Arduino Nano board.

Step 9

Finally, provide a 12V power supply to the solenoid lock. You can now test the system using the RFID tags. Ensure the system is powered up either through a USB cable connected to your computer or a separate 5V DC power supply for the Arduino Nano. Enjoy this project! A full video guide is provided below. We hope to see you in the next project. Have a great day!

Troubleshooting tips

  • Check all connections.
  • Double-check your tag IDs.
  • Include the library file.
  • Select the correct board and port.
  • Provide a stable power supply to this system.
  • Adjust the contract level using the I2C preset.
  • Not showing the COM port, please include the drivers.

DIY RFID Door Lock | Arduino Nano, Relay, and Solenoid Lock Guide

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *