This circuit is designed to control a door locking system using RFID technology. It features an Arduino UNO microcontroller interfaced with an RFID-RC522 module to read RFID tags. The system grants or denies access based on the tag presented. A green LED indicates authorized access, while a red LED and a buzzer signal unauthorized access. The system also includes a relay to control a magnetic lock, which secures the door. A 5V adapter powers the Arduino, and a separate 12V power supply operates the relay and magnetic lock. The system has an alarm feature that activates after multiple failed access attempts and can lock down for a specified duration as a security measure.
3.3V
connected to RFID-RC522 VCC (3.3V)GND
connected to 5V Adapter GND, RFID-RC522 GND, green LED anode, red LED anode, and buzzer GNDVin
connected to 5V Adapter 5VD13
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 PINRST
not connectedIRQ
not connectedcathode
connected to Arduino UNO D4anode
connected to Arduino UNO GNDcathode
connected to Arduino UNO D5anode
connected to Arduino UNO GNDPIN
connected to Arduino UNO D2GND
connected to Arduino UNO GNDAC In 1
and AC In 2
not connected5V
connected to Arduino UNO VinGND
connected to Arduino UNO GNDS
connected to 12V power supply +GND
connected to 12V Relay NONO
connected to Magnetic Lock GNDCOM
connected to 12V power supply -NC
not connectedDC+
connected to 12V power supply +DC-
connected to 12V power supply -IN
connected to Arduino UNO D3+
connected to 12V Relay DC+ and Magnetic Lock S-
connected to 12V Relay COM and DC-/*
* Ce sketch Arduino contrôle un système de verrouillage de porte utilisant RFID.
* Le système lit les tags RFID et déverrouille la porte si le tag est autorisé.
* Un buzzer émet des sons différents pour les tags acceptés et rejetés.
* Deux exemples de tags RFID sont utilisés pour le contrôle d'accès.
* Après 5 tentatives d'échecs, une alarme se déclenche pendant 1 minute.
* Si après l'alarme, il y a encore 3 tentatives échouées, le système se bloque pendant 1 heure.
*/
#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
#define MAX_ATTEMPTS 5
#define ADDITIONAL_ATTEMPTS 3
#define ALARM_DURATION 60000 // 1 minute in milliseconds
#define LOCK_DURATION 3600000 // 1 hour in milliseconds
MFRC522 mfrc522(SS_PIN, RST_PIN);
// Exemples de tags RFID autorisés
byte authorizedUIDs[][4] = {
{0xDE, 0xAD, 0xBE, 0xEF},
{0xCA, 0xFE, 0xBA, 0xBE}
};
const int numAuthorizedUIDs = sizeof(authorizedUIDs) / sizeof(authorizedUIDs[0]);
int failedAttempts = 0;
int additionalFailedAttempts = 0;
bool isLocked = false;
unsigned long lockStartTime = 0;
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); // Assurez-vous que le relais est éteint initialement
}
void loop() {
if (isLocked) {
if (millis() - lockStartTime >= LOCK_DURATION) {
isLocked = false;
additionalFailedAttempts = 0;
} else {
return; // Le système est bloqué
}
}
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
return;
}
if (isAuthorized(mfrc522.uid.uidByte, mfrc522.uid.size)) {
grantAccess();
failedAttempts = 0; // Reset failed attempts on successful access
additionalFailedAttempts = 0; // Reset additional failed attempts
} else {
denyAccess();
failedAttempts++;
if (failedAttempts >= MAX_ATTEMPTS) {
triggerAlarm();
failedAttempts = 0; // Reset failed attempts after alarm
additionalFailedAttempts++;
if (additionalFailedAttempts >= ADDITIONAL_ATTEMPTS) {
lockSystem();
}
}
}
mfrc522.PICC_HaltA();
}
bool isAuthorized(byte *uid, byte uidSize) {
if (uidSize != 4) return false;
for (int i = 0; i < numAuthorizedUIDs; i++) {
if (memcmp(uid, authorizedUIDs[i], 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); // Bip court pour tag accepté
delay(5000); // Garder la porte déverrouillée pendant 5 secondes
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); // Bip long pour tag rejeté
delay(1000);
digitalWrite(RED_LED_PIN, LOW);
}
void triggerAlarm() {
unsigned long startTime = millis();
while (millis() - startTime < ALARM_DURATION) {
tone(BUZZER_PIN, 2000); // Alarme sonore
digitalWrite(RED_LED_PIN, HIGH); // LED rouge allumée
delay(500);
noTone(BUZZER_PIN);
digitalWrite(RED_LED_PIN, LOW);
delay(500);
}
}
void lockSystem() {
isLocked = true;
lockStartTime = millis();
Serial.println("Système bloqué pendant 1 heure en raison de tentatives d'accès échouées.");
}
This code is responsible for controlling the RFID door lock system. It initializes the RFID reader and sets up the pins for the LEDs, relay, and buzzer. The main loop checks for new RFID cards, verifies if they are authorized, and then grants or denies access accordingly. It also handles the alarm and system lock features based on the number of failed attempts.