Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino Mega 2560 RFID Access Control System with Solenoid Locks and Inductive Sensors

Image of Arduino Mega 2560 RFID Access Control System with Solenoid Locks and Inductive Sensors

Circuit Documentation

Summary

This circuit is designed to control access using RFID cards, solenoids, and an inductive sensor. The system includes an Arduino Mega 2560 microcontroller, RFID readers, solenoids, inductive sensors, relays, a buzzer, and an LCD display. The circuit allows authorized access through RFID cards and monitors the door status using inductive sensors. Unauthorized access triggers an alarm.

Component List

  1. Arduino Mega 2560

    • Description: Microcontroller board based on the ATmega2560.
    • Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0-A15, D0-D53, AREF, SDA, SCL.
  2. RFID-RC522

    • Description: RFID reader module.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA.
  3. Solenoid

    • Description: Electromechanical device for locking/unlocking.
    • Pins: pin1, pin2.
  4. Inductive Sensor

    • Description: Proximity sensor to detect metal objects.
    • Pins: Signal, VCC, GND.
  5. 1-Channel Relay (5V 10A)

    • Description: Relay module for switching high power devices.
    • Pins: NC, signal, C, power, NO, ground.
  6. Buzzer

    • Description: Audio signaling device.
    • Pins: PIN, GND.
  7. 12V Power Supply

    • Description: Power supply module.
    • Pins: +, -.
  8. LCD I2C

    • Description: LCD display with I2C interface.
    • Pins: GND, VCC, SDA, SCL.

Wiring Details

Arduino Mega 2560

  • 5V: Connected to:

    • 1-Channel Relay (5V 10A) power pin
    • Inductive Sensor VCC pin
    • LCD I2C VCC pin
  • 3V3: Connected to:

    • RFID-RC522 VCC (3.3V) pin
  • VIN: Connected to:

    • 1-Channel Relay (5V 10A) power pin
    • 12V Power Supply + pin
  • GND: Connected to:

    • 1-Channel Relay (5V 10A) ground pin
    • Buzzer GND pin
    • RFID-RC522 GND pin
    • LCD I2C GND pin
    • Inductive Sensor GND pin
  • D4 PWM: Connected to:

    • Inductive Sensor Signal pin
  • D5 PWM: Connected to:

    • Inductive Sensor Signal pin
  • D6 PWM: Connected to:

    • 1-Channel Relay (5V 10A) signal pin
  • D7 PWM: Connected to:

    • 1-Channel Relay (5V 10A) signal pin
  • D8 PWM: Connected to:

    • Buzzer PIN
  • D9 PWM: Connected to:

    • RFID-RC522 RST pin
  • D20/SDA: Connected to:

    • LCD I2C SDA pin
  • D21/SCL: Connected to:

    • LCD I2C SCL pin
  • D50: Connected to:

    • RFID-RC522 MISO pin
  • D51: Connected to:

    • RFID-RC522 MOSI pin
  • D52: Connected to:

    • RFID-RC522 SCK pin
  • D53: Connected to:

    • RFID-RC522 SDA pin

RFID-RC522

  • VCC (3.3V): Connected to:

    • Arduino Mega 2560 3V3 pin
  • RST: Connected to:

    • Arduino Mega 2560 D9 PWM pin
  • GND: Connected to:

    • Arduino Mega 2560 GND pin
  • MISO: Connected to:

    • Arduino Mega 2560 D50 pin
  • MOSI: Connected to:

    • Arduino Mega 2560 D51 pin
  • SCK: Connected to:

    • Arduino Mega 2560 D52 pin
  • SDA: Connected to:

    • Arduino Mega 2560 D53 pin

Solenoid

  • pin1: Connected to:

    • 12V Power Supply - pin
  • pin2: Connected to:

    • 1-Channel Relay (5V 10A) C pin

Inductive Sensor

  • Signal: Connected to:

    • Arduino Mega 2560 D4 PWM pin
    • Arduino Mega 2560 D5 PWM pin
  • VCC: Connected to:

    • Arduino Mega 2560 5V pin
  • GND: Connected to:

    • Arduino Mega 2560 GND pin

1-Channel Relay (5V 10A)

  • NC: Connected to:

    • 12V Power Supply + pin
  • signal: Connected to:

    • Arduino Mega 2560 D6 PWM pin
    • Arduino Mega 2560 D7 PWM pin
  • C: Connected to:

    • Solenoid pin2
  • power: Connected to:

    • Arduino Mega 2560 5V pin
  • ground: Connected to:

    • Arduino Mega 2560 GND pin

Buzzer

  • PIN: Connected to:

    • Arduino Mega 2560 D8 PWM pin
  • GND: Connected to:

    • Arduino Mega 2560 GND pin

12V Power Supply

  • +: Connected to:

    • 1-Channel Relay (5V 10A) NC pin
  • -: Connected to:

    • Solenoid pin1

LCD I2C

  • GND: Connected to:

    • Arduino Mega 2560 GND pin
  • VCC: Connected to:

    • Arduino Mega 2560 5V pin
  • SDA: Connected to:

    • Arduino Mega 2560 D20/SDA pin
  • SCL: Connected to:

    • Arduino Mega 2560 D21/SCL pin

Documented Code

Arduino Mega 2560 Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>

// Pin Definitions
#define RST_PIN 9
#define SS_PIN 53
#define BUZZER_PIN 8
#define SOLENOID1_PIN 7
#define SOLENOID2_PIN 6
#define PROX_SENSOR1_PIN 5
#define PROX_SENSOR2_PIN 4

// RFID Master and Teacher Cards
#define MASTER_CARD_1 "BD9DCD2C" //VALLE
#define MASTER_CARD_2 "7D61D02C" //IGNACIO
#define MASTER_CARD_3 "" //CARDENAS CDB2CF7A
#define TEACHER_CARD_1 "5B83A70D" //RFID TAG
#define TEACHER_CARD_2 "2333911B" //RFID CARD

// Initialize LCD with I2C
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Initialize RFID Reader
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Global variables
long countdownTime = 180 * 60;  // 180 minutes in seconds
bool doorOpen = false;

void setup() {
  // Initialize Serial communication
  Serial.begin(9600);

  // Initialize LCD
  lcd.init();
  lcd.backlight();

  // Initialize RFID
  SPI.begin();
  mfrc522.PCD_Init();

  // Initialize pins
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(SOLENOID1_PIN, OUTPUT);
  pinMode(SOLENOID2_PIN, OUTPUT);
  pinMode(PROX_SENSOR1_PIN, INPUT);
  pinMode(PROX_SENSOR2_PIN, INPUT);

  // Initial state
  closeSolenoids();
  updateLCD("  Tap card here  ");
}

void loop() {
  // Check for forced door open
  if ((!digitalRead(PROX_SENSOR1_PIN) && !digitalRead(PROX_SENSOR2_PIN)) && !doorOpen) {
    unauthorizedAccess();
  }

  // Check for RFID card presence
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    String cardUID = "";
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      cardUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
      cardUID += String(mfrc522.uid.uidByte[i], HEX);
    }
    cardUID.toUpperCase();

    if (cardUID == MASTER_CARD_1 || MASTER_CARD_2 || MASTER_CARD_3) {
      openSolenoidsUnlimited();
    } else if (cardUID == TEACHER_CARD_1 || TEACHER_CARD_2) {
      openSolenoidsWithTimer();
    } else {
      unauthorizedAccess();
    }

    mfrc522