.jpeg&w=3840&q=75)
Get full C++ & Python code + lifetime access
The ESP32 RFID Smart Security & Intrusion Alert System demonstrates an end-to-end access control and IoT telemetry application combining high-frequency RFID scanning, dual-state physical feedback, and automated cloud dispatch over encrypted HTTPS.
In this project, an ESP32 microcontroller interfaces with an MFRC522 13.56 MHz RFID reader over the Serial Peripheral Interface (SPI) bus and an I2C 16x2 character display. When a user presents a badge or key fob, the ESP32 captures and sanitizes its Unique Identifier (UID). If an authorized key is matched, the system triggers a welcome audio chime and illuminates a green confirmation LED. If an unauthorized badge or intruder card is detected, the firmware executes a zero-latency local alarm sequence (strobe red LED and 4-pulse buzzer warning) before dispatching an encrypted push alert directly to your smartphone through the Telegram Bot API.
This project introduces:
MFRC522.h)LiquidCrystal_I2C.h)millis() TimersWiFiClientSecure & HTTPClient)By completing this project, you will understand how to interface complex SPI and I2C peripherals simultaneously, handle credential logic, and deploy cloud notification pipelines without relying on paid third-party brokers.
ESP32 DevKit V1 (30-Pin) × 1
RC522 13.56 MHz RFID Reader Module × 1
Mifare Classic 1K RFID Card / Key Fob × 2
16x2 Character LCD with I2C Backpack (PCF8574) × 1
5V Active Piezo Buzzer × 1
5mm Green LED × 1
5mm Red LED × 1
220Ω Resistors × 2
Half-Size or Full-Size Breadboard × 1
Male-to-Male & Male-to-Female Jumper Wires × 1 Set
Micro-USB or Type-C Cable × 1
Design Note: The RC522 reader is strictly a 3.3V logic device. Connecting its power rail to 5V will permanently destroy its internal receiver circuitry. Tie all grounds together on a shared breadboard power rail to avoid floating reference voltages.
Connect the RFID module to the ESP32 primary hardware SPI bus:
3.3V (VCC) → ESP32 3V3 (Strict: 3.3V only)RST → ESP32 GPIO 4 (D4)GND → Breadboard GND RailMISO → ESP32 GPIO 19 (D19)MOSI → ESP32 GPIO 23 (D23)SCK → ESP32 GPIO 18 (D18)SDA (SS) → ESP32 GPIO 5 (D5)IRQ → Leave UnconnectedConnect the four pins of the I2C LCD backpack to the hardware I2C lines:
GND → Breadboard GND RailVCC → ESP32 VIN (5V rail required for clear liquid crystal contrast)SDA → ESP32 GPIO 21 (D21)SCL → ESP32 GPIO 22 (D22)Connect the visual indicators and the active buzzer:
GPIO 15 (D15)GPIO 2 (D2)GPIO 13 (D13)Inside setup(), the ESP32 flushes its stored flash network settings, initiates Station Mode (WIFI_STA), and disables modem sleep via WiFi.setSleep(false) to prevent packet drops. In loop(), network retries are throttled to 10-second intervals using non-blocking millis() tracking. This prevents CPU core panics and stops wifi:sta is connecting, return error driver loops.
The main loop continuously queries the RC522 using PICC_IsNewCardPresent() and PICC_ReadCardSerial(). When an RFID transponder enters the 13.56 MHz electromagnetic field, the firmware iterates through the module's byte array, converts the raw binary values into a two-digit uppercase hexadecimal string, and halts the card to prepare for the next read cycle.
Traditional cloud devices often freeze while waiting for an HTTPS response. To eliminate physical lag, handleUnauthorized() drives the hardware first:
RED_LED HIGH immediately.! WARNING ! Access Denied on the LCD.Once the local alarm cycle executes, sendTelegramAlert() constructs an encrypted outbound socket using WiFiClientSecure with client.setInsecure(). The string payload is passed through an onboard urlEncode() helper function, and an HTTPS GET request hits the Telegram Bot API endpoint:
$$\text{Endpoint} = \text{api.telegram.org/bot}\langle\text{Token}\rangle/\text{sendMessage}$$
This delivers an instant Markdown notification containing the unauthorized UID, lock status, and incident timestamp directly to your Telegram chat.
After uploading the firmware and opening the Serial Monitor at 115200 baud:
Connecting WiFi while the ESP32 associates with your 2.4 GHz network.Security System / Tap ID Card... and the Serial Monitor prints the assigned local IP address.1A4E12B0): The green LED lights up, a pleasant two-tone welcome chime sounds, and the screen confirms >> WELCOME! << Access Granted for 2.5 seconds before returning to idle.! WARNING ! Access Denied, and your smartphone immediately receives an encrypted Telegram notification with the scanned UID.LCD Backlight On But No Characters Visible: Turn the small contrast potentiometer on the back of the I2C backpack using a small flathead screwdriver until the letters become sharp. Ensure the LCD VCC pin is wired to VIN (5V), not 3.3V.
RFID Module Fails to Detect Tags: Verify that the RC522 is wired to the exact hardware SPI pins (SCK: 18, MISO: 19, MOSI: 23, SDA: 5, RST: 4). Ensure your solder joints on the RC522 pin header are solid and not bridging adjacent pins.
Wi-Fi Times Out on Hotspot: Ensure your hotspot is configured strictly to 2.4 GHz (ESP32 cannot communicate with 5 GHz channels). If connecting through a mobile phone hotspot fails due to Protected Management Frame (PMF) negotiation, share your laptop's connection using the Windows 11 2.4 GHz Mobile Hotspot.
Buzzer Clicks Instead of Beeping: If using a passive buzzer, driving the pin HIGH only produces a dull click because it lacks an internal oscillator. Use an active buzzer (continuous sound when given 3.3V/5V DC) or implement PWM frequency modulation using the ESP32 ledcWrite() API.
By completing this project, you have learned: