AI-Based Smart Battery Management System (BMS) for EV Applications
Using ESP32 + Agentic AI + IoT + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard
AI-Based Smart Battery Management System (BMS) for EV Applications
Using ESP32 + Agentic AI + IoT + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard
1. Project Overview
Project Title
AI-Based Smart Battery Management System for Electric Vehicle Applications Using ESP32, Agentic AI, n8n Automation, Telegram Voice Notifications, Google Sheets, and ThingSpeak Cloud Analytics
Objective
Develop a smart battery monitoring and predictive maintenance system for EV batteries that:
Monitors battery voltage, current, temperature, and State of Charge (SOC)
Uploads data to cloud platforms
Uses AI to predict battery health and power consumption
Sends real-time Telegram notifications
Generates voice alerts automatically
Stores historical data in Google Sheets
Displays live dashboard on ThingSpeak
Uses n8n as an intelligent automation engine
Supports future EV fleet management
2. System Architecture
Battery Pack
│
▼
Voltage Sensor
Current Sensor
Temperature Sensor
│
▼
ESP32
│
├────────► ThingSpeak Dashboard
│
├────────► n8n Webhook
│
│ ▼
│ AI Prediction Agent
│ ▼
│ Decision Engine
│
├────────► Google Sheets
│
▼
Telegram Bot
│
▼
Voice Alert Message
3. Features
Real-Time Monitoring
Battery Voltage
Battery Current
Battery Temperature
State of Charge (SOC)
AI Functions
Battery Health Prediction
Remaining Runtime Estimation
Power Consumption Forecasting
Fault Detection
IoT Features
Cloud Dashboard
Data Logging
Remote Monitoring
Automation Features
Telegram Alerts
Voice Notifications
Google Sheets Logging
AI Recommendations
4. Hardware Components
Component Quantity
ESP32 Dev Board 1
INA219 Current Sensor 1
Voltage Divider Circuit 1
DS18B20 Temperature Sensor 1
EV Battery Pack (12V/24V/48V) 1
OLED Display (Optional) 1
Jumper Wires Several
Breadboard/PCB 1
WiFi Router 1
5. Sensor Selection
INA219 Current Sensor
Measures:
Voltage
Current
Power
Communication:
I2C Protocol
DS18B20 Temperature Sensor
Measures:
Battery Temperature
Range:
-55°C to +125°C
Voltage Divider
Converts:
48V Battery
↓
3.3V ESP32 ADC
Formula:
V
out
=V
in
×
R
1
+R
2
R
2
Example:
R1 = 100kΩ
R2 = 10kΩ
6. Circuit Schematic
Battery +
│
├── Voltage Divider ── GPIO34
Battery +
│
└── INA219 Sensor
INA219
SDA → GPIO21
SCL → GPIO22
DS18B20
DATA → GPIO4
VCC → 3.3V
GND → GND
ESP32
Connected to WiFi
7. Pin Configuration
Device ESP32 Pin
INA219 SDA GPIO21
INA219 SCL GPIO22
DS18B20 Data GPIO4
Voltage Sensor GPIO34
8. Working Principle
Step 1
ESP32 reads:
Voltage
Current
Temperature
Step 2
Calculates:
Battery Power
State of Charge
Power Formula:
P=V×I
Step 3
Uploads data to:
ThingSpeak
n8n Webhook
Step 4
n8n receives data
Example:
{
"voltage": 48.5,
"current": 12.4,
"temperature": 35,
"soc": 82
}
Step 5
AI Agent analyzes battery condition
Possible outputs:
Battery Healthy
Battery Overheating
High Power Consumption
Low SOC Warning
Step 6
Telegram Voice Alert Sent
Example:
Warning!
Battery Temperature is 48°C.
Please stop charging immediately.
9. State of Charge Calculation
Simple SOC estimation:
SOC=
V
max
−V
min
V
battery
−V
min
×100
Example:
Battery Voltage = 48V
SOC = 80%
10. AI Power Consumption Prediction
Inputs
Voltage
Current
Temperature
Historical Usage
AI Logic
Dataset:
Voltage
Current
Temperature
SOC
Runtime
Model:
Linear Regression
Random Forest
LSTM
Prediction:
Expected Runtime Remaining
Power Consumption Trend
Battery Health Score
Pseudo Logic
if temperature > 45:
health_score -= 20
if current > threshold:
health_score -= 10
if soc < 20:
alert = True
11. ESP32 Source Code
#include
#include
#include
#include
const char* ssid="YOUR_WIFI";
const char* password="YOUR_PASSWORD";
String apiKey="THINGSPEAK_API_KEY";
Adafruit_INA219 ina219;
float voltage;
float current;
float power;
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED)
{
delay(500);
}
ina219.begin();
}
void loop()
{
voltage=ina219.getBusVoltage_V();
current=ina219.getCurrent_mA()/1000;
power=voltage*current;
sendThingSpeak();
sendn8n();
delay(15000);
}
ThingSpeak Upload Function
void sendThingSpeak()
{
HTTPClient http;
String url=
"http://api.thingspeak.com/update?api_key="+
apiKey+
"&field1="+String(voltage)+
"&field2="+String(current)+
"&field3="+String(power);
http.begin(url);
http.GET();
http.end();
}
n8n Webhook Function
void sendn8n()
{
HTTPClient http;
http.begin(
"https://your-n8n-server/webhook/battery");
http.addHeader(
"Content-Type",
"application/json");
String data=
"{\"voltage\":"+String(voltage)+
",\"current\":"+String(current)+
"}";
http.POST(data);
http.end();
}
12. n8n Workflow Design
Workflow Nodes
Webhook
↓
Set Data
↓
AI Analysis
↓
IF Condition
↓
Telegram Alert
↓
Google Sheets
Detailed Flow
Webhook Node
Receives sensor data.
Example:
{
"voltage":48,
"current":10,
"temperature":36,
"soc":75
}
AI Agent Node
Prompt:
Analyze battery data.
Voltage: {{$json.voltage}}
Current: {{$json.current}}
Temperature: {{$json.temperature}}
SOC: {{$json.soc}}
Give:
1. Health Score
2. Remaining Runtime
3. Recommendation
IF Node
Condition:
Temperature > 45°C
OR
SOC < 20%
Telegram Node
Message:
⚠️ Battery Alert
Voltage: 48V
SOC: 15%
Action Required
13. n8n Workflow JSON (Simplified)
{
"nodes": [
{
"name": "Webhook"
},
{
"name": "AI Agent"
},
{
"name": "Telegram"
},
{
"name": "Google Sheets"
}
]
}
14. Telegram Bot Setup
Step 1
Open Telegram.
Search:
Telegram
Step 2
Search:
@BotFather
Step 3
Create Bot
/newbot
Step 4
Copy:
BOT TOKEN
Example:
123456:ABCXYZ
Step 5
Add token to n8n Telegram node.
15. Voice Notification Automation
Method
Use Text-To-Speech API.
Workflow:
AI Alert
↓
Google TTS
↓
Audio File
↓
Telegram Send Voice
Voice Example:
Attention!
Battery temperature exceeds safe limit.
Please inspect immediately.
16. Google Sheets Integration
Create Sheet:
Battery Monitoring Log
Columns:
Timestamp Voltage Current Temp SOC Health
n8n Node
Google Sheets Node
Action:
Append Row
Stored Data Example
2026-06-11
48.4
10.3
35
80
Healthy
17. ThingSpeak Dashboard Setup
Step 1
Create account on ThingSpeak
Step 2
Create New Channel
Fields:
Field1 Voltage
Field2 Current
Field3 Temperature
Field4 SOC
Field5 Health Score
Step 3
Enable Public Dashboard
Step 4
Add Widgets
Gauge
Line Chart
Battery Indicator
Temperature Trend
18. Agentic AI Decision Engine
AI evaluates:
Battery Health
Charging Pattern
Discharge Pattern
Thermal Condition
Decision Rules:
if temp > 45:
send_alert()
if soc < 20:
send_alert()
if health < 70:
maintenance_required()
19. Future Enhancements
Advanced AI
LSTM Battery Degradation Prediction
Predictive Maintenance
Remaining Useful Life (RUL)
EV Fleet Management
Monitor:
100+
Vehicles
through one dashboard.
Mobile App
Features:
Live Battery Status
Notifications
Maintenance Alerts
Route-Based Energy Prediction
Digital Twin
Create virtual battery model for simulation.
20. Project Execution Guide (Step-by-Step)
Phase 1: Hardware Setup
Assemble ESP32.
Connect INA219.
Connect DS18B20.
Connect voltage divider.
Verify sensor readings.
Phase 2: Cloud Setup
Create ThingSpeak channel.
Obtain Write API Key.
Test data upload.
Phase 3: n8n Setup
Install n8n.
Create Webhook.
Create AI Agent node.
Configure Telegram node.
Configure Google Sheets node.
Phase 4: AI Integration
Collect battery data.
Train prediction model.
Deploy model API.
Connect API to n8n.
Phase 5: Testing
Simulate low SOC.
Simulate overheating.
Verify alerts.
Verify voice notifications.
Verify cloud logging.
Phase 6: Deployment
Install in EV battery enclosure.
Enable Wi-Fi/4G connectivity.
Secure API endpoints.
Monitor dashboard.
Perform periodic calibration.
Expected Project Outcomes
Real-time EV battery monitoring
AI-based battery health prediction
Automatic Telegram voice alerts
Cloud-based analytics dashboard
Historical logging in Google Sheets
Predictive maintenance recommendations
Industry-ready Agentic IoT architecture suitable for smart EVs, e-bikes, solar battery banks, and fleet management systems.

Comments
Post a Comment