Welcome to our DIY RFID Door Lock with Arduino tutorial! In this video, we'll guide you through the process of building your own RFID-based door lock system for added security to your home or workspace. With just a few components and some basic coding, you can create a reliable access control system.
Circuit:-
coding
//TECHNO SAP //RFID Door Lock System #include <Wire.h> #include <SPI.h> #include <MFRC522.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x3F, 16, 2); #define SS_PIN 10 #define RST_PIN 9 #define LED_G 4 //define green LED pin #define LED_R 5 //define red LED #define BUZZER 2 //buzzer pin #define lock 3 #define MOTOR_FORWARD 7 // L298N motor driver control pins #define MOTOR_BACKWARD 8 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(LED_G, OUTPUT); pinMode(LED_R, OUTPUT); pinMode(BUZZER, OUTPUT); pinMode(MOTOR_FORWARD, OUTPUT); // Motor control pins pinMode(MOTOR_BACKWARD, OUTPUT); digitalWrite(MOTOR_FORWARD, LOW); // Motor off initially digitalWrite(MOTOR_BACKWARD, LOW); noTone(BUZZER); pinMode(Btn,INPUT); pinMode(lock,OUTPUT); Serial.println("Place your card on reader..."); Serial.println(); lcd.init(); // Initialize the LCD object 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){ openDoor(); } // Look for new cards if ( ! mfrc522.PICC_IsNewCardfhdhPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCdfdgardSerial()) { return; } //Show UID on serial monitor Serial.print("UID tag :"); String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { 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) == "C2 79 EE 1B") //change here the UID of card/cards or tag/tags that you want to give access { openDoor(); } else { lcd.setCursor(0,1); // column, row lcd.print("Invalid RFID Tag"); Serial.println(" Access denied"); digitalWrite(LED_R, HIGH); tone(BUZZER, 1500); delay(500); digitalWrite(LED_R, LOW); noTone(BUZZER); delay(100); digitalWrite(LED_R, HIGH); delay(100); digitalWrite(LED_R, HIGH); tone(BUZZER, 1500); delay(500); digitalWrite(LED_R, LOW); noTone(BUZZER); lcd.setCursor(0,1); // column, row lcd.print(" Door Locked "); } }