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

This circuit is designed to control a 12V Solenoid Lock using an RFID system for authentication. The core of the system is an Arduino UNO microcontroller, which interfaces with an RFID-RC522 module to read RFID tags. Upon successful authentication, the Arduino activates a relay, which in turn controls the power to the solenoid lock. Additionally, there is a buzzer in the circuit that sounds when an unauthorized RFID tag is detected.

Component List

12V Solenoid Lock

RFID-RC522

Arduino UNO

Relay 4 Channel 5V

Buzzer

12V Power Supply

Wiring Details

12V Solenoid Lock

RFID-RC522

Arduino UNO

Relay 4 Channel 5V

Buzzer

12V Power Supply

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
}

This code is responsible for initializing the RFID reader and the output pins for the relay and buzzer. It continuously checks for new RFID cards, reads their UIDs, and compares them to a predefined authorized UID. If the UID matches, it activates the relay to unlock the solenoid lock for a set period. If the UID does not match, it activates the buzzer to alert of an unauthorized attempt.