

This circuit is designed to control a door lock system using RFID technology. It features an Arduino UNO microcontroller interfaced with an RFID-RC522 module to read RFID tags. The system unlocks a magnetic lock if an authorized RFID tag is presented. Visual feedback is provided through a green LED for access granted and a red LED for access denied. An audible alert is given by a buzzer, with different tones indicating accepted or rejected tags. The circuit is powered by a 5V adapter, and a 12V power supply is used to control the magnetic lock through a 12V relay.
3.3V connected to RFID-RC522 VCC (3.3V)GND connected to common ground netVin connected to 5V Adapter 5V outputD13 connected to RFID-RC522 SCKD12 connected to RFID-RC522 MISOD11 connected to RFID-RC522 MOSID10 connected to RFID-RC522 SDAD5 connected to red LED cathodeD4 connected to green LED cathodeD3 connected to 12V Relay IND2 connected to buzzer PINVCC (3.3V) connected to Arduino UNO 3.3VGND connected to common ground netSCK connected to Arduino UNO D13MISO connected to Arduino UNO D12MOSI connected to Arduino UNO D11SDA connected to Arduino UNO D10anode connected to common ground netcathode connected to Arduino UNO D4anode connected to common ground netcathode connected to Arduino UNO D5PIN connected to Arduino UNO D2GND connected to common ground net5V connected to Arduino UNO VinGND connected to common ground netS connected to 12V Relay DC+GND connected to 12V Relay NOIN connected to Arduino UNO D3DC+ connected to Magnetic Lock S and 12V Power Supply +DC- connected to 12V Power Supply -NO connected to Magnetic Lock GND+ connected to 12V Relay DC+- connected to 12V Relay DC-/*
* 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 <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
#define RED_LED_PIN 5
#define GREEN_LED_PIN 4
#define RELAY_PIN 3
#define BUZZER_PIN 2
MFRC522 mfrc522(SS_PIN, RST_PIN);
// Example authorized RFID tag UIDs
byte authorizedUID1[] = {0xDE, 0xAD, 0xBE, 0xEF};
byte authorizedUID2[] = {0xCA, 0xFE, 0xBA, 0xBE};
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
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 (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
return;
}
if (isAuthorized(mfrc522.uid.uidByte, mfrc522.uid.size)) {
grantAccess();
} else {
denyAccess();
}
mfrc522.PICC_HaltA();
}
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 is responsible for initializing the RFID reader and setting up the pins for the LEDs, relay, and buzzer. It continuously checks for new RFID cards, compares the UID of the card with authorized UIDs, and then either grants or denies access accordingly. The relay is activated to unlock the door for authorized access, and the LEDs and buzzer provide the corresponding visual and audible feedback.