Muhammad_Munir
Published © GPL3+

Open a Door Lock with a Ring

How to Open a Door Lock with a Ring

BeginnerFull instructions provided2 hours290
Open a Door Lock with a Ring

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
RFID Reader
×1
Motor Driver L298n
×1
Jumper wires (generic)
Jumper wires (generic)
×1
2s Battery Holder
×1
3.7v Batteries
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code

Arduino
#define lockPin A0
#define unlockPin A1

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
int x = 1;
void setup()
{
  pinMode(lockPin, OUTPUT);
  pinMode(unlockPin, OUTPUT);
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate 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) == "C1 BA 3E 19") || (content.substring(1) == "63 78 52 2E")) //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    if (x == 1)
    {
      x=0;
      Serial.println("if statement execute");
      digitalWrite(lockPin, HIGH);
      delay(500);
      digitalWrite(lockPin, LOW);
      
      
    }
    else if (x == 0)
    {
      x=1;
      Serial.println("else if statement execute");
      digitalWrite(unlockPin, HIGH);
      delay(500);
      digitalWrite(unlockPin, LOW);
      
    }
  }

  else   {
    Serial.println(" Access denied");
    delay(3000);
  }
}

Credits

Muhammad_Munir

Muhammad_Munir

77 projects • 48 followers
I am Arduino programmer, also expertise in ESP32 and 8266 wifi modules.

Comments