Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
120 min
Share

Make a RFID Lock System With Servo Using Arduino

Have you ever seen a smart lock in which you have to put the card on the reader to get access? Well, with Arduino, we can create our own smart lock using an RFID lock system that requires a unique card to perform a specific action. In our case, we will use it to open a door with a servo motor.

Project Video

Overview

In this tutorial, we will make an RFID lock system that opens a door when a unique card is used with the device, and we will use a servo motor to open and close that door.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
2×16 LCD with I2C Module
Get Item
SG90 Servo -Positional Rotation
Get Item
RFID Kit
Get Item
1/4 Watt Resistor (20 Pack)
Get Item
LED Kit – (4 colors, 5 pieces each)
Get Item
Active Buzzer - 5V
Get Item
Half-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the RFID module and the Arduino and the servo and the buzzer  as shown in the image below.

 

 

Connections from the Arduino to the breadboard:

 

  • Arduino GND pin →Breadboard ground line

 

  • Arduino 5V pin →Breadboard 5V line

 

 

Connections fromthe RFID reader to the Arduino:

 

  • RFID 3.3V pin →Arduino VCC (3.3V) pin

 

 • RFID RST pin →Arduino pin 9

 

 • RFID GND pin →Breadboard ground line

 

  • RFID IRQ pin →unconnected

 

  • RFID MISO pin →Arduino pin 12

 

  • RFID MOSI pin →Arduino pin 11

 

  • RFID SCK pin →Arduino pin 13

 

  • RFID SDA pin →Arduino pin 10

 

 

 

Connections fromthe servo motor:

 

  • Servo GND pin→breadboard GND line

 

  • Servo 5V pin→breadboard 5V line

 

  • Servo signal pin→ Arduino pin 3

 

 

 

Connections fromthe passive buzzer :

 

  • passive buzzerGND pin → Breadboard ground line

 

  • passive buzzerVCC pin (+ pin) → Arduino pin 6

 

 

 

Connections fromthe Green LED :

 

  • Green LED anodepin → Arduino pin 5

 

  • Green LED cathodepin → 330 ohm resistor first pin → Breadboard ground line

 

 

Connections fromthe Red LED :

 

  • Red LED anode pin→ Arduino pin 7

 

  • Red LED cathodepin → 330 ohm resistor first pin → Breadboard ground line

 

 

Coding

/*

 Voltaat learn (http://learn.voltaat.com)

 Link for full tutorial:

 RFID reader library: https://learn.voltaat.com/wp-content/uploads/2023/04/rfid-master.zip

 Tutorial: RFID Lock System With Servo Using Arduino

 The purpose of this sketch is to open and close a door with a servo motor

 when a unique card is brought near the RFID module.

 

 Connections from the Arduino to the breadboard:

 • Arduino GND pin → Breadboard ground line

 

 • Arduino 5V pin → Breadboard 5V line

 

 

 Connections from the RFID reader to the Arduino:

 

 

 • RFID 3.3V pin → Arduino VCC (3.3V) pin

 

 • RFID RST pin → Arduino pin 9

 

 • RFID GND pin → Breadboard ground line

 

 • RFID IRQ pin → unconnected

 

 • RFID MISO pin → Arduino pin 12

 

 • RFID MOSI pin → Arduino pin 11

 

 • RFID SCK pin → Arduino pin 13

 

 • RFID SDA pin → Arduino pin 10

 

 

 

 Connections from the servo motor:

 

 • Servo GND pin→ breadboard GND line

 

 • Servo 5V pin→ breadboard 5V line

 

 • Servo signal pin → Arduino pin 3

 

 

 

 Connections from the passive buzzer :

 

 • passive buzzer GND pin → Breadboard ground line

 

 • passive buzzer VCC pin (+ pin) → Arduino pin 6

 

 

 

 Connections from the Green LED :

 

 • Green LED anode pin → Arduino pin 5

 

 • Green LED cathode pin → 330 ohm resistor first pin → Breadboard ground line

 

 

 Connections from the Red LED :

 

 • Red LED anode pin → Arduino pin 7

 

 • Red LED cathode pin → 330 ohm resistor first pin → Breadboard ground line

 

*/

// MFRC522 Library  

// https://github.com/miguelbalboa/rfid  

#include "SPI.h"  

#include "MFRC522.h"  

#include "Servo.h"  

#include "Wire.h"  

#include "LiquidCrystal_I2C.h" 

LiquidCrystal_I2C lcd(0x27,16,2);  

Servo s1;  

#define SS_PIN 10  

#define RST_PIN 9  

#define LED_G 5  //define green LED pin  

#define LED_R 7  //define red LED  

#define BUZZER 6 //buzzer pin  

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.  

//Servo myServo; //define servo name  

void setup()  

{  

 Serial.begin(9600);  // Initiate a serial communication  

 SPI.begin();     // Initiate SPI bus  

  lcd.init();            

 lcd.backlight();  

;  

 mfrc522.PCD_Init();  // Initiate MFRC522  

 s1.attach(3); //servo pin  

 // myServo.write(0); //servo start position  

 pinMode(LED_G, OUTPUT);  

 pinMode(LED_R, OUTPUT);  

 pinMode(BUZZER, OUTPUT);  

 noTone(BUZZER);  

 Serial.println("Put your card to the reader...");  

 Serial.println();  

 lcd.setCursor(0,0);  

 lcd.print(" Put your card   ");  

}  

void loop()  

{  

 // 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) == "10 A6 DC 51") //change here the UID of the card/cards that you want to give access  

 {  

  Serial.println("Authorized access");  

  Serial.println();  

    lcd.setCursor(0,0);  

    lcd.print(" CARD IS VALID      ");  

    lcd.setCursor(0,1);  

    lcd.print("Opening the Door   ");  

    digitalWrite(LED_G, HIGH); //Green LED ON  

    s1.write(0);  

    delay(3000);  

    s1.write(90);  

    lcd.setCursor(0,1);  

    lcd.print("closing the Door   ");  

    digitalWrite(LED_G, LOW);  //Green LED OFF  

    delay(2000);  

    lcd.setCursor(0,0);  

    lcd.print(" Put your card   ");  

    lcd.setCursor(0,1);  

    lcd.print("                ");  

 }  

 else  

 {  

  Serial.println("CARD IS INVALID");  

   lcd.setCursor(0,1);  

   lcd.print("CARD IS INVALID   ");  

   digitalWrite(LED_R, HIGH);   // Red LED ON  

   tone(BUZZER, 300);       // Buzzer ON  

   delay(2000);  

   digitalWrite(LED_R, LOW);  

   noTone(BUZZER);  

   lcd.setCursor(0,1);  

   lcd.print("               ");  

 }  

}

Testing it Out

Once you’ve uploaded the code to the Arduino board, you will find that the servo will rotate to open the door when a unique card is brought near the RFID module, then the door will close automatically after a delay of three seconds.

Resources

No items found.