Saturday, 30 May 2026

AI Smart Power Factor Correction with Load Prediction

AI Smart Power Factor Correction with Load Prediction ESP32 + Agentic AI + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard
AI Smart Power Factor Correction with Load Prediction ESP32 + Agentic AI + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard 1. Project Overview Project Title AI-Powered Smart Power Factor Correction System with Load Prediction using ESP32, n8n Automation, Telegram Voice Alerts, Google Sheets Logging, and ThingSpeak Cloud Dashboard Project Objective Develop an intelligent energy monitoring and power factor correction system that: Measures Voltage, Current, Power, Energy, and Power Factor. Automatically switches capacitor banks for power factor correction. Uses AI-based prediction to forecast future power consumption. Sends voice alerts through Telegram. Stores historical data in Google Sheets. Visualizes real-time data on ThingSpeak. Uses n8n as the automation and AI orchestration platform. Supports future Agentic AI decision-making. 2. System Architecture ┌────────────────────┐ │ Electrical Load │ └──────────┬─────────┘ │ Voltage & Current │ ┌─────────▼────────┐ │ PZEM004T │ │ Energy Meter │ └─────────┬────────┘ │ UART ┌─────────▼────────┐ │ ESP32 │ │ Data Collection │ └─────────┬────────┘ │ WiFi ┌──────────────────┼─────────────────┐ │ │ │ ▼ ▼ ▼ ThingSpeak n8n Workflow Google Sheets │ ▼ AI Prediction Engine │ ▼ Telegram Bot │ Voice Alerts ▼ Power Factor Control Relay Bank 3. Features Monitoring Voltage Current Active Power Apparent Power Reactive Power Power Factor Energy Consumption Automation Automatic capacitor switching AI load forecasting Telegram alerts Voice notifications Cloud ThingSpeak Dashboard Google Sheets Storage Historical Analytics AI Features Consumption Prediction Anomaly Detection Peak Demand Forecasting Future Agentic Actions 4. Components Required Component Quantity ESP32 Dev Board 1 PZEM-004T v3 Energy Meter 1 ZMPT101B Voltage Sensor (optional) 1 SCT013 Current Sensor (optional) 1 5V Relay Module 4 Capacitor Banks 4 Capacitors (2µF,4µF,8µF,16µF) As required Power Supply 5V 1 WiFi Router 1 Breadboard/PCB 1 Jumper Wires Multiple Telegram Bot 1 ThingSpeak Account 1 Google Account 1 n8n Server 1 5. Power Factor Correction Theory Power Factor: PF= Apparent Power Real Power ​ Ideal PF: 0.95 to 1.00 If PF drops: PF < 0.90 Capacitor bank is switched ON. Example: PF = 0.72 Relay 1 ON PF = 0.65 Relay 1 + Relay 2 ON PF = 0.55 Relay 1 + Relay 2 + Relay 3 ON 6. Circuit Connections ESP32 ↔ PZEM004T PZEM ESP32 TX GPIO16 RX GPIO17 VCC 5V GND GND Relay Module Relay ESP32 Relay1 GPIO25 Relay2 GPIO26 Relay3 GPIO27 Relay4 GPIO14 Capacitor Banks Relay1 → 2uF Relay2 → 4uF Relay3 → 8uF Relay4 →16uF Connected parallel to load. 7. Circuit Schematic AC LOAD │ ┌──▼──┐ │PZEM │ └──┬──┘ │ ▼ ESP32 │ ┌──┼───────────────┐ │ │ │ │ │ ▼ ▼ ▼ ▼ ▼ R1 R2 R3 R4 WiFi │ │ │ │ ▼ ▼ ▼ ▼ Capacitor Bank 8. Flowchart START │ ▼ Connect WiFi │ ▼ Read PZEM Data │ ▼ Calculate PF │ ▼ PF < 0.90 ? ┌──Yes──┐ ▼ ▼ Enable No Action Capacitor │ ▼ Send Data │ ▼ ThingSpeak │ ▼ n8n Webhook │ ▼ AI Prediction │ ▼ Store in Sheets │ ▼ Send Telegram Alert │ ▼ Repeat 9. ESP32 Source Code Libraries Install: PZEM004Tv30 WiFi HTTPClient ArduinoJson Main Code #include #include #include PZEM004Tv30 pzem(Serial2,16,17); const char* ssid="YOUR_WIFI"; const char* pass="PASSWORD"; String webhookURL = "https://n8n-server/webhook/power"; #define RELAY1 25 #define RELAY2 26 #define RELAY3 27 #define RELAY4 14 void setup() { Serial.begin(115200); pinMode(RELAY1,OUTPUT); pinMode(RELAY2,OUTPUT); pinMode(RELAY3,OUTPUT); pinMode(RELAY4,OUTPUT); WiFi.begin(ssid,pass); while(WiFi.status()!=WL_CONNECTED) { delay(500); } } void loop() { float voltage=pzem.voltage(); float current=pzem.current(); float power=pzem.power(); float pf=pzem.pf(); if(pf<0.90) { digitalWrite(RELAY1,HIGH); } if(pf<0.80) { digitalWrite(RELAY2,HIGH); } if(pf<0.70) { digitalWrite(RELAY3,HIGH); } if(pf<0.60) { digitalWrite(RELAY4,HIGH); } HTTPClient http; http.begin(webhookURL); http.addHeader("Content-Type", "application/json"); String payload="{\"voltage\":" +String(voltage)+ ",\"current\":" +String(current)+ ",\"power\":" +String(power)+ ",\"pf\":" +String(pf)+"}"; http.POST(payload); http.end(); delay(30000); } 10. ThingSpeak Setup Create channel. Fields: Field1 Voltage Field2 Current Field3 Power Field4 PF Field5 Energy Field6 Predicted Load Get: Write API Key Channel ID ESP32 sends data every 30 seconds. Example URL: https://api.thingspeak.com/update Parameters: api_key=XXXX field1=230 field2=5 field3=1100 field4=0.92 11. Google Sheets Integration Create Sheet: Timestamp Voltage Current Power PF Energy Prediction Status n8n Google Sheet Node Action: Append Row Every incoming ESP32 record gets stored. 12. Telegram Bot Setup Open Telegram. Search: BotFather Create bot: / newbot Receive: BOT TOKEN Get Chat ID. Save both. 13. Voice Alert System Telegram supports voice files. n8n workflow: Incoming Data │ ▼ Function Node │ ▼ Text-to-Speech │ ▼ Telegram Send Audio Example message: Warning. Power factor has dropped to 0.68 Capacitor bank activated. Predicted load increase within 30 minutes. 14. AI Load Prediction Logic Dataset Historical records: Time Voltage Current Power Energy PF Prediction Inputs Last 24 Hours Features: Hour Day Power Current Energy Prediction Output Next 30 min load Next 1 hour load Next 24 hour load Simple AI Model Linear Regression Predicted_Load = a+b(power)+c(current)+d(hour) Advanced AI Use: XGBoost Random Forest LSTM Prophet 15. n8n Workflow Design Webhook Trigger │ ▼ Data Processing │ ▼ AI Agent Node │ ├─────────► ThingSpeak │ ├─────────► Google Sheets │ ├─────────► Telegram Text │ └─────────► Telegram Voice 16. Example n8n Workflow JSON Structure { "nodes":[ { "name":"Webhook" }, { "name":"Function" }, { "name":"Google Sheets" }, { "name":"Telegram" } ] } In actual deployment export the workflow from n8n after configuration. 17. Agentic AI Extension AI Agent receives: PF Voltage Current Historical Trends Weather Time Agent decides: Increase Capacitor Decrease Capacitor Peak Warning Maintenance Alert Example: Predicted PF drop in 20 min Activate 8uF capacitor now. 18. Telegram Alert Examples Normal System Healthy PF = 0.97 Load = 1.1 kW Warning PF Low PF = 0.75 Capacitor Activated Critical PF = 0.52 Maximum Capacitor Bank Active Immediate inspection required 19. Future Enhancements AI LSTM Forecasting Reinforcement Learning Predictive Maintenance Load Classification Cloud MQTT Broker AWS IoT Azure IoT Hub Google Cloud IoT Hardware 3-Phase Monitoring Automatic Capacitor Bank Panel Industrial PLC Integration Mobile App Flutter Dashboard React Native Dashboard AI Chat Assistant 20. Deployment Guide Phase 1 Build hardware. Verify: Voltage readings Current readings PF readings Phase 2 Configure: WiFi ThingSpeak Telegram Phase 3 Deploy n8n. Recommended options: Docker VPS Raspberry Pi Phase 4 Connect: ESP32 → n8n n8n → Sheets n8n → Telegram n8n → ThingSpeak Phase 5 Train AI Model Collect: 1–4 weeks data Train prediction model and integrate it into n8n or a Python microservice. Final Outcome This project becomes a complete Industry 4.0 Smart Energy Management System capable of: Real-time electrical monitoring Automatic power factor correction AI-based load forecasting Agentic decision-making Cloud analytics Google Sheets logging ThingSpeak visualization Telegram text and voice alerts Scalable industrial deployment using ESP32 and n8n automation.

No comments:

Post a Comment

AI Smart Road Pothole Detection and Mapping System

AI Smart Road Pothole Detection and Mapping System AI-Powered ESP32 + Agentic IoT + n8n Automation + Telegram Voice Alerts + Google Sheets +...