Yes. This can be developed as a complete academic/industrial-style IoT project combining:
- ESP32 as the edge controller
- Three-phase transformer sensing
- Local protection/interlocking
- ThingSpeak cloud dashboard
- n8n automation
- AI-based fault interpretation
- Telegram text + voice alerts
- Google Sheets event/history logging
- A custom IoT web dashboard
- Optional AI-agent commands and remote control
The most important design principle is: the ESP32 must perform the immediate protection locally; cloud/AI/n8n must never be the only protection layer. Internet or AI failure must not prevent the transformer from being protected.
The ESP32 Arduino platform officially supports Wi-Fi and ADC/peripheral functionality suitable for this type of edge-monitoring application. ThingSpeak provides REST APIs for writing and reading channel data. n8n provides Webhook and Telegram nodes for event-driven automation.
1. Proposed Project Title
IoT-Based Three-Phase Transformer Monitoring, Protection and AI-Agentic Alert System Using ESP32, ThingSpeak and n8n Automation
Alternative title
AI-Powered Agentic IoT Three-Phase Transformer Monitoring and Protection System Using ESP32, n8n, ThingSpeak, Telegram and Google Sheets
2. Complete Project Concept
The proposed system continuously monitors a three-phase transformer and measures parameters such as:
- Phase-R voltage
- Phase-Y voltage
- Phase-B voltage
- Phase-R current
- Phase-Y current
- Phase-B current
- Transformer/load temperature
- Frequency
- Phase imbalance
- Overvoltage
- Undervoltage
- Overcurrent
- Overtemperature
- Power/load condition
- Protection status
- Internet/device status
The ESP32 collects the sensor information and performs local fault detection.
Normal data is uploaded to ThingSpeak.
When a fault occurs:
Transformer
↓
Sensors
↓
ESP32
↓
Local Protection Decision
↓
Fault detected?
/ \
NO YES
| |
Cloud Trip/Alarm
| |
ThingSpeak ↓
| n8n Webhook
| ↓
| AI Analysis
| ↓
| Telegram Alert
| ↓
| Voice Alert
| ↓
| Google Sheets
↓
Dashboard
3. High-Level Architecture
┌──────────────────────────┐
│ 3-PHASE TRANSFORMER │
│ │
│ R Y B │
└───────┬───────┬───────┬──┘
│ │ │
┌───────────┴───────┴───────┴───────────┐
│ SENSORS │
│ │
│ Voltage Current Temperature │
│ Sensors Sensors Sensor │
└───────────────┬─────────────────────────┘
│
↓
┌─────────────────────┐
│ ESP32 │
│ │
│ ADC / GPIO / Wi-Fi │
│ │
│ Monitoring │
│ Protection Logic │
│ Fault Detection │
└──────┬──────────────┘
│
┌──────────┴───────────┐
│ │
↓ ↓
LOCAL PROTECTION Wi-Fi/Internet
│ │
↓ ↓
Relay/Contactor ThingSpeak
/ Trip Circuit │
│ ↓
↓ Cloud Dashboard
Transformer │
isolated │
n8n
│
┌──────────────────┼────────────────┐
↓ ↓ ↓
AI Agent Telegram Google Sheets
│ │ │
↓ ↓ ↓
Fault Analysis Text Alert Event Log
│
↓
Voice Alert
4. Safety Architecture
This is particularly important because transformer monitoring involves potentially lethal voltages.
Do not connect transformer primary or secondary mains directly to ESP32 GPIO/ADC pins.
Use properly rated:
- Isolation transformers / voltage transformers
- Current transformers
- Hall-effect current sensors
- Opto-isolation where appropriate
- Fuses
- MCB
- Surge protection
- Proper earthing
- Isolation barriers
- Rated contactors
- Proper enclosure
The ESP32 side should operate at its low-voltage logic level, while measurement/protection interfaces provide the necessary electrical isolation.
For an academic prototype, it is much safer to demonstrate using a low-voltage isolated three-phase source or laboratory transformer model.
5. Hardware Components
Main controller
ESP32 Development Board
Recommended:
- ESP32 DevKit
- ESP32-WROOM-based board
- USB programming interface
- Wi-Fi connectivity
Espressif's Arduino documentation currently documents the ESP32 Arduino core and supported ESP32 families.
Sensors
A practical prototype can use:
| Parameter | Sensor/interface |
|---|---|
| Voltage R | Isolated voltage sensor |
| Voltage Y | Isolated voltage sensor |
| Voltage B | Isolated voltage sensor |
| Current R | CT/Hall current sensor |
| Current Y | CT/Hall current sensor |
| Current B | CT/Hall current sensor |
| Temperature | DS18B20 / PT100 interface |
| Frequency | Zero-crossing isolated circuit |
| Trip feedback | Digital input |
| Contactor status | Digital input |
6. Recommended Pin Allocation
One possible ESP32 mapping:
ESP32
────────────────────────────
GPIO 34 ← Voltage R
GPIO 35 ← Voltage Y
GPIO 32 ← Voltage B
GPIO 33 ← Current R
GPIO 36 ← Current Y
GPIO 39 ← Current B
GPIO 4 ← Temperature sensor
GPIO 25 ← Trip relay
GPIO 26 ← Alarm relay
GPIO 27 ← Reset input
GPIO 14 ← Contactor feedback
GPIO 13 ← Emergency-stop feedback
GPIO 2 → Status LED
Important: exact ADC suitability and pin availability depend on the specific ESP32 board. Verify the board's pinout before building.
7. Measurement Chain
The measurement architecture should look like:
HIGH-VOLTAGE SIDE
│
│
↓
┌───────────────────┐
│ Isolation Sensor │
└─────────┬─────────┘
│
↓
Signal conditioning
│
↓
┌───────────────────┐
│ ESP32 ADC │
└─────────┬─────────┘
│
↓
Digital processing
│
↓
RMS calculation
│
↓
Fault analysis
For current:
Transformer conductor
│
↓
CT
│
↓
Burden / signal conditioning
│
↓
ESP32 ADC
8. Three-Phase Monitoring
The ESP32 calculates:
Phase voltage
VR, VY, VB
Phase current
IR, IY, IB
Average voltage
Vavg=VR+VY+VB3
Average current
Iavg=IR+IY+IB3
Voltage imbalance
Vimbalance=max(VR,VY,VB)−min(VR,VY,VB)Vavg×100
Current imbalance
Iimbalance=max(IR,IY,IB)−min(IR,IY,IB)Iavg×100
These values can be used for warning and protection decisions.
9. Protection Logic
Example engineering thresholds:
| Condition | Example threshold |
|---|---|
| Undervoltage | < 90% nominal |
| Overvoltage | > 110% nominal |
| Overcurrent warning | > 90% rated |
| Overcurrent trip | > 110% rated |
| Temperature warning | 70°C |
| Temperature trip | 85°C |
| Voltage imbalance warning | > 3% |
| Voltage imbalance trip | > 5% |
These are example values only. Actual thresholds must come from the transformer rating, protection study, applicable standards, sensor characteristics and engineering requirements.
10. Two-Level Protection
This project should deliberately use two separate layers.
Layer 1 — Local protection
ESP32 immediately evaluates:
Voltage
Current
Temperature
Phase imbalance
↓
Protection algorithm
↓
Fault?
↓
Relay/Trip
This should continue operating even if:
- Wi-Fi fails
- ThingSpeak fails
- n8n fails
- Telegram fails
- AI service fails
- Internet fails
Layer 2 — Cloud intelligence
Cloud services provide:
- Historical analysis
- Notifications
- Reports
- AI interpretation
- Maintenance suggestions
- Event logging
- Remote dashboard
11. Fault State Machine
┌──────────────┐
│ NORMAL │
└──────┬───────┘
│
abnormal value
↓
┌──────────────┐
│ WARNING │
└──────┬───────┘
│
condition persists
↓
┌──────────────┐
│ TRIP │
└──────┬───────┘
│
Contactor OFF
│
↓
┌──────────────┐
│ LOCKOUT │
└──────┬───────┘
│
Manual reset
↓
┌──────────────┐
│ NORMAL │
└──────────────┘
This is better than simply saying:
if fault -> relay off
because it prevents rapid relay oscillation.
12. ThingSpeak Architecture
ThingSpeak can store the measurements and display them as charts. Its REST API supports channel writes using HTTP GET or POST.
A suggested channel structure:
| Field | Parameter |
|---|---|
| Field 1 | Voltage R |
| Field 2 | Voltage Y |
| Field 3 | Voltage B |
| Field 4 | Current R |
| Field 5 | Current Y |
| Field 6 | Current B |
| Field 7 | Temperature |
| Field 8 | Fault code |
Additional calculated values can be sent through another channel if necessary.
For example:
ThingSpeak Channel
│
├── Field 1 = V_R
├── Field 2 = V_Y
├── Field 3 = V_B
├── Field 4 = I_R
├── Field 5 = I_Y
├── Field 6 = I_B
├── Field 7 = Temperature
└── Field 8 = Fault Code
ThingSpeak uses channel Write API Keys for writing data.
13. ESP32 → ThingSpeak
The ESP32 sends an HTTP request such as:
https://api.thingspeak.com/update.json
with parameters conceptually like:
api_key=YOUR_WRITE_KEY
field1=230
field2=231
field3=229
field4=4.2
field5=4.1
field6=4.3
field7=52
field8=0
ThingSpeak documents this update endpoint and its field parameters.
14. IoT Webpage
I recommend building a separate dashboard rather than relying only on ThingSpeak.
Example:
┌────────────────────────────────────────────────────────┐
│ THREE-PHASE TRANSFORMER IoT DASHBOARD │
├────────────────────────────────────────────────────────┤
│ │
│ STATUS: 🟢 NORMAL ESP32: ONLINE │
│ │
├──────────┬──────────┬──────────┬───────────────────────┤
│ V-R │ V-Y │ V-B │ Temperature │
│ 230 V │ 231 V │ 229 V │ 54 °C │
├──────────┼──────────┼──────────┼───────────────────────┤
│ I-R │ I-Y │ I-B │ Frequency │
│ 4.2 A │ 4.1 A │ 4.3 A │ 50 Hz │
└──────────┴──────────┴──────────┴───────────────────────┘
LIVE GRAPHS
Voltage
240 ┤ ╭───╮
230 ┤───────╯ ╰────────
220 ┤
└────────────────────── time
Current
6 ┤
4 ┤──────╭────╮─────────
2 ┤──────╯ ╰─────────
└────────────────────── time
FAULT HISTORY
Time Fault Action
20:10 Normal —
20:15 Temp Warning Alert
20:20 Normal —
15. n8n Automation Architecture
n8n becomes the automation/orchestration layer.
ESP32
│
│ HTTP POST
↓
┌──────────────┐
│ n8n Webhook │
└──────┬───────┘
│
↓
Validate JSON
│
↓
┌──────────────┐
│ IF / Switch │
└──────┬───────┘
│
┌──────┴────────────┐
│ │
NORMAL FAULT
│ │
↓ ↓
Google Sheets AI Analysis
│
↓
Fault diagnosis
│
┌─────────┴──────────┐
↓ ↓
Telegram Sheets
│
↓
Voice message
n8n's Webhook node is specifically intended to receive data from applications/services and act as a workflow trigger.
16. ESP32 → n8n JSON
Instead of sending a complicated query string, use JSON.
Example:
{
"device": "TX-001",
"voltage_r": 230.4,
"voltage_y": 229.8,
"voltage_b": 231.2,
"current_r": 4.8,
"current_y": 4.7,
"current_b": 4.9,
"temperature": 57.3,
"frequency": 50.01,
"voltage_imbalance": 0.61,
"current_imbalance": 4.08,
"fault_code": 0,
"status": "NORMAL"
}
When there is a fault:
{
"device": "TX-001",
"voltage_r": 230.4,
"voltage_y": 229.8,
"voltage_b": 231.2,
"current_r": 12.8,
"current_y": 12.5,
"current_b": 13.1,
"temperature": 88.2,
"fault_code": 3,
"status": "TRIP"
}
17. AI Agent Architecture
The AI agent should not directly control the transformer without deterministic safety controls.
Instead:
Sensor data
↓
ESP32 protection
↓
n8n
↓
AI Agent
↓
Interpretation
↓
Recommended action
↓
Safety policy
↓
Notification / approved action
The AI can answer questions such as:
"Why did the transformer trip?"
The AI receives:
Voltage R = 231 V
Voltage Y = 230 V
Voltage B = 229 V
Current R = 13.2 A
Current Y = 13.0 A
Current B = 13.5 A
Temperature = 91°C
Fault = Overtemperature
and generates:
TRANSFORMER FAULT ANALYSIS
Device: TX-001
Severity: HIGH
Primary condition:
Transformer temperature exceeded the configured
trip threshold.
Measured temperature: 91°C
Recommended checks:
1. Verify cooling system.
2. Check transformer loading.
3. Inspect ventilation.
4. Check recent current trend.
5. Do not re-energize until temperature and cause
are verified safe.
18. Agentic IoT Concept
The "agentic" part can be structured as:
┌──────────────┐
│ Operator │
└──────┬───────┘
│
Telegram message
│
↓
┌──────────────┐
│ AI Agent │
└──────┬───────┘
│
┌──────────────┼──────────────┐
↓ ↓ ↓
Read Status Analyze Fault Get History
│ │ │
└──────────────┼──────────────┘
↓
Safety Policy
│
↓
Allowed Action?
/ \
NO YES
│ │
↓ ↓
Explain Execute approved
rejection operation
For example:
Operator:
"What's the transformer status?"
AI Agent:
"TX-001 is operating normally.
R/Y/B voltages are within limits.
Temperature is 53°C.
Load current is approximately 4.2 A."
Operator:
"Why did it trip yesterday?"
AI Agent:
"At 14:32 the temperature reached 87°C.
The trip was preceded by increasing phase current.
The likely cause is excessive loading or inadequate cooling."
Operator:
"Reset the transformer."
AI Agent:
"Reset command is not permitted until the local
interlock confirms the transformer is safe."
That final safety behavior is important.
19. Telegram Alert Workflow
Telegram's Bot API provides a sendVoice method for playable voice messages.
The workflow can be:
Fault
↓
n8n
↓
AI Agent
↓
Generate alert text
↓
Text-to-Speech
↓
Audio file
↓
Telegram
↓
Operator phone
Example alert:
🚨 TRANSFORMER ALERT
Device: TX-001
Fault: Overtemperature
Temperature: 88.4 °C
Status: TRIPPED
Phase currents:
R = 12.7 A
Y = 12.5 A
B = 12.9 A
Immediate inspection required.
Then a voice notification:
"Attention. Transformer TX-001 has tripped due to high temperature. The measured temperature is 88.4 degrees Celsius. Please inspect the transformer before re-energizing."
20. Google Sheets Logging
Every event can be recorded:
| Timestamp | Device | VR | VY | VB | IR | IY | IB | Temp | Fault | Action |
|---|---|---|---|---|---|---|---|---|---|---|
| 20:10 | TX001 | 230 | 231 | 229 | 4.2 | 4.1 | 4.3 | 52 | NORMAL | — |
| 20:25 | TX001 | 229 | 231 | 230 | 8.1 | 8.4 | 8.0 | 71 | TEMP-WARN | ALERT |
| 20:31 | TX001 | 228 | 229 | 230 | 12.5 | 12.6 | 12.8 | 87 | TEMP-TRIP | TRIP |
This creates a useful maintenance history.
21. Complete n8n Workflow
A practical workflow can be:
[Webhook]
│
↓
[JSON Validation]
│
↓
[Set / Normalize Data]
│
↓
[Google Sheets - Log]
│
↓
[Switch Fault Status]
│
┌──┴───────────────┐
│ │
NORMAL FAULT
│ │
↓ ↓
End [AI Agent]
│
↓
[Generate Alert]
│
┌────────┴─────────┐
↓ ↓
[Telegram Text] [Text-to-Speech]
│
↓
[Telegram Voice]
│
↓
[Google Sheets]
n8n's Telegram integration supports Telegram automation and message operations.
22. ESP32 Software Structure
The firmware should be divided into modules:
ESP32 Firmware
│
├── sensors.cpp
│ ├── readVoltage()
│ ├── readCurrent()
│ └── readTemperature()
│
├── protection.cpp
│ ├── checkOverVoltage()
│ ├── checkUnderVoltage()
│ ├── checkOverCurrent()
│ ├── checkTemperature()
│ └── checkImbalance()
│
├── cloud.cpp
│ ├── sendThingSpeak()
│ └── sendN8N()
│
├── webserver.cpp
│ └── local dashboard
│
└── main.cpp
23. ESP32 Complete Prototype Code
Below is a prototype firmware architecture. The sensor conversion constants must be calibrated for the actual voltage/current interfaces.
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// =====================================================
// Wi-Fi
// =====================================================
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASSWORD = "YOUR_PASSWORD";
// =====================================================
// ThingSpeak
// =====================================================
const char* THINGSPEAK_URL =
"https://api.thingspeak.com/update";
const char* THINGSPEAK_API_KEY =
"YOUR_THINGSPEAK_WRITE_KEY";
// =====================================================
// n8n
// =====================================================
const char* N8N_WEBHOOK =
"https://YOUR-N8N-DOMAIN/webhook/transformer";
// =====================================================
// Pins
// =====================================================
#define VOLTAGE_R_PIN 34
#define VOLTAGE_Y_PIN 35
#define VOLTAGE_B_PIN 32
#define CURRENT_R_PIN 33
#define CURRENT_Y_PIN 36
#define CURRENT_B_PIN 39
#define TEMP_PIN 4
#define TRIP_RELAY_PIN 25
#define ALARM_RELAY_PIN 26
#define CONTACTOR_FB_PIN 14
#define RESET_PIN 27
// =====================================================
// Temperature
// =====================================================
OneWire oneWire(TEMP_PIN);
DallasTemperature temperatureSensor(&oneWire);
// =====================================================
// Protection thresholds
// =====================================================
float NOMINAL_VOLTAGE = 230.0;
float OVERVOLTAGE_LIMIT =
NOMINAL_VOLTAGE * 1.10;
float UNDERVOLTAGE_LIMIT =
NOMINAL_VOLTAGE * 0.90;
float MAX_CURRENT = 10.0;
float TEMPERATURE_WARNING = 70.0;
float TEMPERATURE_TRIP = 85.0;
float VOLTAGE_IMBALANCE_LIMIT = 5.0;
float CURRENT_IMBALANCE_LIMIT = 10.0;
// =====================================================
// Timing
// =====================================================
unsigned long lastCloudUpdate = 0;
const unsigned long CLOUD_INTERVAL =
15000;
// =====================================================
// Structure
// =====================================================
struct TransformerData {
float voltageR;
float voltageY;
float voltageB;
float currentR;
float currentY;
float currentB;
float temperature;
float voltageImbalance;
float currentImbalance;
int faultCode;
bool tripped;
};
TransformerData data;
// =====================================================
// Read analog sensor
// =====================================================
float readAnalogAverage(int pin, int samples = 100) {
long total = 0;
for (int i = 0; i < samples; i++) {
total += analogRead(pin);
delayMicroseconds(100);
}
return (float)total / samples;
}
// =====================================================
// Convert voltage sensor reading
// =====================================================
float readVoltage(int pin) {
float adc = readAnalogAverage(pin);
// --------------------------------------------------
// Replace this with calibration equation
// --------------------------------------------------
float voltage = adc * 0.100;
return voltage;
}
// =====================================================
// Convert current sensor reading
// =====================================================
float readCurrent(int pin) {
float adc = readAnalogAverage(pin);
// --------------------------------------------------
// Replace with calibrated CT/Hall conversion
// --------------------------------------------------
float current = adc * 0.010;
return current;
}
// =====================================================
// Read temperature
// =====================================================
float readTemperature() {
temperatureSensor.requestTemperatures();
return temperatureSensor.getTempCByIndex(0);
}
// =====================================================
// Calculate imbalance
// =====================================================
float calculateImbalance(
float a,
float b,
float c) {
float average =
(a + b + c) / 3.0;
if (average <= 0.01)
return 0;
float maxValue =
max(a, max(b, c));
float minValue =
min(a, min(b, c));
return ((maxValue - minValue)
/ average) * 100.0;
}
// =====================================================
// Read all sensors
// =====================================================
void readSensors() {
data.voltageR =
readVoltage(VOLTAGE_R_PIN);
data.voltageY =
readVoltage(VOLTAGE_Y_PIN);
data.voltageB =
readVoltage(VOLTAGE_B_PIN);
data.currentR =
readCurrent(CURRENT_R_PIN);
data.currentY =
readCurrent(CURRENT_Y_PIN);
data.currentB =
readCurrent(CURRENT_B_PIN);
data.temperature =
readTemperature();
data.voltageImbalance =
calculateImbalance(
data.voltageR,
data.voltageY,
data.voltageB);
data.currentImbalance =
calculateImbalance(
data.currentR,
data.currentY,
data.currentB);
}
// =====================================================
// Protection
// =====================================================
void protectionCheck() {
data.faultCode = 0;
// -----------------------------------------------
// Overvoltage
// -----------------------------------------------
if (
data.voltageR > OVERVOLTAGE_LIMIT ||
data.voltageY > OVERVOLTAGE_LIMIT ||
data.voltageB > OVERVOLTAGE_LIMIT
) {
data.faultCode = 1;
}
// -----------------------------------------------
// Undervoltage
// -----------------------------------------------
if (
data.voltageR < UNDERVOLTAGE_LIMIT ||
data.voltageY < UNDERVOLTAGE_LIMIT ||
data.voltageB < UNDERVOLTAGE_LIMIT
) {
data.faultCode = 2;
}
// -----------------------------------------------
// Overcurrent
// -----------------------------------------------
if (
data.currentR > MAX_CURRENT ||
data.currentY > MAX_CURRENT ||
data.currentB > MAX_CURRENT
) {
data.faultCode = 3;
}
// -----------------------------------------------
// Overtemperature
// -----------------------------------------------
if (
data.temperature >= TEMPERATURE_TRIP
) {
data.faultCode = 4;
}
// -----------------------------------------------
// Voltage imbalance
// -----------------------------------------------
if (
data.voltageImbalance >
VOLTAGE_IMBALANCE_LIMIT
) {
data.faultCode = 5;
}
// -----------------------------------------------
// Current imbalance
// -----------------------------------------------
if (
data.currentImbalance >
CURRENT_IMBALANCE_LIMIT
) {
data.faultCode = 6;
}
// -----------------------------------------------
// Trip
// -----------------------------------------------
if (data.faultCode != 0) {
data.tripped = true;
digitalWrite(
TRIP_RELAY_PIN,
HIGH);
digitalWrite(
ALARM_RELAY_PIN,
HIGH);
}
}
// =====================================================
// ThingSpeak upload
// =====================================================
void sendThingSpeak() {
if (WiFi.status() != WL_CONNECTED)
return;
HTTPClient http;
String url =
String(THINGSPEAK_URL) +
"?api_key=" +
THINGSPEAK_API_KEY +
"&field1=" +
String(data.voltageR, 2) +
"&field2=" +
String(data.voltageY, 2) +
"&field3=" +
String(data.voltageB, 2) +
"&field4=" +
String(data.currentR, 2) +
"&field5=" +
String(data.currentY, 2) +
"&field6=" +
String(data.currentB, 2) +
"&field7=" +
String(data.temperature, 2) +
"&field8=" +
String(data.faultCode);
http.begin(url);
int response =
http.GET();
Serial.print(
"ThingSpeak response: ");
Serial.println(response);
http.end();
}
// =====================================================
// Send JSON to n8n
// =====================================================
void sendN8N() {
if (WiFi.status() != WL_CONNECTED)
return;
HTTPClient http;
http.begin(N8N_WEBHOOK);
http.addHeader(
"Content-Type",
"application/json");
StaticJsonDocument<1024> doc;
doc["device"] = "TX-001";
doc["voltage_r"] =
data.voltageR;
doc["voltage_y"] =
data.voltageY;
doc["voltage_b"] =
data.voltageB;
doc["current_r"] =
data.currentR;
doc["current_y"] =
data.currentY;
doc["current_b"] =
data.currentB;
doc["temperature"] =
data.temperature;
doc["voltage_imbalance"] =
data.voltageImbalance;
doc["current_imbalance"] =
data.currentImbalance;
doc["fault_code"] =
data.faultCode;
doc["tripped"] =
data.tripped;
doc["status"] =
data.tripped ?
"TRIP" :
"NORMAL";
String payload;
serializeJson(
doc,
payload);
int response =
http.POST(payload);
Serial.print(
"n8n response: ");
Serial.println(response);
http.end();
}
// =====================================================
// Reset protection
// =====================================================
void checkReset() {
if (
digitalRead(RESET_PIN) == HIGH
) {
// Only allow reset when
// conditions are safe.
readSensors();
if (
data.temperature <
TEMPERATURE_WARNING &&
data.currentR <
MAX_CURRENT * 0.8 &&
data.currentY <
MAX_CURRENT * 0.8 &&
data.currentB <
MAX_CURRENT * 0.8
) {
data.tripped = false;
data.faultCode = 0;
digitalWrite(
TRIP_RELAY_PIN,
LOW);
digitalWrite(
ALARM_RELAY_PIN,
LOW);
}
}
}
// =====================================================
// Setup
// =====================================================
void setup() {
Serial.begin(115200);
pinMode(
TRIP_RELAY_PIN,
OUTPUT);
pinMode(
ALARM_RELAY_PIN,
OUTPUT);
pinMode(
CONTACTOR_FB_PIN,
INPUT);
pinMode(
RESET_PIN,
INPUT);
digitalWrite(
TRIP_RELAY_PIN,
LOW);
digitalWrite(
ALARM_RELAY_PIN,
LOW);
temperatureSensor.begin();
WiFi.begin(
WIFI_SSID,
WIFI_PASSWORD);
Serial.print(
"Connecting to Wi-Fi");
while (
WiFi.status() != WL_CONNECTED
) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print(
"IP address: ");
Serial.println(
WiFi.localIP());
}
// =====================================================
// Main loop
// =====================================================
void loop() {
readSensors();
protectionCheck();
checkReset();
Serial.println(
"-----------------------------");
Serial.print("VR: ");
Serial.println(data.voltageR);
Serial.print("VY: ");
Serial.println(data.voltageY);
Serial.print("VB: ");
Serial.println(data.voltageB);
Serial.print("IR: ");
Serial.println(data.currentR);
Serial.print("IY: ");
Serial.println(data.currentY);
Serial.print("IB: ");
Serial.println(data.currentB);
Serial.print("Temperature: ");
Serial.println(data.temperature);
Serial.print("Fault: ");
Serial.println(data.faultCode);
if (
millis() -
lastCloudUpdate >=
CLOUD_INTERVAL
) {
sendThingSpeak();
sendN8N();
lastCloudUpdate =
millis();
}
delay(1000);
}
Espressif documents the Wi-Fi station mode used by this type of ESP32 firmware.
24. Important Improvement: RMS Measurement
For a serious three-phase monitoring project, don't simply convert one ADC average directly into voltage.
AC measurement should preferably use:
AC waveform
↓
Sampling
↓
Remove DC offset
↓
Square samples
↓
Average
↓
Square root
↓
RMS
Mathematically:
VRMS=1N∑n=1NVn2
Similarly:
IRMS=1N∑n=1NIn2
This gives a much better monitoring system.
25. Improved RMS Function
For a suitably conditioned isolated AC sensor:
float calculateRMS(
int pin,
float adcOffset,
float calibration)
{
const int samples = 1000;
double sumSquares = 0;
for (int i = 0; i < samples; i++)
{
float raw = analogRead(pin);
float value =
raw - adcOffset;
sumSquares +=
value * value;
delayMicroseconds(100);
}
float rmsADC =
sqrt(sumSquares / samples);
return rmsADC * calibration;
}
The adcOffset and calibration values must be experimentally obtained from the actual sensing circuit.
26. n8n Webhook Payload
Configure the Webhook node to receive:
{
"device": "TX-001",
"voltage_r": 230.2,
"voltage_y": 231.0,
"voltage_b": 229.8,
"current_r": 4.2,
"current_y": 4.4,
"current_b": 4.1,
"temperature": 54.2,
"fault_code": 0,
"status": "NORMAL"
}
Then create an n8n flow:
Webhook
↓
Code/Set
↓
Google Sheets
↓
Switch
├── NORMAL → END
│
└── FAULT
↓
AI Agent
↓
Alert Text
↓
Telegram
↓
Text-to-Speech
↓
Telegram Voice
27. AI Prompt for n8n
A useful system prompt for the AI Agent is:
You are an industrial transformer monitoring assistant.
Your task is to analyze telemetry from a three-phase
transformer.
Never claim that the transformer is safe unless the
measured values support that conclusion.
Never override or bypass a local protection trip.
Local ESP32 protection has priority over all AI decisions.
Analyze:
- Three-phase voltage
- Three-phase current
- Temperature
- Voltage imbalance
- Current imbalance
- Fault code
- Trip state
Classify the condition as:
NORMAL
WARNING
CRITICAL
TRIPPED
For a fault:
1. Identify the most significant abnormal parameter.
2. Compare it with the configured threshold.
3. Explain the likely condition.
4. Recommend inspection steps.
5. Clearly state that physical inspection is required
before re-energization after a trip.
Return concise output suitable for Telegram.
28. AI Agent Tools
The agent can eventually have tools such as:
AI Agent
│
├── get_current_status()
│
├── get_last_10_readings()
│
├── get_fault_history()
│
├── get_temperature_trend()
│
├── get_current_trend()
│
├── get_voltage_trend()
│
├── create_maintenance_report()
│
└── send_operator_notification()
A more advanced version could query ThingSpeak's REST API for historical data. ThingSpeak supports reading channel and field data through its REST API.
29. Example AI Conversation
Operator
/status
AI Agent
Transformer TX-001
Status: NORMAL 🟢
R voltage: 230.4 V
Y voltage: 229.8 V
B voltage: 231.1 V
R current: 4.2 A
Y current: 4.1 A
B current: 4.3 A
Temperature: 52.6 °C
Voltage imbalance: 0.57%
Current imbalance: 4.76%
No active protection fault.
Operator
Why did TX-001 trip?
AI
TX-001 tripped at 14:32.
The primary trip condition was overtemperature.
Temperature:
87.4 °C
The temperature increased together with phase
current, suggesting that transformer loading may
have contributed.
Recommended checks:
1. Check transformer loading.
2. Check cooling/ventilation.
3. Inspect connections.
4. Review current trend.
5. Do not re-energize until the cause is verified.
30. Voice Alert
The n8n flow can convert the AI response to audio:
AI response
↓
Text-to-Speech
↓
MP3/voice-compatible audio
↓
Telegram
Telegram's Bot API specifically distinguishes ordinary audio from the sendVoice method intended for voice messages.
31. Telegram Command Architecture
Recommended commands:
/status
/voltage
/current
/temperature
/history
/fault
/report
/reset
/help
Example:
User:
/temperature
AI:
TX-001 temperature = 54.7°C
Status = NORMAL
Warning threshold = 70°C
Trip threshold = 85°C
32. Remote Reset Security
I strongly recommend:
Telegram /reset
↓
AI
↓
Safety validation
↓
Is transformer locally safe?
↓
┌───────┐
│ │
NO YES
│ │
↓ ↓
Reject Request
authorized
reset
↓
Local ESP32
↓
Interlock check
↓
Reset allowed
Do not make:
Telegram /reset
↓
ESP32 relay ON
because that bypasses physical safety.
33. Schematic — Conceptual
THREE-PHASE TRANSFORMER
┌────────────────────────┐
│ │
PHASE R ───┤ │
PHASE Y ───┤ TRANSFORMER │
PHASE B ───┤ │
│ │
└────────────────────────┘
│ │ │
│ │ │
CT-R CT-Y CT-B
│ │ │
↓ ↓ ↓
┌─────────────────────────┐
│ Current Signal │
│ Conditioning / Isolation │
└────────────┬────────────┘
│
↓
ESP32 ADC
│
│
R Voltage ──[ISOLATED VOLTAGE SENSOR]──→ ADC
Y Voltage ──[ISOLATED VOLTAGE SENSOR]──→ ADC
B Voltage ──[ISOLATED VOLTAGE SENSOR]──→ ADC
│
↓
┌─────────────┐
│ ESP32 │
│ │
│ ADC │
│ Protection │
│ Wi-Fi │
└──────┬──────┘
│
┌─────────┴─────────┐
│ │
↓ ↓
Trip Relay Wi-Fi Router
│ │
↓ ↓
Contactor Internet/Cloud
│
┌────────────────┼──────────────┐
↓ ↓ ↓
ThingSpeak n8n Dashboard
│
┌──────────┼──────────┐
↓ ↓ ↓
AI Telegram Sheets
34. Relay/Contactor Protection
Conceptually:
ESP32 GPIO
│
↓
Transistor/MOSFET driver
│
↓
Relay coil
│
↓
Interposing relay
│
↓
Contactor/trip circuit
│
↓
Transformer isolation
For an actual electrical installation, the contactor/trip circuit should be engineered independently and appropriately rated.
The ESP32 should not directly drive a large contactor coil.
35. Local Web Server
The ESP32 can also expose a local page:
http://ESP32-IP/
Example:
ESP32 LOCAL DASHBOARD
Transformer: TX-001
Status: NORMAL
Voltage:
R = 230 V
Y = 231 V
B = 229 V
Current:
R = 4.2 A
Y = 4.1 A
B = 4.3 A
Temperature = 52°C
Wi-Fi = Connected
ThingSpeak = OK
n8n = OK
ESP32 Wi-Fi station mode supports connecting to an access point for Internet-connected applications.
36. Complete Data Flow
TRANSFORMER
│
↓
Sensors
│
↓
ESP32
│
┌──────────────┼──────────────┐
│ │ │
↓ ↓ ↓
Protection ThingSpeak n8n
│ │ │
↓ ↓ ↓
Trip Relay Cloud Graph AI Agent
│
┌──────────┼──────────┐
│ │ │
↓ ↓ ↓
Analysis Telegram Sheets
│
┌──────────┴──────────┐
↓ ↓
Text Alert Voice Alert
37. Fault Codes
Define a fixed fault-code table:
0 = NORMAL
1 = OVERVOLTAGE
2 = UNDERVOLTAGE
3 = OVERCURRENT
4 = OVERTEMPERATURE
5 = VOLTAGE_IMBALANCE
6 = CURRENT_IMBALANCE
7 = SENSOR_FAILURE
8 = CONTACTOR_FAILURE
9 = ESP32_COMMUNICATION_FAILURE
10 = MULTIPLE_FAULT
For multiple simultaneous faults, send a bitmask or a fault array rather than allowing one fault to overwrite another.
For example:
{
"faults": [
"OVERCURRENT",
"OVERTEMPERATURE"
]
}
38. Sensor Failure Detection
This is a very important addition.
Suppose the current sensor suddenly reports:
0 A
while the transformer is known to be energized.
The system shouldn't blindly assume the current is zero.
Implement:
Sensor reading
↓
Plausibility check
↓
Valid?
┌────┴────┐
YES NO
│ │
↓ ↓
Normal SENSOR FAULT
Examples:
ADC saturated
Negative impossible value
Disconnected sensor
Constant frozen value
Unexpected zero
Out-of-range value
39. Communication Failure Handling
If Internet fails:
Internet lost
↓
ESP32 continues
↓
Protection continues
↓
Local alarm continues
↓
Data buffered locally
↓
Internet restored
↓
Upload buffered data
Never design the protection system so that:
Wi-Fi OFF → Transformer protection OFF
40. Cloud Failure Handling
Similarly:
ThingSpeak unavailable
↓
Local protection continues
↓
n8n may still receive data
↓
Dashboard shows cloud fault
The system should have health indicators:
ESP32 🟢
Sensors 🟢
Wi-Fi 🟢
ThingSpeak 🟢
n8n 🟢
Telegram 🟢
AI Agent 🟢
41. ThingSpeak Dashboard
Recommended charts:
Chart 1:
Three-phase voltage
Chart 2:
Three-phase current
Chart 3:
Transformer temperature
Chart 4:
Voltage imbalance
Chart 5:
Current imbalance
Chart 6:
Fault code
Chart 7:
Load trend
ThingSpeak is specifically designed to aggregate, visualize and analyze live IoT data streams.
42. Project Operating Modes
Implement four modes:
NORMAL
WARNING
TRIPPED
MAINTENANCE
NORMAL
Everything within limits.
WARNING
Parameter approaching limit.
TRIPPED
Unsafe condition detected.
MAINTENANCE
Protection temporarily controlled under authorized maintenance procedures.
43. Example Warning
⚠️ TRANSFORMER WARNING
Device: TX-001
Temperature: 72.1°C
Warning limit: 70°C
Trip limit: 85°C
Current:
R = 8.8 A
Y = 8.6 A
B = 8.9 A
Recommendation:
Inspect loading and cooling conditions.
44. Example Critical Alert
🚨 CRITICAL TRANSFORMER FAULT
Device: TX-001
Fault: OVERTEMPERATURE
Temperature: 87.3°C
Trip status: ACTIVE
The local protection controller has isolated
the transformer.
Do not re-energize until the cause is inspected.
45. Google Sheets Database Design
Create columns:
Timestamp
Device_ID
Voltage_R
Voltage_Y
Voltage_B
Current_R
Current_Y
Current_B
Temperature
Frequency
Voltage_Imbalance
Current_Imbalance
Fault_Code
Status
Trip_State
AI_Severity
AI_Diagnosis
Action
Operator
This becomes your maintenance database.
46. AI Maintenance Prediction
Once sufficient historical data exists, the AI can identify patterns.
Example:
Week 1:
Temperature = 48°C
Week 2:
Temperature = 54°C
Week 3:
Temperature = 61°C
Week 4:
Temperature = 69°C
AI:
Temperature trend is increasing.
The transformer has shown a gradual increase
in operating temperature over the last four weeks.
Suggested maintenance:
Inspect cooling system and loading conditions.
This is more useful than simple threshold alarms.
47. Agentic Predictive Maintenance
Eventually:
Historical Data
↓
ThingSpeak
↓
n8n
↓
AI Agent
↓
Trend Analysis
↓
Risk Score
↓
Maintenance Recommendation
↓
Telegram
Example:
TX-001 Maintenance Risk
Temperature trend: HIGH
Current trend: MEDIUM
Voltage imbalance: LOW
Overall risk: MEDIUM
Recommended:
Cooling-system inspection within maintenance window.
48. Suggested Project Modules
For a final-year engineering project, divide the project into:
Module 1 — Transformer sensing
Measure:
V_R
V_Y
V_B
I_R
I_Y
I_B
Temperature
Module 2 — ESP32 processing
ADC
RMS
Filtering
Calibration
Fault detection
Module 3 — Local protection
Overvoltage
Undervoltage
Overcurrent
Overtemperature
Imbalance
Trip
Module 4 — IoT
Wi-Fi
ThingSpeak
n8n
Module 5 — Web dashboard
Live values
Graphs
Fault history
Device status
Module 6 — AI Agent
Diagnosis
Trend analysis
Natural-language queries
Maintenance recommendations
Module 7 — Notifications
Telegram
Text
Voice
Module 8 — Data logging
Google Sheets
Fault history
Maintenance history
49. Project Development Sequence
Don't build everything simultaneously.
Follow this sequence:
STEP 1
ESP32 basic programming
↓
STEP 2
Read temperature
↓
STEP 3
Read one voltage sensor
↓
STEP 4
Read one current sensor
↓
STEP 5
Add three-phase measurements
↓
STEP 6
Calibration
↓
STEP 7
RMS calculations
↓
STEP 8
Protection algorithm
↓
STEP 9
Relay/trip simulation
↓
STEP 10
Wi-Fi
↓
STEP 11
ThingSpeak
↓
STEP 12
n8n Webhook
↓
STEP 13
Google Sheets
↓
STEP 14
Telegram
↓
STEP 15
Voice notification
↓
STEP 16
AI Agent
↓
STEP 17
Web dashboard
↓
STEP 18
Complete integration
50. Testing Plan
Test 1 — Normal operation
VR = 230 V
VY = 230 V
VB = 230 V
IR = 4 A
IY = 4 A
IB = 4 A
Temperature = 45°C
Expected:
Status = NORMAL
Trip = OFF
Test 2 — Overtemperature
Temperature = 87°C
Expected:
Fault = OVERTEMPERATURE
Trip = ON
Telegram = ALERT
Google Sheets = LOG
AI = ANALYSIS
Test 3 — Overcurrent
IR = 12 A
Expected:
Fault = OVERCURRENT
Trip = ON
Test 4 — Voltage imbalance
VR = 230
VY = 220
VB = 230
Expected:
Voltage imbalance detected
Test 5 — Wi-Fi failure
Turn off Wi-Fi.
Expected:
Protection continues
Trip continues to work
Local alarms continue
Test 6 — n8n failure
Stop n8n.
Expected:
ESP32 protection continues
Test 7 — ThingSpeak failure
Expected:
Local protection continues
51. Final Demonstration Scenario
For your project demonstration:
SYSTEM START
↓
ESP32 connects to Wi-Fi
↓
Dashboard shows NORMAL
↓
ThingSpeak receives measurements
↓
Google Sheets logs data
↓
Simulate increasing load
↓
Current rises
↓
Temperature rises
↓
ESP32 detects fault
↓
Trip output activates
↓
ESP32 sends JSON to n8n
↓
n8n logs event
↓
AI Agent analyzes fault
↓
Telegram text alert
↓
Text-to-Speech
↓
Telegram voice alert
↓
Operator receives notification
That makes a very strong project demonstration because it shows the complete edge → cloud → automation → AI → human chain.
52. Overall System Diagram for Your Report
┌───────────────────┐
│ THREE-PHASE TX │
└─────────┬─────────┘
│
┌──────────────────┼──────────────────┐
│ │ │
Voltage Current Temperature
Sensors Sensors Sensor
│ │ │
└──────────────────┼──────────────────┘
│
↓
┌───────────────────┐
│ ESP32 │
│ │
│ Data Acquisition │
│ RMS Calculation │
│ Filtering │
│ Fault Detection │
│ Protection │
│ Wi-Fi │
└───────┬─────┬─────┘
│ │
Trip ───┘ │
│
↓
┌─────────────────┐
│ Internet │
└──────┬──────────┘
│
┌────────────────┼────────────────┐
│ │ │
↓ ↓ ↓
ThingSpeak n8n Web App
│ │
│ ┌──────┴────────┐
│ │ │
│ ↓ ↓
│ AI Agent Automation
│ │ │
│ ├──────┬────────┤
│ ↓ ↓ ↓
│ Telegram Voice Sheets
│
↓
Cloud Charts
53. Software Stack
| Layer | Technology |
|---|---|
| Microcontroller | ESP32 |
| Firmware | Arduino/C++ |
| Connectivity | Wi-Fi |
| IoT cloud | ThingSpeak |
| Automation | n8n |
| AI | LLM/AI Agent |
| Notification | Telegram Bot |
| Voice | Text-to-Speech |
| Database/log | Google Sheets |
| Web dashboard | HTML/CSS/JavaScript |
| API | HTTP/REST |
| Data format | JSON |
ESP32's current Arduino documentation provides the underlying Wi-Fi and peripheral APIs needed for the firmware layer.
54. Security Requirements
Do not put credentials directly into a public GitHub repository.
Use:
Wi-Fi password → secret
ThingSpeak Write Key → secret
n8n webhook URL → protected
Telegram Bot Token → secret
Google credentials → n8n credential store
AI API key → n8n credential store
ThingSpeak's Write API Key controls channel writes, so it should be treated as a credential.
Also use:
- HTTPS
- Authentication on custom APIs
- Device IDs
- Webhook secrets
- Rate limiting
- Telegram user authorization
- n8n credential storage
- No unrestricted remote trip/reset commands
55. Final Project Objectives
The project objectives can be written as:
- To design a real-time three-phase transformer monitoring system.
- To measure phase voltage and current using isolated sensing circuits.
- To monitor transformer temperature continuously.
- To calculate electrical parameter imbalance.
- To implement local protection using ESP32.
- To detect abnormal transformer operating conditions.
- To transmit telemetry to ThingSpeak.
- To develop a web-based IoT dashboard.
- To integrate n8n for workflow automation.
- To log transformer events in Google Sheets.
- To provide Telegram text notifications.
- To provide Telegram voice notifications.
- To implement an AI agent for fault interpretation.
- To provide historical and predictive maintenance analysis.
- To maintain local protection even during cloud/network failure.
56. Expected Results
The completed system should provide:
EXPECTED OUTPUT
┌───────────────────┐
│ TRANSFORMER │
│ MONITORING │
└─────────┬─────────┘
↓
┌─────────────────────────┐
│ Real-time measurements │
└────────────┬────────────┘
↓
ESP32
↓
┌──────────┴──────────┐
↓ ↓
LOCAL TRIP IoT DATA
│ │
↓ ↓
Transformer safe ThingSpeak
│
↓
n8n
│
┌────────────────┼──────────────┐
↓ ↓ ↓
AI Telegram Sheets
│ │ │
↓ ↓ ↓
Diagnosis Text/Voice History
57. Important Engineering Limitation
This architecture is excellent for a prototype, academic project, laboratory demonstrator, or non-safety-critical monitoring system.
For an actual utility/industrial transformer protection installation, an ESP32 + cloud/AI system should not replace certified transformer protection equipment. Protection such as overcurrent, differential, earth fault, temperature, breaker trip circuits, interlocks and emergency systems should be engineered using appropriate industrial protection hardware and standards.
The AI component should be treated as decision support and maintenance intelligence, not as the primary protection relay.
58. Recommended Final Project Name
For a university report, I would use:
“Design and Implementation of an IoT-Based Three-Phase Transformer Monitoring and Protection System Using ESP32 with ThingSpeak, n8n Automation, AI-Agentic Fault Analysis, Telegram Voice Alerts and Cloud Dashboard”
That title captures essentially the whole architecture without making the project sound like only a simple ESP32 sensor project.
Useful official documentation
If you are turning this into a final-year project report, the next logical step is to convert this architecture into a formal Chapter 1–10 project document with abstract, literature survey, block diagram, circuit/schematic, component specifications, mathematical calculations, ESP32 source code, n8n workflow design, AI-agent prompt, Telegram setup, Google Sheets setup, ThingSpeak setup, testing tables, results, conclusion, future scope, references, and viva questions/answers.








No comments:
Post a Comment