ESP32 RFID Machine Access Control System Comprehensive Documentation & Hardware Integration Guide | The V Dimension Project Overview: This document details the architectural design, circuit pinout, software implementation, procedure, and real-world industrial applications of an RFID-based Machine Access Control System built with the ESP32 Microcontroller , MFRC522 RFID Module , I2C LCD 16x2 , Servo Motor , and audio-visual alert systems. 1. SYSTEM COMPONENTS & HARDWARE REQUIREMENTS 2. CIRCUIT WIRING & PIN MAPPING Below is the pin connection schematic mapping components to the ESP32 microcontroller pins: RC522 RFID Module (SPI) SDA (SS): GPIO 5 SCK: GPIO 18 MOSI: GPIO 23 MISO: GPIO 19 GND: GND RST: GPIO 22 3.3V: 3.3V (Strictly 3.3V) Peripherals (I2C, Servo, Alerts) LCD SDA: GPIO 21 LCD SCL: GPIO 22 (Shared / Configured) Servo Signal: GPIO 13 Buzzer Positive: GPIO 12 Green LED: GPIO 2 Red LED: GPIO 4 LCD VCC & Servo VCC: 5V (VIN) COMPONENT QUANTITY FUNCTION / DESCRIPTION ESP32 Microcontroller 1 Main process controller running access authorization logic and SPI/I2C protocols. RC522 RFID Reader Module 1 Reads 13.56 MHz RFID tags / cards via SPI communication interface. LCD Display (16x2 with I2C Backpack) 1 Displays system status messages ("SCAN RFID TAG", "ACCESS GRANTED", "ACCESS DENIED"). Servo Motor (SG90 / MG996R) 1 Acts as the physical gate/machine lock actuator (rotates 0° to 90° upon authorization). Buzzer 1 Provides audible alarm alerts upon unauthorized card scans. LED Indicators (Green & Red) 2 Visual status indication: Green LED for Access Granted, Red LED for Access Denied. Resistors (220Ω) & Jumper Wires As needed Current limiting for LEDs and interconnecting components on breadboard. The V Dimension — ESP32 RFID Control System Page 1 of 4 3. REQUIRED ARDUINO LIBRARIES Ensure the following libraries are installed in the Arduino IDE or Wokwi simulator before uploading code: MFRC522 Library (by githubuser / miguelbalboa) — For interfacing with RC522 RFID reader. LiquidCrystal_I2C Library (by Frank de Brabander) — For controlling the 16x2 I2C display. ESP32Servo Library (by Kevin Harrington / John Plocher) — For PWM servo motor control on ESP32. SPI Wire Libraries (Built-in to ESP32 Arduino Core) — For hardware SPI/I2C communication. 4. SYSTEM OPERATING PROCEDURE & WORKFLOW System Initialization: Upon power-up, ESP32 initializes SPI bus, I2C LCD, and attaches the Servo Motor to locked position (0°). LCD displays: FACTORY ACCESS: SCAN RFID TAG Card Scanning: Operator places an RFID card/keyfob near the RC522 reader. The module reads the 4-byte or 7-byte Unique Identifier (UID). Verification Logic: ESP32 checks the scanned UID against stored authorized UID arrays. Authorized Tag Access Granted: Servo turns 90° (Unlocks Gate), Green LED turns ON, Buzzer stays OFF, LCD displays ACCESS GRANTED! GATE UNLOCKED . After 3 seconds, servo returns to 0° (Locked). Unauthorized / Fake Tag Access Denied: Red LED flashes, Buzzer sounds continuous alert tone, Servo stays at 0° (Locked), LCD displays ACCESS DENIED! UNAUTHORIZED! 5. INDUSTRIAL & REAL-WORLD USE CASES Industrial Machine Authorization: Prevents unauthorized operators from turning on hazardous machinery (e.g., CNC machines, laser cutters, heavy presses) without proper clearance. Secure Factory Zone Entry: Controls turnstiles, electro-magnetic doors, or boom barriers in high-security manufacturing areas. Shift Change Attendance Logging: Can be integrated with cloud database (Firebase / MQTT) to automatically log employee working hours, shift start times, and operator identity. 6. COMPLETE SOURCE CODE (C++) Below is the fully tested and functional source code ready for deployment on ESP32 / Wokwi Simulator: #include <SPI.h> #include <MFRC522.h> #include <LiquidCrystal_I2C.h> #include <ESP32Servo.h> // Pin Definitions #define SS_PIN 5 #define RST_PIN 22 #define SERVO_PIN 13 #define BUZZER 12 #define RED_LED 4 #define GREEN_LED 2 // Object Instances MFRC522 rfid(SS_PIN, RST_PIN); • • • • 1. 2. 3. ◦ ◦ • • • The V Dimension — ESP32 RFID Control System Page 2 of 4 LiquidCrystal_I2C lcd(0x27, 16, 2); Servo gateServo; // Authorized RFID Card UID (Replace with your tag's UID) byte authorizedUID[4] = {0xAA, 0xBB, 0xCC, 0xDD}; void setup() { Serial.begin(115200); SPI.begin(); rfid.PCD_Init(); lcd.init(); lcd.backlight(); gateServo.attach(SERVO_PIN); gateServo.write(0); // Locked position pinMode(BUZZER, OUTPUT); pinMode(RED_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT); digitalWrite(BUZZER, LOW); digitalWrite(RED_LED, LOW); digitalWrite(GREEN_LED, LOW); displayIdleScreen(); } void loop() { // Look for new RFID cards if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) { return; } boolean isAuthorized = true; for (byte i = 0; i < 4; i++) { if (rfid.uid.uidByte[i] != authorizedUID[i]) { isAuthorized = false; break; } } if (isAuthorized) { grantAccess(); } else { denyAccess(); } rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); } void displayIdleScreen() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("FACTORY ACCESS"); lcd.setCursor(0, 1); lcd.print("SCAN RFID TAG"); } void grantAccess() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("ACCESS GRANTED!"); lcd.setCursor(0, 1); lcd.print("GATE UNLOCKED"); The V Dimension — ESP32 RFID Control System Page 3 of 4 digitalWrite(GREEN_LED, HIGH); gateServo.write(90); // Unlock gate delay(3000); // Hold open for 3 seconds gateServo.write(0); // Lock gate digitalWrite(GREEN_LED, LOW); displayIdleScreen(); } void denyAccess() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("ACCESS DENIED!"); lcd.setCursor(0, 1); lcd.print("UNAUTHORIZED!"); digitalWrite(RED_LED, HIGH); digitalWrite(BUZZER, HIGH); delay(2000); digitalWrite(RED_LED, LOW); digitalWrite(BUZZER, LOW); displayIdleScreen(); } The V Dimension — ESP32 RFID Control System Page 4 of 4