Arduino Door Lock Using MFRC522 RFID Reader - DIY Door Lock - RFID Door Lock - Servo Motor Door Lock
by Mechatronics Workshop in Circuits > Arduino
25 Views, 0 Favorites, 0 Comments
Arduino Door Lock Using MFRC522 RFID Reader - DIY Door Lock - RFID Door Lock - Servo Motor Door Lock

In this tutorial, we will be building a simple door lock using an Arduino and an MFRC522 RFID reader. The lock will be activated by a specific RFID tag, and will unlock the door when the tag is presented to the reader.
Supplies

Materials needed:
- Arduino board (e.g. Arduino Uno)
- MFRC522 RFID reader
- RFID tags
- Servo motor
- Jumper wires
- Breadboard
- 9V battery
- Door latch (e.g. a deadbolt)
Connect the MFRC522 RFID Reader

First, let's connect the MFRC522 RFID reader to the Arduino. Follow the wiring diagram below to connect the reader to the Arduino:
Connect the Servo Motor

Next, let's connect the servo motor to the Arduino. The servo motor will be used to turn the door latch and unlock the door. Follow the wiring diagram below to connect the servo motor to the Arduino:
Upload the Sketch to the Arduino

Now that the hardware is set up, let's move on to the software. First, you will need to download the MFRC522 library from the Arduino library manager.
Then, copy and paste the following sketch into the Arduino IDE:
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600); // Initialize serial communications
SPI.begin(); // Initialize SPI bus
mfrc522.PCD_Init(); // Initialize MFRC522
myservo.attach(3); // attaches the servo on pin 3 to the servo object
myservo.write(0); // sets the servo position according to the angle
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Print the UID of the card
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.