In this Arduino project, we are interfacing an Arduino with RFID card reader to read the access card to unlock the door which is fitted with a solenoid lock. LCD display module is interfaced with Arduino to display the status and info on it. Previously we built a password based door lock system using Arduino in which user needs to remember the passcode and enter the password by manually touching typing it on the keypad.
But unlike the previous project here we are using contactless RFID cards as access control keys to unlock the door. We just need to hover the card above the RFID scanner to read the card which is completely safe from visual hackers and its contactless. With this project as a reference we can also built attendance system with data storing feature.
Now a days the role of RFID cards in companies increased to record the attendance of the employees and to give the access controls to few important rooms according to their work. These cards does not require line of sight to get detected, so companies print the employee identity info on this same RFID card. Which makes it work like an ID card and Access control card with Attendance logger.
So, without waiting further lets build an RFID based lock system. As a first step lets know what are the components required to build this project and next understand the concept and working of RFID system, then interface the components using schematic diagram and finally upload the code.
Table of Contents
Required components:
Here are the required components along with Amazon buying links at best prices.Product Name | Quantity | ||
---|---|---|---|
Arduino UNO microcontroller | 1 | https://amzn.to/3H4cKxZ | https://amzn.to/3638aTS |
RC522 RFID sensor module | 1 | https://amzn.to/37z8J8Y | https://amzn.to/3rfjP9X |
16x2 LCD display with I2C adapter | 1 | https://amzn.to/3I3Uaax | https://amzn.to/363ki7F |
12v Solenoid lock | 1 | https://amzn.to/3KWFKu2 | https://amzn.to/3wkEjBs |
Relay module 5v | 1 | https://amzn.to/3N5L8gs | https://amzn.to/3wqHmIq |
Tactile Push button | 1 | https://amzn.to/3uc4gRh | https://amzn.to/3ubrLdc |
1k ohm resistor | 1 | https://amzn.to/3hBlqlq | https://amzn.to/3sXBKmI |
Buzzer | 1 | https://amzn.to/3vAHi8L | https://amzn.to/3hQBwaP |
12 volts power supply | 1 | https://amzn.to/3xgaHpA | https://amzn.to/38Dyk0Z |
Few connecting wires | https://amzn.to/3H2BV4e | https://amzn.to/3J0WVu2 |
What is RFID and applications of it?
RFID(Radio Frequency Identification) is an identification system that may seem similar to the traditional barcode, but it has great advantages. Unlike the barcode, which uses the image to identify the code, RFID uses radio waves to communicate with a microchip, which can be mounted on a large number of supports, such as a tags, cards or a transponder.
You may not be aware of it, but in your day to day, you will probably be using a system with RFID technology. When making automatic payments for car parks, highways, metro trains, Supply chain and retail, medical and hospital, animal tracking and tollgate systems, or even when you use an access card you will probably be using radio frequency identification technology or RFID.
These microchips have a large data storage capacity, so they will allow much more information to be stored than traditional barcode labels. Their technology makes them very difficult to duplicate, which increases their security and also allows them to be read almost instantly, from a distance and without the need for line of sight.
Related project: QR Code/Barcode Scanner using Arduino
How RFID Works?
A receiver or reader send continuous radio frequency signals in search of tags to be identified. When a tag is hit by signal, a coupling occurs between tag and the receiver, which allows the data stored in the tag to be received by the reader. This received information is sent to microcontrollers or computers.
RFID tags are passive components which is not connected to any power, when the reader emits electromagnetic signal from the antenna, due to the electromagnetic induction voltage is generated in the tag and receive the signal and communicate the data to the reader
Technical Features of RFID- RC522 reader:
- Operating Current :13-26mA
- Operating voltage: DC 3.3V
- Idle Current :10-13mA / DC 3.3V
- Sleep Current: < 80uA
- Peak Current: < 30mA
- Operating Frequency: 13.56MHz
- Supported card types: mifare1 S50, mifare1 S70 MIFARE Ultralight, mifare Pro, MIFARE DESFire
- Reader Distance: ≥ 50mm / 1.95″ (mifare 1)
- Module interface: SPI
- Data transfer rate: Maximum 10Mbit/s
Circuit Diagram for RFID based door Lock using Arduino
Here we are using Arduino NANO to make the project compact but you can use Arduino UNO with same connections.
Arduino to LCD display connections:
As you can see from the above circuit diagram the 16×2 LCD display module with I2C is powered by connecting 5V and GND of Arduino Nano to VCC and GND of LCD display module. And I2C pins SDA and SCL of LCD display are connected to A4 and A5 respectively.
RFID-RC522 to Arduino Nano connections:
All the connections between RFID reader and Arduino are listed in the below table
RFID Reader–> Arduino Nano
- 3.3v –> 3V3
- RST –> D9
- GND –>GND
- MISO –>D12
- MOSI –>D11
- SCK –>D13
- SDA –>D10
Relay module to Arduino connections:
Relay module is powered by connecting VCC and GND to 5v and GND of Arduino. IN pin of relay is connected to D3 pin of Arduino.
Other connections:
Solenoid lock is connected to 12 volts power supply and in series with the relay module through Normally Open (NO) condition pins.
Positive wire of Buzzer is connected to pin D2 of Arduino and Negative pin to GND.
A tactile push button is connected to pin D6 and 5V of Arduino which is also connected to 1Kohm resistor with Ground as shown in the circuit diagram.
That’s all for connection now its time to code and upload it to Arduino microcontroller.
Program code:
Now connect Arduino Nano to PC where Arduino IDE is installed. Choose the correct port and board as Arduino NANO from Tools menu and install the required libraries from the Library manager of download from the below links and extract them in Arduino Libraries folder.
Required Libraries:
Next copy the below code and paste it in IDE workspace and press upload button. That’s it the code will be uploaded.
//CircuitSchools https://www.circuitschools.com //RFID based Door Lock System using Arduino and Solenoid Lock #include <Wire.h> #include <SPI.h> #include <MFRC522.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); #define SS_PIN 10 #define RST_PIN 9 #define BUZZER 2 //buzzer pin #define lock 3 MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. int Btn = 6; void setup() { Serial.begin(9600); // Initiate a serial communication SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 pinMode(BUZZER, OUTPUT); noTone(BUZZER); pinMode(Btn,INPUT); pinMode(lock,OUTPUT); Serial.println("Place your card on reader..."); Serial.println(); lcd.init(); lcd.backlight(); lcd.clear(); lcd.setCursor(0,0); // column, row lcd.print(" Scan Your RFID "); lcd.setCursor(0,1); // column, row lcd.print(" Door Locked "); } void loop() { if(digitalRead(Btn) == HIGH){ Serial.println("Access Granted"); Serial.println(); delay(500); lcd.setCursor(0,1); // column, row lcd.print(" Door Un-Locked "); tone(BUZZER, 2000); delay(100); noTone(BUZZER); delay(50); tone(BUZZER, 2000); delay(100); noTone(BUZZER); digitalWrite(lock,HIGH); delay(3000); digitalWrite(lock,LOW); delay(100); lcd.setCursor(0,1); // column, row lcd.print(" Door Locked "); tone(BUZZER, 2000); delay(100); noTone(BUZZER); delay(50); } // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor Serial.print("UID tag :"); String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[i], HEX); content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } Serial.println(); Serial.print("Message : "); content.toUpperCase(); if (content.substring(1) == "40 62 5E 7A") //change here the UID of card/cards or tag/tags that you want to give access { Serial.println("Access Granted"); Serial.println(); delay(500); lcd.setCursor(0,1); // column, row lcd.print(" Door Un-Locked "); tone(BUZZER, 2000); delay(100); noTone(BUZZER); delay(50); tone(BUZZER, 2000); delay(100); noTone(BUZZER); digitalWrite(lock,HIGH); delay(3000); digitalWrite(lock,LOW); delay(100); lcd.setCursor(0,1); // column, row lcd.print(" Door Locked "); tone(BUZZER, 2000); delay(100); noTone(BUZZER); delay(50); } else { lcd.setCursor(0,1); // column, row lcd.print("Invalid RFID Tag"); Serial.println(" Access denied"); tone(BUZZER, 1500); delay(500); noTone(BUZZER); delay(100); tone(BUZZER, 1500); delay(500); noTone(BUZZER); delay(100); tone(BUZZER, 1500); delay(500); noTone(BUZZER); lcd.setCursor(0,1); // column, row lcd.print(" Door Locked "); } }
After uploading the code open serial monitor at 9600 baud rate and scan the tag which you want to make it as an Access card, the serial monitor shows the Unique code of the tag, copy it and paste it in the code at line 94 and reupload the code to Arduino. Now LCD display shows output as the below image.
Working of RFID door lock system using Arduino
After uploading the code again, when you place the access card on the reader the solenoid lock opens the lock for 3 seconds, you can change the time from the code by increasing the delay. if you scan an unregistered tag it gives you an error “Invalid RFID tag” on LCD display.
As we added a push button when we press it the door will get unlocked with out putting any tag on reader, if you are implementing this security system to any door you can place it inside the door.
The system status and alerts are displayed on the LCD display module and Buzzer sounds when we use an unauthorized cards.
Important Notes and Troubleshoot guide:
- Push button is used to unlock the lock without tag. So, you can place it inside the door to unlock.
- If you are using 12V battery for Solenoid lock, if battery charge is empty the lock wont gets unlocked until 12 volts is passed through it.
- If the LCD display or relay is not working with PC connected use external 5v power supply using Mobile charger or adapter.
- Instead of Solenoid lock you can also use a servo motor using Arduino connected to some manual locks but sometimes if the hardware may get jammed.
Video Tutorial:
Coming soon
If you like this project please subscribe to our YouTube Channel “Circuit Schools“ to encourage us to publish more interesting projects. If you have any doubts write to us from below comment section.