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

Arduino UNO RFID Door Lock System with Buzzer and LED Indicators

View and Edit Project In Cirkit DesignerImage of Arduino UNO RFID Door Lock System with Buzzer and LED Indicators

Circuit Documentation

Summary

This document provides a detailed overview of a door lock system controlled by an Arduino UNO using an RFID reader. The system reads RFID tags and unlocks the door if the tag is authorized. It also includes visual and auditory feedback using LEDs and a buzzer. The components used in this circuit include an Arduino UNO, an RFID reader, LEDs, a buzzer, a relay, a magnetic lock, and a 12V power supply.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0, Power
  2. LED: Two Pin (green)

    • Description: A green LED with two pins.
    • Pins: cathode, anode
  3. LED: Two Pin (red)

    • Description: A red LED with two pins.
    • Pins: cathode, anode
  4. Buzzer

    • Description: A simple buzzer for sound output.
    • Pins: PIN, GND
  5. Magnetic Lock

    • Description: An electromagnetic lock for securing the door.
    • Pins: S, GND
  6. 12V Power Supply

    • Description: A power supply providing 12V.
    • Pins: +, -
  7. NFC/RFID Reader PN532

    • Description: An RFID reader module for reading RFID tags.
    • Pins: GND, VCC, SDA, SCL, SCK, MISO, MOSI, SS, IRQ, RSTO
  8. 1 Channel Relay 5V

    • Description: A relay module for switching the magnetic lock.
    • Pins: VCC, GND, IN, NC, COM, NO

Wiring Details

Arduino UNO

LED: Two Pin (green)

LED: Two Pin (red)

Buzzer

Magnetic Lock

12V Power Supply

NFC/RFID Reader PN532

1 Channel Relay 5V

Code Documentation

/*
 * Door Lock System
 * This Arduino Sketch controls a door lock system using RFID.
 * The system reads RFID tags and unlocks the door if the tag is authorized.
 * A buzzer sounds differently for accepted and rejected tags.
 * Two example RFID tags are used for access control.
 */

#include <SPI.h>
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

#define RED_LED_PIN 5
#define GREEN_LED_PIN 4
#define RELAY_PIN 2
#define BUZZER_PIN 3

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc(pn532_i2c);

// Example authorized RFID tag UIDs
byte authorizedUID1[] = {0xDE, 0xAD, 0xBE, 0xEF};
byte authorizedUID2[] = {0xCA, 0xFE, 0xBA, 0xBE};

void setup() {
  Serial.begin(9600);
  nfc.begin();
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW); // Ensure the relay is off initially
}

void loop() {
  if (nfc.tagPresent()) {
    NfcTag tag = nfc.read();
    if (isAuthorized(tag.getUid(), tag.getUidLength())) {
      grantAccess();
    } else {
      denyAccess();
    }
  }
}

bool isAuthorized(byte *uid, byte uidSize) {
  if (uidSize != 4) return false;
  if (memcmp(uid, authorizedUID1, 4) == 0) return true;
  if (memcmp(uid, authorizedUID2, 4) == 0) return true;
  return false;
}

void grantAccess() {
  digitalWrite(GREEN_LED_PIN, HIGH);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(RELAY_PIN, HIGH);
  tone(BUZZER_PIN, 1000, 200); // Short beep for accepted tag
  delay(5000); // Keep the door unlocked for 5 seconds
  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(GREEN_LED_PIN, LOW);
}

void denyAccess() {
  digitalWrite(RED_LED_PIN, HIGH);
  digitalWrite(GREEN_LED_PIN, LOW);
  tone(BUZZER_PIN, 500, 1000); // Long beep for rejected tag
  delay(1000);
  digitalWrite(RED_LED_PIN, LOW);
}

This code initializes the RFID reader and sets up the pins for the LEDs, relay, and buzzer. It continuously checks for the presence of an RFID tag and grants or denies access based on the tag's UID. The system provides visual feedback using LEDs and auditory feedback using a buzzer.