Sunday, 16 August 2026

AI Based Battery Management System for Electric Vehicles

Yes. This can be developed as a complete AI-enabled IoT Battery Management System (BMS) prototype for an Electric Vehicle, combining:

  • ESP32 for battery sensing and local protection logic
  • AI-based battery-state analysis
  • n8n as the automation/orchestration layer
  • AI Agent for natural-language battery diagnostics
  • Telegram for text and voice alerts
  • Google Sheets for historical logging
  • ThingSpeak for cloud visualization
  • ESP32-hosted web dashboard
  • Optional cloud AI dashboard
  • Fault detection, SOC estimation, temperature monitoring and predictive alerts

The architecture below is designed as a low-voltage laboratory/prototype system, not as a direct replacement for a certified EV BMS. For a real traction battery, independent hardware over-current, over-voltage, under-voltage, over-temperature and isolation protections must remain in control of the battery pack.

The current ESP32 Arduino documentation supports Wi-Fi/network communication, and the current Arduino-ESP32 documentation is based on Arduino-ESP32 3.3.11 / ESP-IDF 5.5. ThingSpeak also provides an ESP32-compatible communication library and cloud visualization/analysis facilities. n8n provides Telegram integration and AI-agent/tool functionality suitable for this architecture.


1. Project title

AI-Based IoT Battery Management System for Electric Vehicles using ESP32, n8n, AI Agent, Telegram Voice Alerts, Google Sheets and ThingSpeak

Short title

AI-BMS: Agentic IoT Battery Monitoring and Alert System


2. Abstract

The proposed project is an intelligent IoT-enabled Battery Management System designed for electric-vehicle battery monitoring and predictive maintenance.

An ESP32 microcontroller continuously measures important battery parameters such as:

  • Battery voltage
  • Battery current
  • Battery temperature
  • Individual cell voltages, where applicable
  • State of Charge (SOC)
  • State of Health (SOH)
  • Power
  • Charging/discharging condition
  • Fault condition

The ESP32 performs initial safety checks locally and transmits telemetry through Wi-Fi to an n8n automation server.

n8n acts as the central IoT workflow engine. It receives the ESP32 data, stores measurements in Google Sheets, sends telemetry to ThingSpeak, evaluates alarm conditions and passes relevant battery information to an AI Agent.

The AI Agent analyzes battery conditions and produces human-readable diagnostic information such as:

"Battery temperature is increasing while discharge current remains high. The battery should be inspected and the load reduced."

When a critical condition occurs, n8n automatically sends a Telegram notification. A text-to-speech stage can additionally convert the warning into an audio/voice notification, which is then delivered through Telegram. The n8n Telegram integration supports sending messages and audio files.

The result is an Agentic IoT BMS architecture in which the ESP32 collects physical-world data, n8n coordinates cloud automation, and the AI Agent interprets the data and assists the operator.


3. Main objectives

The project has seven major objectives.

Objective 1 — Battery sensing

Measure battery parameters using ESP32.

Objective 2 — Local BMS protection

Detect dangerous conditions immediately at the embedded-controller level.

Objective 3 — IoT connectivity

Send battery telemetry to an Internet/cloud system.

Objective 4 — AI analysis

Use an AI Agent to interpret battery measurements and identify abnormal behavior.

Objective 5 — Automated alerts

Automatically notify the user through Telegram.

Objective 6 — Historical data

Store battery measurements in Google Sheets for analysis.

Objective 7 — Visualization

Display real-time and historical measurements using ThingSpeak and an ESP32 web dashboard.


4. Overall system architecture

ELECTRIC VEHICLE BATTERY
┌──────────────┼──────────────┐
│ │ │
Voltage Current Temperature
Sensors Sensor Sensors
│ │ │
└──────────────┼──────────────┘
┌─────────────────┐
│ ESP32 │
│ │
│ ADC Processing │
│ SOC Calculation │
│ Fault Detection │
│ Local Web Page │
│ Wi-Fi │
└────────┬────────┘
Wi-Fi/HTTPS
┌─────────────────┐
│ n8n │
│ Automation │
│ Workflow Engine │
└───────┬─────────┘
┌──────────────┼──────────────┐
│ │ │
▼ ▼ ▼
Google Sheets ThingSpeak AI Agent
│ │ │
│ │ ▼
│ │ Battery Analysis
│ │ │
│ │ ▼
│ │ Recommendation
│ │ │
└──────────────┴──────────────┤
Alert Decision
┌─────────┴─────────┐
│ │
▼ ▼
Telegram Voice Alert
Message Audio

5. Agentic IoT architecture

The important distinction is that this isn't simply:

ESP32 → Telegram

Instead:

Physical Battery
ESP32
Sensor Data
n8n
AI Agent
Reasoning
Tools / Actions
├── Google Sheets
├── ThingSpeak
├── Telegram
├── Voice/TTS
└── ESP32 command/API

The AI Agent can be given tools through the n8n workflow. n8n's current documentation includes AI Agents and tools such as workflow tools, calculators and custom-code tools.


6. Hardware requirements

6.1 Main controller

ESP32 development board

Recommended:

  • ESP32 DevKit V1
  • ESP32-WROOM-32
  • ESP32-S3 if additional processing/interface capability is desired

For a student prototype, an ESP32 DevKit V1 is sufficient.


6.2 Sensors

Battery voltage

For a prototype:

  • Precision resistor voltage divider
  • ADC input of ESP32

For an actual multi-cell battery, use an appropriate battery-monitoring IC/cell-monitoring IC, not merely a resistor divider.


Current sensor

Possible options:

  • ACS712
  • ACS758
  • INA219
  • INA226
  • Hall-effect current sensor

For higher-current EV applications, use an appropriately rated isolated/Hall current sensor.


Temperature sensor

Possible options:

  • DS18B20
  • NTC thermistor
  • MCP9808
  • Battery-monitoring IC temperature inputs

For an EV battery prototype, multiple temperature points are preferable.

Example:

T1 → Cell/module 1
T2 → Cell/module 2
T3 → Battery enclosure
T4 → Power electronics

7. Example hardware block diagram

+-------------------------+
| BATTERY PACK |
| |
| +---------+ |
| | Cells | |
| +---------+ |
+-----------+-------------+
|
+----------+----------+
| |
▼ ▼
Voltage Sensor Current Sensor
│ │
└─────────┬───────────┘
Temperature
Sensors
+---------------+
| ESP32 |
| |
| ADC |
| GPIO |
| Wi-Fi |
| Web Server |
+-------+-------+
|
Wi-Fi
|
Router
|
n8n

8. Recommended prototype electrical schematic

For an educational prototype using a low-voltage battery, the arrangement can be:

BATTERY +
Fuse/PTC
├───────────────+
│ │
│ Voltage Divider
│ │
│ ▼
│ ESP32 ADC
Current
Sensor
LOAD/
CHARGER
BATTERY -
└────────────── GND
Temperature Sensor
└────────────── ESP32 GPIO
ESP32
├── Wi-Fi
├── Web Dashboard
└── HTTPS
n8n

Important

Do not connect an unknown/high-voltage EV traction battery directly to an ESP32 ADC.

For a real EV pack, use:

Cell Stack
Cell Monitoring IC
Isolation / CAN
Automotive BMS Controller
ESP32 gateway

The ESP32 should preferably be a monitoring/IoT gateway, while certified BMS hardware handles primary battery safety.


9. Sensor parameters

The system can monitor:

Parameter Example
Pack voltage 48.2 V
Current 12.5 A
Temperature 34.8 °C
Power 602.5 W
SOC 78 %
SOH 94 %
Charge/discharge DISCHARGE
Cell minimum 3.91 V
Cell maximum 4.03 V
Cell imbalance 120 mV
Fault NORMAL

10. ESP32 measurement processing

Battery power

The instantaneous battery power is:

P=V×I

For example:

Voltage = 48 V
Current = 10 A
Power = 48 × 10
= 480 W

11. SOC calculation

A basic prototype SOC can be estimated using voltage:

SOC ≈ Voltage-based estimate

However, voltage-only SOC is not reliable under dynamic EV loads.

A better prototype method is coulomb counting:

SOC(t)=SOC(t0)−C1∫I(t)dt

where:

  • C = usable battery capacity
  • I = current
  • t = time

Example:

Battery capacity = 20 Ah
Current = 5 A
Time = 1 hour
Consumed = 5 Ah
SOC decrease = 5 / 20 × 100
= 25%

A production BMS should combine coulomb counting, voltage, temperature and battery characterization rather than relying on this simple equation alone.


12. SOH estimation

State of Health can be approximated for a prototype using capacity:

SOH=CratedCmeasured×100

Example:

Rated capacity = 20 Ah
Measured capacity = 18.5 Ah
SOH = 18.5 / 20 × 100
= 92.5%

The AI layer can then classify:

SOH > 90% → Excellent
80–90% → Good
70–80% → Aging
< 70% → Service recommended

These thresholds should be configurable rather than treated as universal battery limits.


13. Battery fault detection

Create multiple levels.

Level 0 — NORMAL

Voltage NORMAL
Current NORMAL
Temperature NORMAL
SOC NORMAL

Telegram:

Battery operating normally.


Level 1 — WARNING

Examples:

Temperature > 40°C
SOC < 20%
Cell imbalance > threshold

Notification:

WARNING: Battery temperature is increasing.


Level 2 — CRITICAL

Examples:

Temperature > critical limit
Voltage outside configured limits
Over-current
Sensor failure

Notification:

CRITICAL BATTERY ALERT: Immediate inspection required.


14. Local safety logic

The most important design principle:

AI
Recommendation
n8n / Cloud
User notification

must not replace:

Battery
Local protection
Hardware BMS

The ESP32 should perform deterministic safety checks.

For example:

if (temperature > MAX_TEMP) {
fault = true;
}
if (batteryVoltage > MAX_VOLTAGE) {
fault = true;
}
if (batteryVoltage < MIN_VOLTAGE) {
fault = true;
}
if (abs(current) > MAX_CURRENT) {
fault = true;
}

The AI can explain the condition, but the AI should not be the only mechanism responsible for disconnecting a dangerous battery.


15. ESP32 software architecture

setup()
├── Initialize Serial
├── Initialize sensors
├── Initialize GPIO
├── Connect Wi-Fi
├── Start Web Server
└── Initialize timers
loop()
├── Read voltage
├── Read current
├── Read temperature
├── Calculate power
├── Calculate SOC
├── Check faults
├── Update web page
└── Send telemetry

16. ESP32 Arduino code

The following is a prototype/reference implementation. Sensor calibration constants must be adjusted to your actual hardware.

#include <WiFi.h>
#include <WebServer.h>
#include <HTTPClient.h>
// =====================================================
// WIFI
// =====================================================
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
// =====================================================
// n8n WEBHOOK
// =====================================================
const char* N8N_WEBHOOK =
"https://YOUR-N8N-DOMAIN/webhook/battery-data";
// =====================================================
// PIN DEFINITIONS
// =====================================================
#define VOLTAGE_PIN 34
#define CURRENT_PIN 35
#define TEMP_PIN 4
#define LED_PIN 2
WebServer server(80);
// =====================================================
// BATTERY PARAMETERS
// =====================================================
const float BATTERY_CAPACITY_AH = 20.0;
const float MIN_VOLTAGE = 30.0;
const float MAX_VOLTAGE = 54.6;
const float MAX_CURRENT = 30.0;
const float WARNING_TEMP = 40.0;
const float CRITICAL_TEMP = 50.0;
// =====================================================
// VARIABLES
// =====================================================
float batteryVoltage = 0.0;
float batteryCurrent = 0.0;
float batteryTemperature = 0.0;
float batteryPower = 0.0;
float soc = 100.0;
String batteryStatus = "NORMAL";
// =====================================================
// READ BATTERY VOLTAGE
// =====================================================
float readBatteryVoltage()
{
int adcValue = analogRead(VOLTAGE_PIN);
float adcVoltage =
(adcValue / 4095.0) * 3.3;
// Example divider ratio.
// CHANGE according to your hardware.
float batteryVoltage =
adcVoltage * 16.0;
return batteryVoltage;
}
// =====================================================
// READ CURRENT

The ESP32 networking approach is consistent with the current Arduino-ESP32 networking APIs; ESP32 also has an HTTP client implementation for HTTP/HTTPS communication.


17. Why send data to n8n?

Instead of putting every cloud service directly into ESP32 firmware:

ESP32
├── Telegram
├── Google
├── ThingSpeak
├── AI
└── TTS

use:

ESP32
n8n
├── AI
├── Telegram
├── Google Sheets
├── ThingSpeak
└── Voice

This makes the ESP32 firmware much simpler.

It also means API keys and cloud credentials don't need to be embedded in the ESP32 firmware.


18. n8n architecture

Create a main workflow:

┌───────────────────┐
│ Webhook Trigger │
│ /battery-data │
└─────────┬─────────┘
┌───────────────────┐
│ Validate JSON │
└─────────┬─────────┘
┌───────────────────┐
│ Calculate / │
│ Normalize Values │
└─────────┬─────────┘
├─────────────────┐
│ │
▼ ▼
Google Sheets ThingSpeak
│ │
└────────┬────────┘
Fault Decision
┌────────┴────────┐
│ │
NORMAL WARNING/
CRITICAL
AI Agent
Diagnostic Message
┌────────────┴────────────┐
│ │
▼ ▼
Telegram Text TTS Engine
Telegram Audio

19. n8n node-by-node workflow

Node 1 — Webhook

Create:

Webhook

HTTP method:

POST

Path:

battery-data

ESP32 sends:

{
"voltage": 48.20,
"current": 12.50,
"temperature": 34.80,
"power": 602.50,
"soc": 78.0,
"status": "NORMAL"
}

20. Node 2 — Validate data

Use an n8n Code node.

Example:

const d = $json;
const required = [
"voltage",
"current",
"temperature",
"power",
"soc",
"status"
];
for (const key of required) {
if (d[key] === undefined) {
throw new Error(`Missing parameter: ${key}`);
}
}
return [{
json: {
...d,
timestamp: new Date().toISOString()
}
}];

21. Node 3 — Calculate derived information

Add a Code node:

const d = $json;
let risk = "LOW";
let recommendation = "Battery operating normally.";
if (d.temperature >= 50) {
risk = "CRITICAL";
recommendation =
"Stop high-load operation and inspect the battery.";
}
else if (d.temperature >= 40) {
risk = "WARNING";
recommendation =
"Reduce battery load and monitor temperature.";
}
if (d.soc < 20) {
risk = "WARNING";
recommendation =
"Battery SOC is low. Charging should be considered.";
}
if (d.soc < 10) {
risk = "CRITICAL";
recommendation =
"Battery SOC is critically low.";
}
return [{
json: {
...d,
risk,
recommendation
}
}];

22. Google Sheets workflow

Use Google Sheets as a simple historical database.

Recommended columns:

Timestamp
Voltage
Current
Temperature
Power
SOC
SOH
Status
Risk
AI Recommendation

Example:

Timestamp Voltage Current Temp Power SOC Status
16:20 48.2 8.2 32.1 395 82 NORMAL
16:21 47.9 12.3 34.2 589 80 NORMAL
16:22 47.6 17.1 41.2 814 78 WARNING

This gives you a useful dataset for later AI/ML analysis.


23. ThingSpeak integration

ThingSpeak is useful for graphical IoT visualization. The platform supports multiple fields per channel and stores channel messages; its current licensing documentation describes a message as a write containing up to eight fields.

Create a channel such as:

Channel name

AI EV Battery Management System

Use:

Field 1 → Voltage
Field 2 → Current
Field 3 → Temperature
Field 4 → Power
Field 5 → SOC
Field 6 → SOH
Field 7 → Cell Imbalance
Field 8 → Fault Code

ThingSpeak can visualize these values as charts/gauges.


24. ThingSpeak data flow

ESP32
│ JSON
n8n
│ HTTP Request
ThingSpeak
├── Voltage chart
├── Current chart
├── Temperature chart
├── SOC chart
└── Power chart

You can alternatively have the ESP32 write directly to ThingSpeak, but routing through n8n gives you more centralized control.


25. ThingSpeak HTTP example

Conceptually:

https://api.thingspeak.com/update

with parameters such as:

api_key=YOUR_WRITE_KEY
field1=48.2
field2=12.5
field3=34.8
field4=602.5
field5=78

Do not publish your real API key in documentation, GitHub repositories or screenshots.


26. AI Agent

This is the most interesting part of the project.

The AI Agent receives:

{
"voltage": 47.6,
"current": 17.1,
"temperature": 41.2,
"power": 814,
"soc": 78,
"status": "TEMPERATURE_WARNING"
}

and produces:

Battery condition: WARNING.
The battery temperature has reached 41.2 °C
while the discharge current is 17.1 A.
Recommended action:
Reduce the load and monitor temperature.
If the temperature continues increasing,
stop the load and inspect the battery cooling system.

27. AI Agent system prompt

Configure the AI Agent with a role similar to:

You are an EV Battery Management Assistant.
Your job is to analyze battery telemetry received
from an ESP32-based IoT Battery Management System.
Monitor:
- Battery voltage
- Battery current
- Battery temperature
- Battery power
- State of Charge
- State of Health
- Battery status
- Cell imbalance
Never claim that the battery is safe solely because
the AI analysis says it is safe.
Hardware safety limits always have priority.
When a critical value is detected:
1. Clearly identify the fault.
2. Explain the likely cause.
3. Explain the severity.
4. Give a conservative recommended action.
5. Generate a short Telegram alert.
Do not invent sensor measurements.
If data is missing, state that the data is unavailable.
Use concise language for emergency notifications.

28. AI Agent tools

The AI Agent can be given tools such as:

Tool 1:
Get latest battery data
Tool 2:
Read historical battery data
Tool 3:
Read Google Sheets history
Tool 4:
Calculate battery statistics
Tool 5:
Create diagnostic report
Tool 6:
Send Telegram alert
Tool 7:
Generate voice alert
Tool 8:
Update ThingSpeak

This is what makes the system more agentic instead of merely a fixed alarm workflow.


29. Example AI conversation

User

What is the current battery condition?

AI Agent

Current battery condition: WARNING.
Voltage: 47.6 V
Current: 17.1 A
Temperature: 41.2 °C
SOC: 78%
The main concern is elevated temperature.
Recommendation:
Reduce the load and monitor the temperature.

User

Why is the battery temperature increasing?

AI Agent

Possible causes include:
1. High discharge current
2. Increased battery internal resistance
3. Insufficient cooling
4. High ambient temperature
5. Cell imbalance
Current telemetry shows 17.1 A discharge current,
so electrical loading may be contributing.
Additional historical data should be checked before
determining the root cause.

30. Telegram alert workflow

n8n's Telegram integration supports sending messages as well as audio files, which makes it suitable for both text and voice notification stages.

Workflow:

Battery Data
Fault Detection
Is fault?
/ \
NO YES
| |
END ▼
AI Agent
Alert Text
├─────────────► Telegram Text
TTS API
Audio File
Telegram Audio

31. Example Telegram message

🚨 EV BATTERY ALERT
Severity: CRITICAL
Battery temperature: 52.4 °C
Voltage: 47.1 V
Current: 22.8 A
SOC: 64%
Problem:
Battery temperature has exceeded the configured
critical threshold.
Recommendation:
Reduce/stop the load and inspect the battery cooling
and protection system.
AI-BMS

32. Voice alert

The TTS stage converts the message:

Critical battery alert.
Battery temperature has reached
fifty-two point four degrees Celsius.
Please reduce the load and inspect
the battery cooling system.

into an audio file.

Then:

n8n
TTS API
MP3/OGG
Telegram Send Audio
User's phone

33. Telegram voice interaction

You can also build the reverse direction.

USER
│ Voice message
TELEGRAM
n8n
Speech-to-Text
AI Agent
├── Read battery
├── Analyze battery
├── Read historical data
└── Generate response
Text response
TTS
Telegram Voice

This creates a conversational battery assistant.


34. Example voice conversation

User says

"How is my battery?"

Speech-to-text:

How is my battery?

AI:

Your battery is operating normally.
The current SOC is 78 percent,
temperature is 34.8 degrees Celsius,
and the battery voltage is 48.2 volts.

TTS:

Your battery is operating normally...

Telegram:

🔊 Voice response

35. ESP32 web dashboard

The ESP32 can host a local web page.

User opens:

http://ESP32-IP/

Example:

+--------------------------------------+
| AI EV BATTERY MONITOR |
+--------------------------------------+
| |
| Battery Voltage 48.2 V |
| |
| Current 12.5 A |
| |
| Temperature 34.8 °C |
| |
| Power 602 W |
| |
| SOC 78 % |
| |
| SOH 94 % |
| |
| Status NORMAL |
| |
+--------------------------------------+

The ESP32 supports HTTP/network-server functionality, so a local dashboard is practical.


36. Better web dashboard architecture

For a more advanced project:

┌─────────────────┐
│ ESP32 Web UI │
└────────┬────────┘
┌───────────┴───────────┐
│ │
▼ ▼
Local data Cloud data
│ │
│ ▼
│ ThingSpeak
│ │
└──────────┬────────────┘
AI Dashboard

37. Dashboard sections

Section 1 — Battery overview

SOC
SOH
Voltage
Current
Power

Section 2 — Temperature

T1
T2
T3
T4
Maximum temperature

Section 3 — Cell monitoring

Cell 1
Cell 2
Cell 3
...
Cell N

Section 4 — Faults

Over-voltage
Under-voltage
Over-current
Over-temperature
Sensor failure
Cell imbalance

Section 5 — AI diagnosis

AI STATUS
NORMAL
No significant abnormality detected.

38. Complete software flow

START
Initialize
ESP32
Connect Wi-Fi
Read Sensors
┌──────────┼──────────┐
▼ ▼ ▼
Voltage Current Temperature
│ │ │
└──────────┼──────────┘
Calculate Power
Calculate SOC
Fault Detection
┌──────┴──────┐
│ │
NORMAL FAULT
│ │
│ ▼
│ Local Warning
JSON
Wi-Fi
n8n
├───────────────┐
│ │
▼ ▼
Google Sheets ThingSpeak
AI Agent
Risk Analysis
Notification?
/ \
NO YES
│ │
│ ▼
│ Telegram
│ │
│ ▼
│ TTS
│ │
│ ▼
│ Telegram Voice
Repeat

39. n8n workflow 1 — telemetry ingestion

[Webhook]
[JSON Validation]
[Set Timestamp]
[Calculate Derived Values]
┌───┴────────────┐
▼ ▼
[Google Sheets] [ThingSpeak]

40. n8n workflow 2 — AI diagnosis

[Webhook / Schedule]
[Get Latest Data]
[Get Historical Data]
[AI Agent]
[Risk Classification]
[Diagnostic Report]

41. n8n workflow 3 — emergency alert

[Battery Telemetry]
[IF]
Temperature > threshold?
YES
[AI Agent]
[Generate Alert]
[Telegram Send Message]
[TTS]
[Telegram Send Audio]

42. n8n workflow 4 — periodic battery report

A Schedule Trigger can run, for example, once every hour.

[Schedule Trigger]
[Get Google Sheets History]
[AI Agent]
Generate summary
Telegram

Example:

📊 HOURLY BATTERY REPORT
Average SOC: 74%
Average temperature: 35.2°C
Maximum temperature: 42.1°C
Average current: 11.4 A
AI assessment:
Battery operation is generally normal,
but temperature increased during the
last high-load period.
Recommendation:
Monitor thermal performance.

43. Predictive maintenance

The project can be extended beyond simple threshold alarms.

Instead of:

Temperature > 50°C
ALERT

the system can analyze:

Temperature trend
+
Current trend
+
Voltage sag
+
SOC
+
Cell imbalance
+
Historical data
AI
Predicted abnormal condition

Example:

Day 1:
Temperature = 31°C
Day 7:
Temperature = 34°C
Day 14:
Temperature = 37°C
Day 21:
Temperature = 41°C

AI can detect that the thermal behavior is trending upward.


44. Voltage-sag analysis

During high current:

Battery open-circuit voltage
51.2 V
High load applied
47.8 V

Voltage drop:

ΔV=51.2−47.8ΔV=3.4V

Large voltage sag can be an indicator of:

  • high internal resistance
  • aging cells
  • high load
  • poor connections
  • low SOC

The AI should describe this as an indicator requiring further testing, rather than declaring a definitive battery failure.


45. Cell imbalance

For a multi-cell battery:

Cell 1 = 4.01 V
Cell 2 = 4.00 V
Cell 3 = 4.02 V
Cell 4 = 3.91 V

Maximum:

4.02 V

Minimum:

3.91 V

Cell difference:

4.02−3.91=0.11V

or:

110 mV

The system can generate:

WARNING
Cell voltage imbalance detected.
Maximum cell: 4.02 V
Minimum cell: 3.91 V
Difference: 110 mV

46. Recommended advanced hardware

For a serious multi-cell prototype, use:

Battery
Cell Monitoring IC
├── Cell 1
├── Cell 2
├── Cell 3
├── ...
└── Cell N
BMS Controller
├── Current
├── Temperature
├── Contactor
└── CAN
ESP32
Wi-Fi
n8n

For an EV-style system, a CAN-capable BMS architecture is preferable to measuring every high-voltage cell directly with an ESP32.


47. CAN architecture

An advanced version can use:

Battery BMS
│ CAN
CAN Transceiver
ESP32
Wi-Fi
n8n

Example CAN messages:

0x180
Voltage
Current
0x181
SOC
SOH
0x182
Temperature 1
Temperature 2
0x183
Cell minimum
Cell maximum

This makes the ESP32 an IoT gateway rather than the primary safety controller.


48. AI decision architecture

A good design uses three levels of intelligence.

Level 1 — Hardware protection

Fuse
BMS
Over-current protection
Over-temperature protection
Contactor

Level 2 — ESP32 deterministic logic

Threshold checks
Sensor validation
Communication watchdog
Local fault detection

Level 3 — AI

Trend analysis
Natural-language diagnosis
Historical correlation
Predictive maintenance
Operator assistance

This is much safer than allowing an LLM to directly control battery safety functions.


49. AI fault classification

Create a classification model:

Battery State
┌─────────────┼─────────────┐
│ │ │
NORMAL WARNING CRITICAL
│ │ │
▼ ▼ ▼
Continue Monitor Immediate
operation condition intervention

50. Example rule matrix

Parameter Normal Warning Critical
Temperature <40°C 40–50°C ≥50°C
SOC >20% 10–20% <10%
Cell imbalance Low Moderate High
Current Normal High Over-current
Voltage Normal Near limit Outside limit

These numbers are example prototype values only. The actual limits must come from the battery chemistry, cell configuration, BMS manufacturer and applicable safety requirements.


51. Google Sheets data structure

Create a sheet named:

Battery_Log

Columns:

A: Timestamp
B: Voltage
C: Current
D: Temperature
E: Power
F: SOC
G: SOH
H: Cell_Min
I: Cell_Max
J: Cell_Imbalance
K: Status
L: Risk
M: AI_Diagnosis
N: Recommendation

This also creates a useful dataset for later machine-learning research.


52. Dataset for AI/ML

After several weeks/months:

Google Sheets
CSV
Python
Data Cleaning
Feature Engineering
ML Model

Potential features:

Voltage
Current
Temperature
SOC
Power
Voltage sag
Temperature rate
Current rate
Cell imbalance
Charge cycles

Possible models:

Random Forest
XGBoost
Logistic Regression
Isolation Forest
LSTM
Autoencoder

53. Anomaly detection

A particularly useful extension is an anomaly model.

Normal behavior:

Temperature
30 → 31 → 31 → 32 → 32

Abnormal:

Temperature
30 → 31 → 35 → 41 → 48

The model can calculate:

Anomaly Score = 0.92

Then:

Anomaly Score > 0.80
AI investigation
Telegram alert

54. Full agentic interaction

The final system can behave like this:

USER
│ "Battery status?"
Telegram
n8n
AI Agent
├── Get latest battery
├── Get last 24-hour history
├── Calculate temperature trend
├── Check cell imbalance
└── Generate diagnosis
AI response
├── Telegram text
└── Telegram voice

55. Example complete conversation

User

Battery status?

Agent

Battery status: NORMAL.
Voltage: 48.2 V
Current: 8.4 A
Temperature: 33.2 °C
SOC: 81%
SOH: 95%
No significant abnormality detected.

User

Is the battery getting hotter?

Agent

Yes.
The temperature increased from 31.5 °C
to 38.7 °C over the last 20 minutes.
The increase coincides with higher discharge current.
Recommendation:
Reduce the load if temperature continues increasing.

User

Send me a voice alert if it gets above 45 degrees.

Agent

Understood.
The automation threshold will be 45 °C for the
configured warning workflow.
When triggered, the system will send a Telegram
text notification and voice alert.

For a real safety implementation, however, the actual battery protection threshold should be implemented independently in the BMS hardware/firmware rather than delegated to the AI agent.


56. Security architecture

Do not put these in ESP32 source code if avoidable:

Telegram Bot Token
OpenAI/API keys
Google credentials
ThingSpeak write key
n8n authentication secrets

Use:

ESP32
│ HTTPS
n8n
├── Credentials
├── API keys
└── Cloud services

ESP32's HTTP client supports HTTPS, with certificate verification configurable through the ESP-IDF HTTP/TLS facilities.


57. n8n security

Recommended:

Internet
HTTPS
Reverse Proxy
n8n
├── Authentication
├── Credentials
└── Webhook

Possible deployment:

Docker
+
n8n
+
HTTPS reverse proxy

n8n supports cloud and self-hosted deployment approaches.


58. Recommended project folder structure

AI-EV-BMS/
├── ESP32/
│ ├── AI_EV_BMS.ino
│ ├── sensors.h
│ ├── sensors.cpp
│ ├── wifi.h
│ └── dashboard.h
├── n8n/
│ ├── telemetry-workflow.json
│ ├── alert-workflow.json
│ ├── ai-agent-workflow.json
│ └── report-workflow.json
├── dashboard/
│ ├── index.html
│ ├── style.css
│ └── dashboard.js
├── documentation/
│ ├── project-report.md
│ ├── architecture.md
│ ├── hardware.md
│ └── testing.md
└── datasets/
└── battery_data.csv

59. Development procedure

Phase 1 — ESP32

  1. Install Arduino IDE.
  2. Install ESP32 board support.
  3. Connect ESP32.
  4. Test Serial Monitor.
  5. Test Wi-Fi.
  6. Read battery voltage.
  7. Read current.
  8. Read temperature.
  9. Calculate power.
  10. Calculate SOC.
  11. Implement fault detection.

The current ESP32 Arduino core documentation provides the board/software reference and Wi-Fi APIs.


Phase 2 — Local dashboard

  1. Start ESP32 web server.
  2. Create HTML dashboard.
  3. Display voltage.
  4. Display current.
  5. Display temperature.
  6. Display SOC.
  7. Display status.
  8. Add automatic refresh.
  9. Add graphs.

Phase 3 — n8n

  1. Install n8n.
  2. Create credentials.
  3. Create webhook.
  4. Send ESP32 JSON to webhook.
  5. Validate received data.
  6. Store data.
  7. Add fault logic.

Phase 4 — Google Sheets

  1. Create Google Sheet.
  2. Connect Google credentials.
  3. Add Google Sheets node.
  4. Map sensor values.
  5. Test historical logging.

Phase 5 — ThingSpeak

  1. Create ThingSpeak account.
  2. Create channel.
  3. Configure eight fields.
  4. Obtain API keys.
  5. Connect n8n using HTTP Request.
  6. Send battery telemetry.
  7. Create charts.

ThingSpeak is specifically designed to aggregate, visualize and analyze IoT data, and its Arduino library supports ESP32.


Phase 6 — AI

  1. Configure AI model credentials.
  2. Add AI Agent.
  3. Create system prompt.
  4. Pass battery telemetry.
  5. Add historical-data tool.
  6. Add calculation tool.
  7. Generate diagnostic response.
  8. Test abnormal conditions.

Phase 7 — Telegram

  1. Create Telegram bot.
  2. Configure Telegram credentials.
  3. Connect Telegram node.
  4. Send normal status.
  5. Send warning.
  6. Send critical alert.
  7. Add audio/TTS.
  8. Send voice alert.

The n8n Telegram node supports message and audio operations.


60. Testing procedure

Do not initially test using a high-energy EV battery.

Use:

Low-voltage laboratory battery
+
Current-limited supply/load

Test cases:

Test 1 — Normal

Voltage = normal
Current = normal
Temperature = normal

Expected:

NORMAL

Test 2 — High temperature

Simulate:

Temperature = 42°C

Expected:

WARNING

Telegram:

⚠️ Temperature Warning

Test 3 — Critical temperature

Simulate:

Temperature = 52°C

Expected:

CRITICAL

Telegram:

🚨 CRITICAL BATTERY ALERT

Voice:

Critical battery temperature alert.

Test 4 — Low SOC

SOC = 15%

Expected:

LOW SOC WARNING

Test 5 — Under-voltage

Voltage < configured minimum

Expected:

UNDER-VOLTAGE

Test 6 — Over-current

Current > configured limit

Expected:

OVER-CURRENT

Test 7 — Internet failure

Disconnect Wi-Fi.

Expected:

ESP32 continues local monitoring.

This is extremely important.

Cloud failure must not disable local battery protection.


61. Communication failure design

ESP32
┌───────┴────────┐
│ │
Sensors Wi-Fi
│ │
▼ ▼
Local Safety n8n
Cloud Services

If:

Wi-Fi = DOWN

then:

Sensors
ESP32
Local safety continues

When Wi-Fi returns:

ESP32
n8n
Cloud synchronization

62. Watchdog design

Implement:

Sensor watchdog
Wi-Fi watchdog
n8n communication timeout
ESP32 watchdog

Example:

if (millis() - lastCloudSend > 60000) {
cloudConnected = false;
}

But never interpret loss of cloud connectivity as permission to continue an unsafe battery state.


63. Expected final result

The final demonstration can look like:

AI EV BMS
┌──────────────┼──────────────┐
│ │ │
▼ ▼ ▼
ESP32 n8n ThingSpeak
│ │ │
│ ▼ ▼
│ AI Agent Graphs
│ │
│ ┌─────┴─────┐
│ │ │
│ ▼ ▼
│ Telegram Google
│ Text Sheets
│ │
│ ▼
│ TTS
│ │
│ ▼
│ Telegram
│ Voice
Local Web Dashboard

64. Final project features

Your finished project can claim the following features:

Hardware

  • ESP32-based controller
  • Battery voltage monitoring
  • Current monitoring
  • Temperature monitoring
  • SOC estimation
  • SOH estimation
  • Fault detection
  • Wi-Fi communication
  • Local web dashboard

IoT

  • ESP32 → n8n
  • n8n → ThingSpeak
  • n8n → Google Sheets
  • n8n → Telegram

AI

  • AI battery diagnosis
  • Historical analysis
  • Trend analysis
  • Anomaly detection
  • Natural-language battery assistant
  • Predictive-maintenance capability

Agentic AI

  • AI Agent
  • Tool-based data retrieval
  • Automated diagnostic workflow
  • User conversational interface
  • Telegram interaction
  • Voice response

Alerts

  • Normal notification
  • Warning notification
  • Critical notification
  • Telegram text
  • Telegram audio/voice

65. Suggested project title for academic submission

“Design and Implementation of an AI-Powered IoT Battery Management System for Electric Vehicles Using ESP32, n8n Automation, Telegram Voice Alerts, Google Sheets and ThingSpeak Cloud Monitoring”


66. Suggested problem statement

The increasing adoption of electric vehicles requires reliable monitoring of battery operating conditions such as voltage, current, temperature, State of Charge and State of Health. Conventional battery monitoring systems generally provide sensor measurements and threshold-based protection but offer limited intelligent interpretation and user interaction.

This project proposes an AI-powered IoT Battery Management System using an ESP32 as the sensing and communication controller. The system transmits battery telemetry to an n8n automation platform, where the information is stored, visualized and analyzed. Google Sheets provides historical data storage, ThingSpeak provides cloud visualization, and an AI Agent interprets battery conditions and generates diagnostic recommendations. Telegram provides real-time text and voice alerts to the user.

The proposed system combines embedded sensing, IoT automation, cloud monitoring and AI-based decision support into a unified architecture.


67. Suggested innovation

The key innovation is:

Combining embedded battery monitoring with an agentic AI automation layer rather than using the ESP32 only as a conventional sensor node.

The ESP32 handles:

Sensing + local deterministic protection

n8n handles:

Automation + integration

AI handles:

Reasoning + interpretation + recommendations

Cloud platforms handle:

Storage + visualization

Telegram handles:

Human notification + conversational interface

68. Final architecture in one diagram

┌───────────────────────┐
│ EV BATTERY │
│ │
│ Cells / Battery Pack │
└───────────┬───────────┘
┌────────────────┼────────────────┐
│ │ │
▼ ▼ ▼
Voltage Current Temperature
Sensor Sensor Sensors
│ │ │
└────────────────┼────────────────┘
┌──────────────────────┐
│ ESP32 │
│ │
│ Sensor Acquisition │
│ SOC Estimation │
│ Local Fault Logic │
│ Wi-Fi │
│ Web Dashboard │
└──────────┬───────────┘
HTTPS
┌──────────────────────┐
│ n8n │
│ Automation Platform │
└──────────┬───────────┘
┌──────────────────────┼──────────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│Google Sheets │ │ ThingSpeak │ │ AI Agent │
│ │ │ │ │ │
│ Historical │ │ Cloud Charts │ │ Diagnosis │
│ Data │ │ & Analytics │ │ Prediction │
└──────────────┘ └──────────────┘ └───────┬──────┘
┌─────────────────┐
│ Risk / Decision │
└────────┬────────┘
┌───────────────┼───────────────┐
│ │ │
▼ ▼ ▼
Telegram TTS API Dashboard
Text Alert Voice Status
│ │
│ ▼
│ Telegram Audio
└───────────────┐
USER / DRIVER

69. Important practical recommendation

For your college/project demonstration, I would build it in this order:

ESP32 + sensors → local web page → n8n webhook → Google Sheets → ThingSpeak → AI Agent → Telegram text → TTS → Telegram voice → predictive analytics.

That gives you a working result at every stage instead of trying to build the entire system simultaneously.

For the first prototype, use a safe low-voltage battery/load setup. For a genuine EV traction battery, use an appropriate certified BMS/cell-monitoring architecture and make the ESP32 the IoT/AI gateway; do not make an LLM or cloud workflow the primary safety controller.

Useful official references

If implemented as described, this becomes a strong final-year/major-project architecture because it combines embedded systems + EV/BMS + IoT + cloud + workflow automation + generative AI + agentic AI + voice notification + data analytics rather than being only an ESP32 sensor project.

No comments:

Post a Comment