How dariiats/esp32-security-system works
Purpose and Entry Point
This is ESP32 firmware for a local smart-security system: PIR motion detection triggers Bluetooth user notification; a user can request or ignore an alarm; an authorized RFID card is required to deactivate an active alarm. The firmware entry point is src/main.cpp, built and uploaded through the PlatformIO project defined by platformio.ini.
Embedded Runtime and Hardware Boundary
The system runs on an ESP32 DevKit and directly controls GPIO-connected PIR, LEDs, and buzzer/alarm circuitry. It communicates with the RFID reader over I²C. Hardware-specific initialization and the continuous device event loop are expected to be centralized in src/main.cpp; the application has no stated Wi‑Fi, cloud, server, or persistent-backend dependency.
Paths:
• src/main.cpp
• platformio.ini
Motion Detection Stage
The PIR sensor is the initiating event source. Motion causes the firmware to evaluate the detected activity and notify the connected Bluetooth client, rather than immediately relying solely on physical alarm output. This establishes a control boundary between physical sensor input and user-directed alarm decisions.
Paths:
• src/main.cpp
Bluetooth Command Control
ESP32 Bluetooth provides the human-control channel, exposing the device as ESP32Security for an Android serial-Bluetooth terminal. The intended command flow is: motion notification → user sends alarm or ignore → firmware changes alarm behavior. Bluetooth is therefore both an outbound notification transport and an inbound command interface.
Paths:
• src/main.cpp
Alarm Actuation and State
The active alarm is represented through visual LEDs and an audio buzzer driven from the ESP32. Alarm activation can be requested remotely; ignoring a motion event suppresses/escalation handling. Deactivation is deliberately gated by RFID authorization, creating a security boundary: Bluetooth commands manage the response decision, while RFID identity authorizes alarm shutdown.
Paths:
• src/main.cpp
RFID Authentication
RFID card reads are handled through the bundled MFRC522 I²C driver. The application compares a presented card’s UID with an authorized UID configured in firmware; only a match may deactivate an active alarm. The local library owns reader-level I²C/register communication, while application policy and authorization belong in the main firmware.
Paths:
• lib/MFRC522_I2C/MFRC522_I2C.h
• lib/MFRC522_I2C/MFRC522_I2C.cpp
• src/main.cpp
Dependency and Build Boundary
The project vendors its RFID dependency rather than requiring external installation. MFRC522_I2C integrates with the ESP32’s I²C/Wire stack and includes a standalone Arduino usage example, while the root firmware remains the deployable security application. PlatformIO is the material build/upload infrastructure.
Paths:
• lib/MFRC522_I2C/library.properties
• lib/MFRC522_I2C/examples/mfrc522_i2c/MFRC522_i2c.ino
• platformio.ini
Main entry points: MFRC522_I2C.cpp MFRC522 I²C driver · main.cpp Security application loop · MFRC522_I2C.h MFRC522 driver API · library.properties Library package metadata
Components 16
ESP32 Device
- ESP32 DevKit
- PIR sensor
- LEDs and buzzer
- MFRC522 reader
- ESP32 Wire/I²C stack
Security Firmware
- Security application loop · Owns hardware initialization, event handling, and security policy.
src/main.cpp - Motion evaluation
src/main.cpp - Bluetooth notification and commands · Exposes ESP32Security and accepts alarm or ignore commands.
src/main.cpp - Alarm state control · Remote activation is allowed; shutdown requires RFID authorization.
src/main.cpp - UID authorization · Compares presented card UID with the firmware-authorized UID.
src/main.cpp
RFID Dependency
- MFRC522 I²C driver · Owns reader I²C and register communication.
lib/MFRC522_I2C/MFRC522_I2C.cpp - MFRC522 driver API
lib/MFRC522_I2C/MFRC522_I2C.h - Library package metadata
lib/MFRC522_I2C/library.properties - Standalone RFID example
lib/MFRC522_I2C/examples/mfrc522_i2c/MFRC522_i2c.ino
Other components
- PlatformIO build/upload
platformio.ini - Android Bluetooth client
Connections 16
- PlatformIO build/upload → Security application loop: builds and uploads
- Security application loop → ESP32 DevKit: runs on
- PIR sensor → Motion evaluation: motion signal
- Security application loop → Motion evaluation: handles
- Motion evaluation → Bluetooth notification and commands: notifies
- Android Bluetooth client → Bluetooth notification and commands: alarm / ignore commands
- Bluetooth notification and commands → Alarm state control: response decision
- Alarm state control → LEDs and buzzer: drives
- MFRC522 reader → MFRC522 I²C driver: card communication
- MFRC522 I²C driver → ESP32 Wire/I²C stack: uses I²C
- MFRC522 driver API → MFRC522 I²C driver: declares
- Security application loop → MFRC522 driver API: reads cards through
- MFRC522 I²C driver → UID authorization: card UID
- UID authorization → Alarm state control: authorizes deactivation
- Library package metadata → MFRC522 I²C driver: packages
- Standalone RFID example → MFRC522 driver API: demonstrates