A smart IoT-based power theft detection system using ESP32 and current sensors with a real-time web dashboard.
This system detects power theft by comparing current readings between input and load lines. When theft is detected (measured by a significant difference between input and load current), the system alerts users through a web dashboard. Users can then manually cut off power or restore it remotely from anywhere with internet access.
- Real-time Current Monitoring: Measures current from input and load using ACS712 sensors
- Theft Detection Algorithm: Compares input and output current to detect unauthorized taps
- Manual Control: Cut off or restore power remotely via web dashboard
- Firebase Integration: Data stored in Firebase Realtime Database for remote access
- Web Dashboard: Mobile-responsive interface with real-time updates
- Location Tracking: Shows device location on an integrated map
- Visual & Audio Alerts: Clear notifications when theft is detected
- Backup Local Interface: Fallback local web server if internet connection fails
- ESP32 Development Board (ESP32 DevKit V1 or similar)
- 2 × ACS712 Current Sensors (5A or appropriate for your application)
- Relay Module (to control power)
- Power Supply for ESP32 (5V)
- Jumper Wires
- Breadboard/PCB for circuit assembly
- ACS712 Input Sensor → GPIO32 on ESP32
- ACS712 Load Sensor → GPIO33 on ESP32
- Relay Control → GPIO25 on ESP32
- Connect sensors in series with input and load lines
- PlatformIO IDE (recommended) or Arduino IDE
- Required Libraries:
- Firebase ESP32 Client (version 3.17.1)
- ArduinoJson (version 6.21.3)
- ESP32 Arduino Core
- Connect the ACS712 sensors to your power lines
- Wire the ESP32 as per the connection guide above
- Connect the relay module to control the power line
- Create a Firebase project at Firebase Console
- Set up a Realtime Database
- Update the Firebase credentials in
src/main.cpp:#define FIREBASE_HOST "your-project-id.firebasedatabase.app" #define FIREBASE_AUTH "your-database-secret-or-api-key"
Using PlatformIO (Recommended):
- Clone this repository
- Open the project in PlatformIO
- Update WiFi credentials in
src/main.cpp:const char* ssid = "your-wifi-ssid"; const char* password = "your-wifi-password";
- Update location data for your installation:
const float latitude = 12.938477; // Your location const float longitude = 77.564919; // Your location
- Connect ESP32 via USB
- Click Upload button or run:
pio run --target upload
Using Arduino IDE:
- Install required libraries through Library Manager
- Set board to ESP32 Dev Module
- Copy code from
src/main.cppto a new sketch - Update WiFi and Firebase credentials
- Upload to your ESP32
- Open
firebase-dashboard.htmlin any web browser - The dashboard will connect to Firebase and show real-time data
- Monitor current readings and theft status
- If theft is detected, an alert will appear
- Use the Emergency Cutoff and Restore Power buttons to control the system
If needed, you can also access a local dashboard:
- Find your ESP32's IP address from the serial monitor
- Open
dashboard.htmlin a browser - Enter the ESP32's IP address when prompted
The system uses a default threshold of 0.1A for theft detection. You may need to adjust the following variables in src/main.cpp for your specific setup:
const float sensitivity = 0.185; // For ACS712-5A: 185 mV/A
const float theftThreshold = 0.1; // Theft detection threshold (0.1A)- WiFi Connection Issues: Check SSID and password. The ESP32 will still function without WiFi, but without remote capabilities.
- Firebase Connection Failed: Verify your API key and database URL.
- Current Readings Inaccurate: Calibrate the
offsetVoltagevalues or adjust the sensitivity for your specific ACS712 model. - Theft Detection Too Sensitive/Insensitive: Adjust
theftThresholdvalue.
This project is released under the MIT License.
- ACS712 Current Sensor library
- Firebase ESP32 Client library by Mobizt
- ESP32 Arduino Core
- TailwindCSS for the dashboard UI
- Leaflet for map integration
/
├── platformio.ini # PlatformIO configuration
├── src/
│ └── main.cpp # Main ESP32 code
├── firebase-dashboard.html # Remote web interface
└── dashboard.html # Local backup interface