Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

RFID-Controlled Solenoid Door Lock with Arduino and Buzzer Alert

View and Edit Project In Cirkit DesignerImage of RFID-Controlled Solenoid Door Lock with Arduino and Buzzer Alert

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a 12V solenoid lock using an Arduino UNO microcontroller in conjunction with an RFID-RC522 reader. When an authorized RFID card is presented to the reader, the Arduino activates a relay, which in turn powers the solenoid lock, unlocking it for a predetermined amount of time. Additionally, the circuit includes a buzzer that is activated when an unauthorized card is detected.

Component List

12V Solenoid Lock

RFID-RC522

Arduino UNO

Buzzer

12V Power Supply

Relay 4 Channel 5V

Wiring Details

12V Solenoid Lock

RFID-RC522

Arduino UNO

Buzzer

12V Power Supply

Relay 4 Channel 5V

Documented Code

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

#define SS_PIN 10     // Slave Select pin for RFID
#define RST_PIN 9     // Reset pin for RFID
#define RELAY_PIN 7   // Relay control pin for the lock
#define BUZZER_PIN 6  // Buzzer pin

MFRC522 rfid(SS_PIN, RST_PIN); // Create an instance of the RFID module

// Predefined authorized card ID (replace this with your actual RFID card UID)
byte authorizedUID[] = {0xDE, 0xAD, 0xBE, 0xEF}; // Update with actual UID of your card

void setup() {
  Serial.begin(9600);        // Initialize serial communication
  SPI.begin();               // Start SPI bus
  rfid.PCD_Init();           // Initialize RFID reader

  pinMode(RELAY_PIN, OUTPUT);  // Set relay pin as output
  pinMode(BUZZER_PIN, OUTPUT); // Set buzzer pin as output

  digitalWrite(RELAY_PIN, LOW);  // Start with the lock closed (relay off)
  digitalWrite(BUZZER_PIN, LOW); // Buzzer off initially

  Serial.println("Place your card on the reader...");
}

void loop() {
  // Look for new RFID cards
  if (!rfid.PICC_IsNewCardPresent()) {
    return;
  }

  // Select the RFID card
  if (!rfid.PICC_ReadCardSerial()) {
    return;
  }

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

  // Compare the read UID with the authorized UID
  if (checkUID()) {
    // Authorized card
    Serial.println("Authorized card. Unlocking the door...");
    digitalWrite(RELAY_PIN, HIGH);  // Unlock (relay on)
    delay(5000);                    // Keep the door unlocked for 5 seconds
    digitalWrite(RELAY_PIN, LOW);   // Lock the door (relay off)
  } else {
    // Unauthorized card
    Serial.println("Unauthorized card. Buzzing...");
    digitalWrite(BUZZER_PIN, HIGH); // Buzz (buzzer on)
    delay(3000);                    // Buzz for 3 seconds
    digitalWrite(BUZZER_PIN, LOW);  // Turn off the buzzer
  }

  rfid.PICC_HaltA(); // Halt RFID reader
}

// Function to check if the scanned UID matches the authorized UID
bool checkUID() {
  if (rfid.uid.size != sizeof(authorizedUID)) {
    return false;  // UID sizes don't match
  }
  
  for (byte i = 0; i < rfid.uid.size; i++) {
    if (rfid.uid.uidByte[i] != authorizedUID[i]) {
      return false;  // UID bytes don't match
    }
  }
  
  return true;  // All bytes match, card is authorized
}

Note: The code provided is for the Arduino UNO microcontroller. It initializes the RFID reader and sets up the relay and buzzer pins. When an RFID card is presented, it checks if the UID matches the authorized UID and either unlocks the door (activates the relay) or sounds the buzzer if unauthorized. The relay and buzzer are controlled using digital pins D3 and D2, respectively. The RFID-RC522 module is interfaced with the Arduino using the SPI protocol with pin assignments as defined in the code.