Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Access control systems are essential in various environments, from securing homes to managing entry points in commercial buildings. With the flexibility and affordability of Arduino, creating a custom access control system becomes accessible to hobbyists and professionals alike. This article will guide you through building an Arduino-based access control system, highlighting its importance in enhancing security and demonstrating how to implement it effectively.
Project: The project involves creating an access control system using an Arduino board, RFID reader, and a relay module to control a door lock. The system will read RFID tags, verify them against a list of authorized tags, and activate the relay to unlock the door if the tag is valid. The objective is to provide a secure and user-friendly method to control access to a restricted area.
Components List:
Examples:
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define RELAY_PIN 8
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(9600); // Initialize serial communications
SPI.begin(); // Initialize SPI bus
mfrc522.PCD_Init(); // Initialize MFRC522
pinMode(RELAY_PIN, OUTPUT); // Set relay pin as output
digitalWrite(RELAY_PIN, LOW); // Ensure relay is off
Serial.println("Access Control System Initialized");
}
void loop() {
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
return;
}
// Read the card UID
String uid = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
uid += String(mfrc522.uid.uidByte[i], HEX);
}
uid.toUpperCase();
Serial.println("Card UID: " + uid);
// Check if the UID is authorized
if (isAuthorized(uid)) {
Serial.println("Access Granted");
digitalWrite(RELAY_PIN, HIGH); // Activate relay to unlock door
delay(5000); // Keep the door unlocked for 5 seconds
digitalWrite(RELAY_PIN, LOW); // Deactivate relay to lock door
} else {
Serial.println("Access Denied");
}
// Halt PICC
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
bool isAuthorized(String uid) {
// List of authorized UIDs
String authorizedUids[] = {"UID1", "UID2", "UID3"};
for (String authorizedUid : authorizedUids) {
if (uid == authorizedUid) {
return true;
}
}
return false;
}
Explanation:
Libraries and Pin Definitions:
#include <SPI.h>
and #include <MFRC522.h>
: Include necessary libraries for SPI communication and RFID functionality.Setup Function:
Loop Function:
Authorization Function: