This is a Smart Energy Monitoring and Safety System designed for residential areas in Nigeria. The system monitors power parameters (Voltage, Current, Power), displays data locally on an OLED screen, transmits data to the cloud via Blynk, and includes automatic safety protection that disconnects power during fault conditions.
This project was professionally designed and implemented as a Final Year Project (FYP) for a client, focusing on robust industrial-grade monitoring principles and cloud-integrated data analytics.
β
Real-time Monitoring: Continuous voltage, current, and power measurement
β
Cloud Dashboard: Blynk IoT integration for remote monitoring
β
Cloud Logging: Automatic logging to Google Sheets for historical data analysis
β
Local Display: 1.3" OLED screen showing live data
β
Safety Protection: Automatic relay trip on over-voltage, under-voltage, or over-current
β
Offline Operation: Continues monitoring and protection even without WiFi
β
Battery Monitoring: Track system uptime and battery health via heartbeat logging
β
Visual Status: RGB LED indicates system state
β
Modular Architecture: Clean C++ design with separated concerns
β
Non-blocking: Uses millis() timers, no delay() calls
- Microcontroller: ESP32 Dev Kit
- Voltage Sensor: ZMPT101b (simulated with potentiometer for testing)
- Current Sensor: SCT-013 100A CT (simulated with potentiometer for testing)
- Relay: 1-Channel Relay Module
- Display: 1.3" OLED (SSD1306, I2C)
- Status LED: RGB LED (Common Cathode)
- Power Control: Physical Boat Switch (hardware power on/off)
- Power: AC-DC 5V with 7.4V battery backup
| Component | GPIO Pin | Notes |
|---|---|---|
| Voltage Sensor | GPIO 34 | ADC1_CH6 |
| Current Sensor | GPIO 35 | ADC1_CH7 |
| Relay | GPIO 26 | Configurable Active HIGH/LOW |
| RGB LED (Red) | GPIO 25 | PWM capable |
| RGB LED (Green) | GPIO 33 | PWM capable |
| RGB LED (Blue) | GPIO 32 | PWM capable |
| OLED SDA | GPIO 21 | I2C Data |
| OLED SCL | GPIO 22 | I2C Clock |
- EnergySensor: Handles sensor reading with calibration
- DisplayManager: Manages OLED display screens
- NetworkManager: WiFi and Blynk communication
- SafetyManager: Threshold monitoring and relay control
- CloudLogger: Automatic logging to Google Sheets
- PerformanceLogger: CSV logging via Serial and cloud integration
- StateManager: Finite state machine coordinating all modules
- STATE_BOOT: Initialization and WiFi connection
- STATE_NORMAL: Active monitoring with cloud logging
- STATE_TRIP_PROTECTION: Fault detected, power disconnected
- STATE_OFFLINE_MODE: WiFi lost, local monitoring continues
You can test the entire system in your browser using Wokwi:
- Install Wokwi for VS Code
- Build the project:
pio run - Press
F1β "Wokwi: Start Simulator" - Adjust potentiometers to simulate voltage/current changes
See WOKWI_SIMULATION.md for detailed testing scenarios.
Install PlatformIO IDE or CLI.
IMPORTANT: Create your secrets.h file by moving the template from the docs folder:
# Move the template to the include folder and rename it
copy docs/secrets.h.example include/secrets.h # On Windows
# OR
cp docs/secrets.h.example include/secrets.h # On Linux/MacEdit include/secrets.h and update your credentials:
// WiFi Credentials
#define SECRET_WIFI_SSID "Your_WiFi_Name"
#define SECRET_WIFI_PASSWORD "Your_WiFi_Password"
// Blynk IoT Credentials
#define SECRET_BLYNK_TEMPLATE_ID "Your_Template_ID"
#define SECRET_BLYNK_TEMPLATE_NAME "Your_Template_Name"
#define SECRET_BLYNK_AUTH_TOKEN "Your_Blynk_Token"
// Google Sheets Logging
#define SECRET_GOOGLE_SHEETS_URL "https://script.google.com/macros/s/YOUR_DEPLOYMENT_ID/exec"Note:
secrets.his already in.gitignoreand will NOT be committed to version control.
Adjust thresholds in include/config.h:
#define VOLTAGE_MAX 240.0 // Over-voltage trip
#define VOLTAGE_MIN 180.0 // Under-voltage trip
#define CURRENT_MAX 20.0 // Over-current trippio run --target upload
pio device monitor- V0: Voltage (read-only)
- V1: Current (read-only)
- V2: Power (read-only)
- V3: System State (read-only)
- V4: Reset Button (write)
Create the following datastreams in your Blynk template:
- V0 - Voltage (0-300V)
- V1 - Current (0-100A)
- V2 - Power (0-10000W)
- V3 - State (String)
- V4 - Reset (Integer 0-1)
The system automatically logs performance data and system events to Google Sheets when WiFi is connected.
- Create a Google Sheet named "ESP32 Performance Logs"
- Create 4 tabs:
SystemEvents,Latency,Accuracy,TripResponse - Open Script Editor: Extensions β Apps Script
- Paste the script from
docs/google_apps_script.js - Deploy as Web App:
- Click Deploy β New deployment
- Type: Web app
- Execute as: Me
- Who has access: Anyone
- Click Deploy
- Copy the deployment URL
Edit include/config.h:
#define GOOGLE_SHEETS_URL "https://script.google.com/macros/s/YOUR_DEPLOYMENT_URL/exec"
#define ENABLE_CLOUD_LOGGING // Enables automatic cloud logging
#define ENABLE_PERFORMANCE_LOGGING // Enables performance metricsSystemEvents Tab:
- BOOT - System startup
- HEARTBEAT - Every 5 minutes (includes WiFi RSSI for battery health monitoring)
- POWER_OUTAGE - Mains voltage lost
- POWER_RESTORED - Mains voltage restored
- TRIP - Safety faults with fault reason
Latency Tab:
- Sensor read time
- Blynk transmit time
- Total latency (logged on every Blynk transmission)
Accuracy Tab:
- Voltage, Current, Power readings
- Logged every 10 seconds
TripResponse Tab:
- Fault detection time
- Relay trip time
- Total response time (logged when safety trips occur)
Use heartbeat data to monitor battery health:
- Continuous heartbeats during outage = Healthy battery
- Gaps in heartbeats = Battery depleted or WiFi too weak
- Declining RSSI = Battery voltage dropping
- BOOT after gap = System shut down (battery dead)
After hardware assembly, calibrate sensors:
- Connect a known voltage source (measure with multimeter)
- Adjust
VOLTAGE_SLOPEandVOLTAGE_INTERCEPTinconfig.h - Connect a known current load (measure with clamp meter)
- Adjust
CURRENT_SLOPEandCURRENT_INTERCEPTinconfig.h - Verify accuracy across operating range
The system continuously monitors power parameters every 100ms. If any threshold is exceeded:
- Relay trips immediately (power disconnected)
- RGB LED turns RED
- OLED displays fault reason
- Alert sent to Blynk (if connected)
To reset after a trip:
- Ensure fault condition is cleared
- Press reset button in Blynk app
The system will only reset if readings are within safe limits.
Critical: Safety monitoring continues even when WiFi is disconnected. The relay will trip on fault conditions regardless of network status.
- π΅ Blue: Booting/Initializing
- π’ Green: Normal operation
- π‘ Yellow: Offline mode (WiFi disconnected)
- π΄ Red: Trip protection active
- Check I2C address (0x3C or 0x3D)
- Verify SDA/SCL connections
- Check serial monitor for initialization errors
- Verify credentials in
config.h - Check 2.4GHz WiFi (ESP32 doesn't support 5GHz)
- Monitor serial output for connection attempts
- Verify auth token
- Ensure WiFi is connected first
- Check Blynk server status
- Adjust hysteresis values in
config.h - Calibrate sensors properly
- Check for electrical noise
To switch from simulation (potentiometers) to real sensors:
- Remove
-D SIMULATION_MODEfromplatformio.ini - Add EmonLib library
- Update
EnergySensor.cppwith EmonLib code - Recalibrate with actual sensors
- API Documentation - Complete API reference, configuration guide, calibration procedures, and troubleshooting
- Technical Challenges Report - Detailed analysis of all challenges faced and solutions implemented
- Chapter 3: Methodology - Academic methodology documentation with diagrams and algorithms
- Blynk Setup Guide - Step-by-step IoT platform configuration
- Hybrid Analysis Guide - Guide for combining cloud and USB data for unified analysis
- Wokwi Simulation Guide - Browser-based testing without hardware
| Topic | Document | Description |
|---|---|---|
| Getting Started | API Documentation | Installation and first-time setup |
| API Reference | API Documentation | Complete class and method documentation |
| Calibration | API Documentation | Sensor calibration step-by-step |
| Troubleshooting | API Documentation | Common issues and solutions |
| Contributing | API Documentation | Code style and contribution guidelines |
| Future Plans | API Documentation | Roadmap and planned features |
MIT License - Free for educational and commercial use
For issues or questions, please open an issue on GitHub.