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

Arduino UNO Based RFID Access Control with Environmental Monitoring

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based RFID Access Control with Environmental Monitoring

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with various peripherals including an RFID-RC522 module, an I2C LCD 16x2 screen, a 4-channel 5V relay module, a PIR motion sensor, an MQ-135 air quality sensor, a 12V white LED strip, a 12V solenoid lock, a 12V power supply, a 40mm 12V fan, and a green button. The Arduino UNO serves as the central processing unit, controlling the peripherals based on sensor inputs and RFID card detection. The circuit is powered by both the Arduino's onboard voltage regulators and an external 12V power supply.

Component List

Wiring Details

Arduino UNO

RFID-RC522

I2C LCD 16x2 Screen

Relay 4 Channel 5V

PIR Motion Sensor (Wokwi Compatible)

MQ-135 SENSOR AIR QUALITY

12V White LED strip

12V Solenoid Lock

12V Power Supply

40mm Fan 12V

Green Button

Documented Code

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

// Define pins for RFID
#define SS_PIN 10
#define RST_PIN 9
#define Lock 7
#define Button 2

// Define pins for PIR sensor and LED
#define LED 3
#define PIR 5

// Define pins for air quality sensor and fan
#define airsensor A1 
#define FAN 6

// Air quality threshold
const int AIR_QUALITY_THRESHOLD = 100;

// Initialize the LCD with I2C address 0x27, 16 columns, and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2); 

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.

void setup() {
  // Setup for RFID
  pinMode(Button, INPUT);
  pinMode(Lock, OUTPUT); 
  Serial.begin(9600);    // Initiate serial communication
  SPI.begin();           // Initiate SPI bus
  mfrc522.PCD_Init();    // Initiate MFRC522
  
  // Setup for PIR sensor and LED
  pinMode(LED, OUTPUT);  // Declare LED as output
  pinMode(PIR, INPUT);   // Declare PIR sensor as input

  // Setup for air quality sensor and fan
  pinMode(airsensor, INPUT);
  pinMode(FAN, OUTPUT); 
  
  // Setup for LCD
  lcd.init();            // Initialize the I2C LCD
  lcd.backlight();       // Turn on the LCD backlight
  lcd.setCursor(0, 0);   // Set the cursor to the first row, first column
  lcd.print("System Ready");  // Display the initial message
  delay(2000);           // Wait 2 seconds to display this message
  lcd.clear();           // Clear the LCD screen
  
  unsigned long previousMillis = 0;
  const long interval = 500; // interval at which to read sensors
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    // Call functions to handle RFID, PIR, and Air Quality
    handleRFID();
    handlePIR();
    handleAirQuality();
  }
}

void handleRFID() {
  lcd.setCursor(0, 0);   // Set the cursor to the first row

  // ************ RFID Section ************
  Serial.println("Loop started");

  // Check button state
  int buttonState = digitalRead(Button);
  Serial.print("Button state: ");
  Serial.println(buttonState);

  // Look for new RFID cards
  if (!mfrc522.PICC_IsNewCardPresent()) {
    Serial.println("No new card present");
    updateLCD(0, 0, "No Card Present");
  } else {
    if (!mfrc522.PICC_ReadCardSerial()) {
      Serial.println("Failed to read card serial");
      updateLCD(0, 0, "