Monday, July 21, 2025

RFID DOOR JASKIRAT

 

1. RC522 RFID Reader to Arduino Uno:

RC522 PinArduino Uno PinDescription
SDAD10Slave Select (SS) for SPI
SCKD13SPI Clock
MOSID11SPI Master Out
MISOD12SPI Master In
IRQNot connectedInterrupt (not used here)
GNDGNDGround
RSTD9Reset Pin
3.3V3.3VPower Supply

🛑 Note: RC522 works on 3.3V, do not connect to 5V.


📌 2. Servo Motor to Arduino Uno:

Servo WireArduino Uno PinDescription
SignalD3PWM control signal
VCC5VPower
GNDGNDGround



CODE:   


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

#define SS_PIN 10     // SDA pin of RC522
#define RST_PIN 9     // RST pin of RC522
#define SERVO_PIN 3   // Servo control pin

MFRC522 rfid(SS_PIN, RST_PIN);  // Create MFRC522 instance
Servo myServo;

// ✅ Your RFID UID
byte authorizedUID[4] = {0xE0, 0x2A, 0x0D, 0x18};

void setup() {
  Serial.begin(9600);
  SPI.begin();          // Init SPI bus
  rfid.PCD_Init();      // Init MFRC522
  myServo.attach(SERVO_PIN);
  myServo.write(0);     // Initial lock position
  Serial.println("RFID Door Lock System Initialized.");
}

void loop() {
  // Check for new RFID card
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;

  Serial.print("Scanned UID: ");
  for (byte i = 0; i < rfid.uid.size; i++) {
    Serial.print(rfid.uid.uidByte[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  if (isAuthorized(rfid.uid.uidByte)) {
    Serial.println("✅ Access Granted!");
    myServo.write(120);     // Unlock
    delay(3000);           // Keep unlocked for 3 seconds
    myServo.write(0);      // Lock again
  } else {
    Serial.println("❌ Access Denied!");
    // Optional: Add buzzer or red LED here
  }

  rfid.PICC_HaltA();       // Halt PICC
  rfid.PCD_StopCrypto1();  // Stop encryption
}

bool isAuthorized(byte *uid) {
  for (byte i = 0; i < 4; i++) {
    if (uid[i] != authorizedUID[i]) return false;
  }
  return true;
}

No comments:

Post a Comment

MUD Three Mode operation Manual Automatic GPS

 Code for three mode operation: /*   3-Mode Headlight Controller   - Manual mode (driver uses a toggle to pick high/low)   - Auto mode (LDR...