An intelligent ESP32-based security system with AI-powered analysis, real-time dashboard, and comprehensive monitoring.
|
|
graph TB
A[ESP32 Hardware] --> B[Backend API]
B --> C[AI Analysis Engine]
B --> D[Web Dashboard]
C --> E[Gemini AI]
D --> F[Real-time Updates]
subgraph "Hardware Layer"
A1[RFID Reader]
A2[Motion Sensor]
A3[Servo Lock]
A4[LCD Display]
end
subgraph "Software Layer"
B1[FastAPI Backend]
B2[Vector Database]
B3[AI Processing]
end
subgraph "User Interface"
D1[Security Dashboard]
D2[Event Logs]
D3[AI Chat Interface]
end
A --> A1
A --> A2
A --> A3
A --> A4
B --> B1
B --> B2
B --> B3
D --> D1
D --> D2
D --> D3
git clone https://github.com/SH-Nihil-Mukkesh-25/Vaultify.git
cd Vaultify# Install Python dependencies
pip install fastapi uvicorn langchain langchain-google-genai python-dotenv requests
# Set up environment variables
echo "GEMINI_API_KEY=your_gemini_api_key_here" > .env
# Start the backend
python backend.py# Open the dashboard
start frontend.html
# Or navigate to: http://localhost:8000// Update hardware_code.ino with your credentials
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
const String BACKEND_URL = "http://YOUR_COMPUTER_IP:8000";| Component | Quantity | Purpose |
|---|---|---|
| ESP32 DevKit | 1x | Main Controller |
| MPU6050 | 1x | Motion Detection |
| MFRC522 RFID | 1x | Access Control |
| 16x2 I2C LCD | 1x | Status Display |
| SG90 Servo | 1x | Lock Mechanism |
| Buzzer | 1x | Audio Alerts |
| RFID Cards | 2-5x | Access Keys |
| ποΈ Component | π ESP32 Pin | π Connection |
|---|---|---|
| π Buzzer | GPIO 25 |
Digital Output |
| βοΈ Servo Motor | GPIO 26 |
PWM Signal |
| πΊ LCD (SDA) | GPIO 21 |
I2C Data |
| πΊ LCD (SCL) | GPIO 22 |
I2C Clock |
| π·οΈ RFID (SS) | GPIO 5 |
SPI Select |
| π·οΈ RFID (RST) | GPIO 4 |
Reset |
| π MPU6050 | I2C Bus |
Motion Sensor |
# Core framework
pip install fastapi uvicorn
# AI and ML libraries
pip install langchain langchain-google-genai langchain-community
# Utilities
pip install python-dotenv requests
# Optional: For development
pip install python-multipart| Library | Version | Installation |
|---|---|---|
LiquidCrystal_I2C |
Latest | Library Manager |
MPU6050_light |
Latest | Library Manager |
MFRC522 |
Latest | Library Manager |
ESP32Servo |
Latest | Library Manager |
Quick Install:
// In Arduino IDE: Tools β Manage Libraries β Search & Install:
LiquidCrystal I2C by Frank de Brabander
MPU6050 light by rfetick
MFRC522 by GithubCommunity
ESP32Servo by Kevin HarringtonThe system uses Google's Gemini AI to provide:
- π Security Insights: "What security events have occurred today?"
- π Pattern Analysis: "How many unauthorized access attempts were there?"
- π¨ Threat Assessment: "Are there any suspicious patterns in the logs?"
- π Trend Analysis: "Show me the security summary for this week"
Ask questions in plain English:
"Who tried to access the door today?"
"How many times was the door unlocked?"
"Show me all motion alerts"
"What's the security status?"
- Live Event Stream: Real-time security event monitoring
- AI Summary: Automated security insights
- Interactive Chat: Ask questions about your security data
- Visual Analytics: Door status and event patterns
-
Gemini AI Key:
# Get free API key from: https://makersuite.google.com/app/apikey echo "GEMINI_API_KEY=your_actual_api_key" > .env
-
Twilio SMS (Optional):
const String TWILIO_ACCOUNT_SID = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; const String TWILIO_AUTH_TOKEN = "your_32_character_auth_token"; const String DEST_PHONE = "+1234567890";
// ESP32 WiFi Setup
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
// Backend URL (replace with your computer's IP)
const String BACKEND_URL = "http://192.168.1.100:8000";| Endpoint | Method | Description |
|---|---|---|
/api/health |
GET | System health check |
/api/logs |
GET | Retrieve all security logs |
/api/logs |
POST | Add new security event |
/api/summary |
GET | Get AI-generated summary |
/api/ask |
GET | Ask AI questions about security |
# Add a security event
import requests
event = {
"event": "door_unlocked",
"detail": "RFID authorized"
}
response = requests.post("http://localhost:8000/api/logs", json=event)
# Ask AI a question
response = requests.get("http://localhost:8000/api/ask?question=What security events occurred today?")
print(response.json()["answer"])|
π Motion Detected |
β |
π¨ Alarm Activated |
β |
π Door Locks |
β |
π± SMS Alert |
β |
π€ AI Analysis (Logs to backend) |
| π’ Normal Mode | π‘ Alert Mode | π΄ Lockdown Mode |
|---|---|---|
| System monitoring | Invalid access detected | Theft attempt detected |
| RFID access enabled | Audio/visual warnings | All access disabled |
| Auto-lock timer active | SMS notifications sent | Continuous alarm |
| AI analysis active | Backend logging | Emergency lockdown |
// Servo Positions
#define SERVO_LOCKED_POS 70 // Adjust for your lock mechanism
#define SERVO_UNLOCKED_POS 160 // Fine-tune door opening angle
// Security Settings
#define ACCEL_THRESHOLD 0.6 // Motion sensitivity
const unsigned long ALARM_DURATION = 120000; // 2 minutes alarm
const unsigned long DOOR_AUTO_CLOSE = 120000; // 2 minutes auto-lock-
Scan Unknown Card (check Serial Monitor):
New card detected: A1 B2 C3 D4 -
Add to Valid Cards Array:
byte validCards[][4] = { {0x3D, 0xF3, 0x3B, 0x06}, // Existing card {0xA1, 0xB2, 0xC3, 0xD4}, // New card β¨ };
Click to expand solutions
Common Issues:
- β
Check Gemini API key in
.envfile - β Verify internet connection for AI requests
- β Ensure backend is running on port 8000
- β Check API quota limits
Debug Commands:
# Test API key
python -c "from dotenv import load_dotenv; import os; load_dotenv(); print('API Key loaded:', bool(os.getenv('GEMINI_API_KEY')))"
# Test backend health
curl http://localhost:8000/api/healthClick to expand solutions
ESP32 Connection:
// Debug WiFi connection
Serial.println("WiFi Status: " + String(WiFi.status()));
Serial.println("SSID: " + String(WiFi.SSID()));
Serial.println("IP Address: " + WiFi.localIP().toString());Backend Connection:
// Test backend connectivity
HTTPClient http;
http.begin(BACKEND_URL + "/api/health");
int httpCode = http.GET();
Serial.println("Backend Status: " + String(httpCode));Click to expand solutions
Connection Test:
void setup() {
if (!rfid.PCD_Init()) {
Serial.println("β RFID initialization failed!");
} else {
Serial.println("β
RFID ready");
}
}Common Issues:
- β Check SPI connections (MISO, MOSI, SCK)
- β Verify 3.3V power supply
- β Try different RFID cards
- β Clean card and reader surface
-
Start Backend:
python backend.py
-
Open Dashboard:
start frontend.html
-
Test AI Features:
- Ask: "What security events have occurred?"
- Ask: "How many door unlocks today?"
- Ask: "Show me motion alerts"
-
Simulate Events:
python simulate_logs.py
"Who are you?"
"What security events have occurred today?"
"How many times has the door been unlocked?"
"Are there any suspicious patterns?"
"Show me a summary of recent activity"
"What motion alerts have been triggered?"
The system automatically:
- Logs all security events with timestamps
- Creates vector embeddings for intelligent search
- Provides pattern analysis through AI
- Generates security insights and recommendations
- Live dashboard updates every 5 seconds
- Instant AI responses to security queries
- Automatic event logging from ESP32
- Real-time status monitoring
| Contributor | Role |
|---|---|
| SH Nihil Mukkesh | Hardware , AI Integration & Deployment |
| Dakshin Raj P | Hardware , Firmware & Testing |
| Prawin Aadhithya AM | Circuit Connections & Simulation |
| Sharvesh C | Circuit Connections & Simulation |
MIT License - See LICENSE file for details
This project is open-source and free to use for educational and personal purposes.