Components Required:

  • Arduino Board
  • RFID RC522 Module
  • Servo Motor
  • Magnetic Lock (If to use)
  • LED Kit
  • Buzzer
  • F to F Jumper
  • M to M Jumper
  • Breadboard

Description:

In this tutorial, we will learn how to use the RFID MFRC522. So we can use an RFID system to open a door. For example, only the person with the right information on his card is allowed to enter.

 Quick Points:

Connections: Use RFID and Arduino board and make connections between them.Below I am going to be mention pins.

Procedure:

  •  SDA      –     Digital input 10
  • SCK       –     Digital input 13
  • MOSI    –     Digital input 11
  • MISO    –     Digital input 12
  • Unconnected
  • GND     –      Digital input GND
  • RST      –      Digital input 9
  • 3.3 V    –      Digital input 3.3 v
  • In this example, we have a keychain and an electromagnetic card.Each tag has his own identification.
  • servo motor signal output will be connected to Arduino digital input 3.
  • servomotor VCC output will be connected to the Arduino +5V.
  • Red LED short leg(-) will be connected to the Arduino GND.
  • Red LED long leg (+) will be connected to the Arduino digital input 4.
  • To avoid damaging the LED’S you can use a 220-ohm Resistor.
  • Green LED short leg(-) will be connected to the Arduino GND.
  •  Buzzer short leg(-) will be connected to the Arduino GND.
  • Buzzer long leg(+) will be connected to the digital input 2.
  • Connect Arduino to your Laptop/PC by USB Cable.( we use A to B USB cable for Arduino which is also used in printers )
  • Open Arduino IDE ( You can download it from here you can use online platform Arduino Web editor )
  • Go to File > New type the code given above.Check program, save it and then upload it.

 Circuit Diagram:

 

  • #include <SPI.h>
    #include <MFRC522.h>
    
    #define SS_PIN 10
    #define RST_PIN 9
    MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
    
    void setup()
    {
      Serial.begin(9600);   // Initiate a serial communication
      SPI.begin();      // Initiate  SPI bus
      mfrc522.PCD_Init();   // Initiate MFRC522
      Serial.println("Put your card to the reader...");
      Serial.println();
    
    }
    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) == "XX XX XX XX") //change here the UID of the card/cards that you want to give access
      {
        Serial.println("Authorized access");
        Serial.println();
        delay(3000);
      }
    
     else   {
        Serial.println(" Access denied");
        delay(3000);
      }
    }
    #include <SPI.h>
    #include <MFRC522.h>
    #include <Servo.h>
    
    #define SS_PIN 10
    #define RST_PIN 9
    #define LED_G 5 //define green LED pin
    #define LED_R 4 //define red LED
    #define BUZZER 2 //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
      mfrc522.PCD_Init();   // Initiate MFRC522
      myServo.attach(3); //servo pin
      myServo.write(0); //servo start position
      pinMode(LED_G, OUTPUT);