Version: 2.0
Platform: ESP32 DevKit V1 (30-Pin)
Architecture: Component-Based Modular Design
Framework: PlatformIO (Arduino)
- Overview
- Features
- Hardware Requirements
- Quick Start
- Architecture
- API Documentation
- Web Dashboard
- Development
- Deployment
- Troubleshooting
- License
SecureLock is a production-grade IoT security system built on ESP32 with a glassmorphism web dashboard. It combines multi-factor authentication (RFID + PIN), real-time Telegram alerts, and a responsive web interface for complete access control and user management.
- Multi-Factor Authentication: RFID RC522 + 4x4 Matrix Keypad
- Duress Code: Silent alarm (9999) for emergency situations
- Tamper Detection: Vibration sensor + Reed switch monitoring
- Web Dashboard: Real-time control via glassmorphism UI
- User Management: Add, edit, and delete users via web interface with RFID enrollment
- Telegram Notifications: Instant security alerts (intrusion, tamper, duress)
- Guest Access: Temporary 5-minute PIN codes
- Auto-Lock: 5-second timer after unlock
- β Multi-factor authentication (RFID + PIN)
- β Duress code detection (9999 = silent alarm)
- β Vibration-based intrusion detection (SW-420)
- β Door tamper detection (reed switch)
- β Real-time Telegram security alerts
- β Activity logging with timestamps
- β Factory reset (BOOT button held 10s)
- β Responsive glassmorphism dark-theme design
- β Real-time lock status polling (3s interval)
- β Emergency override with confirmation modal
- β Guest code generation (5-minute expiry)
- β Activity logs viewer (table format)
- β Full user management (CRUD + RFID enrollment)
- β Component-based modular architecture (4 libraries)
- β Fully non-blocking (millis-based, async web server)
- β RESTful API (9 endpoints with CORS support)
- β LittleFS filesystem for web assets and data
- β NVS persistence for user credentials
- β Low memory footprint (~35% RAM)
| Component | Model | GPIO | Purpose |
|---|---|---|---|
| Microcontroller | ESP32 DevKit V1 | - | Main controller |
| Solenoid Lock | 12V DC | 4 (Relay) | Physical lock |
| RFID Reader | RC522 | SPI (5, 21) | Card authentication |
| Keypad | 4x4 Matrix | 32-36, 39 | PIN entry |
| Vibration Sensor | SW-420 | 27 | Intrusion detection |
| Reed Switch | - | 13 | Door open/close |
| Active Buzzer | - | 14 | Audio feedback |
| Status LED | Onboard | 2 | Visual indicator |
GPIO 4 β Relay Module (Solenoid Lock) - Active HIGH = Unlocked
GPIO 2 β Onboard LED (Status Indicator)
GPIO 14 β Active Buzzer (Audio Feedback)
GPIO 27 β SW-420 Vibration Sensor (Intrusion Detection)
GPIO 13 β Reed Switch (Door Open/Close) - INPUT_PULLUP
RFID RC522 (SPI):
SS = GPIO 5
SCK = GPIO 18
MOSI = GPIO 23
MISO = GPIO 19
RST = GPIO 21
Keypad 4x4 Matrix:
Rows = GPIO 32, 33, 25, 26
Columns = GPIO 34, 35, 36, 39
Factory Reset:
GPIO 0 (BOOT button) - Hold 10 seconds
# Install PlatformIO
pip install platformio
# Verify ESP32 connection
pio device listEdit include/secrets.h:
#define WIFI_SSID "YourWiFiNetwork"
#define WIFI_PASSWORD "YourWiFiPassword"
#define BOT_TOKEN "1234567890:ABCdefGHI..." // From @BotFather
#define ADMIN_CHAT_ID "123456789" // From @userinfobotpio run --target uploadfspio run --target uploadpio device monitorOpen browser: http://[ESP32_IP]/
SecureLock v2.0
β
βββ LockManager [Hardware Control Layer]
β βββ Relay (GPIO 4) β Solenoid lock, active HIGH
β βββ LED (GPIO 2) β Onboard status indicator
β βββ Reed Switch (GPIO 13) β Door open/close detection
β
βββ SecurityManager [Sensor & Alarm Layer]
β βββ Vibration Sensor (GPIO 27) β SW-420 intrusion detection
β βββ Active Buzzer (GPIO 14) β Feedback patterns (beep, siren)
β
βββ AuthHandler [Authentication Layer]
β βββ RFID RC522 (SPI) β Card-based authentication
β βββ 4x4 Matrix Keypad β PIN entry
β βββ Duress Detection β Code 9999 triggers silent alarm
β βββ NVS User Storage β Persistent user credentials
β
βββ WebServer [Network Layer]
βββ WiFi Manager β Auto-connect with status reporting
βββ LittleFS File Server β Serves HTML/CSS/JS/JSON
βββ RESTful API β 9 endpoints with CORS support
βββ Activity Logging β Writes events to logs.json
SecureLock/
βββ data/ # Web Dashboard (uploaded to LittleFS)
β βββ html/index.html # Dashboard UI
β βββ css/style.css # Glassmorphism theme
β βββ js/script.js # Frontend controller (API client)
β βββ users.json # User data store
β βββ logs.json # Activity log store
β
βββ lib/ # Component Libraries
β βββ LockManager/ # Relay, LED, reed switch control
β βββ SecurityManager/ # Vibration sensor, buzzer patterns
β βββ AuthHandler/ # RFID, keypad, duress, NVS users
β βββ WebServer/ # Async HTTP server, API routes
β
βββ src/
β βββ main.cpp # Orchestrator + Telegram integration
β
βββ include/
β βββ secrets.h # WiFi & Telegram credentials (gitignored)
β βββ secrets.h.example # Credential template for setup
β
βββ .github/
β βββ copilot-instructions.md # AI agent guidance
β
βββ platformio.ini # Build configuration & dependencies
βββ build.ps1 # PowerShell build helper script
βββ README.md
All endpoints return JSON and include CORS headers for cross-origin access.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/status |
Real-time system status |
POST |
/api/unlock |
Emergency door unlock |
POST |
/api/guest-code |
Generate temporary PIN |
GET |
/api/users |
List registered users |
POST |
/api/users |
Add new user (with RFID + PIN) |
PUT |
/api/users |
Edit existing user |
DELETE |
/api/users?uid=XX |
Remove user |
GET |
/api/logs |
Retrieve activity logs |
GET |
/api/rfid/scan |
Poll RFID reader for card tap |
Returns real-time system status including lock state, sensor readings, and network info.
{
"locked": true,
"doorOpen": false,
"tampered": false,
"alarm": false,
"vibration": false,
"uptime": 12345,
"freeHeap": 234567,
"wifiConnected": true,
"ipAddress": "192.168.1.100",
"rssi": -45
}Triggers emergency door unlock (5-second auto-lock timer).
{
"success": true,
"message": "Emergency unlock activated",
"timestamp": 123456789
}Generates a temporary 4-digit PIN valid for 5 minutes.
{
"success": true,
"code": "4821",
"expiresIn": 300,
"timestamp": 123456789
}Lists all registered users from users.json.
{
"users": [
{ "uid": "DEADBEEF", "name": "Admin", "type": "admin" }
]
}Add a new user. Requires JSON body with name, pin, and uid fields. Persists to NVS and users.json.
Request Body:
{
"name": "John Doe",
"pin": "1234",
"uid": "AABBCCDD"
}Response:
{
"success": true,
"message": "User added successfully"
}Edit an existing user. Requires JSON body with uid (identifier) plus fields to update (name, pin, newUid).
Request Body:
{
"uid": "AABBCCDD",
"name": "Jane Doe",
"pin": "5678",
"newUid": "11223344"
}Response:
{
"success": true,
"message": "User updated successfully"
}Remove a user by UID. Admin user cannot be deleted.
{
"success": true,
"message": "User deleted successfully"
}Retrieve activity logs from logs.json.
{
"logs": [
{ "time": "12:30:00", "user": "Admin", "method": "RFID", "status": "granted" }
]
}Poll the RFID reader for a newly scanned card. Used by the web dashboard during user enrollment.
{
"scanned": true,
"uid": "AABBCCDD"
}If no card detected:
{
"scanned": false
}The web dashboard is a single-page application served from LittleFS with a glassmorphism dark theme.
- Lock Status β Animated lock visual with real-time state (locked/unlocked)
- Emergency Override β One-click unlock with confirmation modal
- Guest Access β Generate temporary 4-digit codes with countdown timer
- Activity Logs β Table view of recent access events
- User Management β Add, edit, delete users with live RFID card enrollment
Browser (JavaScript) β REST API Calls β WebServer Component β Hardware Components
β β
Poll /api/status (3s) Query LockManager/SecurityManager
β β
Update UI elements Return JSON with real-time data
# Clean build (removes .pio cache)
.\build.ps1
# Manual compile
pio run
# Upload filesystem only
pio run --target uploadfs
# Upload firmware only
pio run --target upload
# Complete deployment
pio run --target uploadfs && pio run --target upload && pio device monitorFrontend Changes (HTML/CSS/JS):
- Edit files in
data/folder pio run --target uploadfs- Refresh browser (Ctrl+F5)
Backend Changes (C++ code):
- Edit files in
src/orlib/ pio run --target upload- ESP32 auto-restarts
Each component follows this pattern:
class ComponentName {
public:
void init(); // Setup hardware
void update(); // Non-blocking loop function
private:
// State variables
// Private helper methods
};- Update
secrets.hwith real credentials - Test all hardware components
- Verify WiFi connectivity
- Test Telegram bot alerts
- Test emergency override
- Test duress code (9999)
- Verify guest code expiry
- Test door tamper detection
- Test vibration sensor
- Check activity logging
-
Network Security:
- Use WPA2/WPA3 WiFi encryption
- Keep ESP32 on isolated VLAN
- Do NOT expose to public internet without VPN
-
Credentials:
- Never commit
secrets.hto git - Use strong WiFi passwords
- Rotate Telegram bot token periodically
- Never commit
-
Physical Security:
- Mount ESP32 in tamper-proof enclosure
- Secure relay module from physical access
- Position sensors strategically
"LittleFS.h not found"
- Verify
platformio.inihasplatform = espressif32 - Run:
pio lib install
Library conflicts
# Clean build
Remove-Item .pio -Recurse -Force
pio runWiFi not connecting
- Check
secrets.hcredentials - Verify 2.4GHz network (ESP32 doesn't support 5GHz)
- Monitor serial output:
pio device monitor
Dashboard not loading
- Upload filesystem first:
pio run --target uploadfs - Check serial for "[FS] Mounting LittleFS... β OK"
- Verify files exist with
ls data/
Sensors not responding
- Verify GPIO connections match pin map
- Check component
.init()called in setup() - Monitor serial for sensor readings
Telegram not working
- Verify
BOT_TOKENandADMIN_CHAT_ID - Test token:
https://api.telegram.org/bot<TOKEN>/getMe - Check WiFi connection
| Issue | Solution |
|---|---|
| Upload fails | Close serial monitor, press BOOT button |
| Door won't unlock | Check relay wiring, verify GPIO 4 |
| RFID not reading | Check SPI connections, verify SS=5 |
| Keypad not working | Verify row/col GPIOs, check wiring |
This is an academic project for IoT coursework. If you fork this project:
- Maintain component-based architecture
- Follow existing code style
- Add tests for new features
- Update documentation
MIT License
Copyright (c) 2026 SecureLock Team - IoT Group 7
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Internet of Things - Group 7
- Hardware Design: ESP32 DevKit V1 integration
- Backend Development: C++ component architecture
- Frontend Development: Glassmorphism web dashboard
- Security Implementation: Multi-factor auth + Telegram alerts
Technologies Used:
- PlatformIO (ESP32 Framework)
- ESPAsyncWebServer (Non-blocking HTTP)
- ArduinoJson (JSON serialization)
- LittleFS (Filesystem)
- UniversalTelegramBot (Notifications)
- MFRC522 (RFID reader)
- Keypad (Matrix keypad library)
For issues, questions, or contributions:
- Check Troubleshooting section above
- Review API Documentation for endpoint details
- Open an issue on the GitHub repository
Made with π by IoT Group 7 | ESP32 Smart Security System | 2026