IoT Based 12V Battery Monitoring System with ESP8266
IoT Based 12V Lead-Acid Battery Monitoring System with ESP8266 to monitor Battery Voltage, Load Voltage, Current & Power on ThingSpeak Server
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelIntermediate
- Available atAjvika Labs, Kakinada
About this project
Overview:
In this project, we will build an
IoT-based 12V Battery Monitoring System
using
ESP8266
and
INA226
DC Current Sensor. This system is specifically designed for monitoring
lead-acid batteries
, which are widely used in automotive, solar, and other high-capacity applications. The primary goal of this system is to ensure the
optimal performance
and
longevity
of the battery by preventing
overcharging
or excessive
discharging
, which can lead to battery damage or system failure.
In this setup, we are using the
INA226 sensor
, a high-precision current and power monitor, to provide accurate readings of the
battery’s voltage
, load voltage,
current
, and
power
. These readings are crucial for maintaining the
health
and
efficiency
of the battery. The ESP8266, a low-cost Wi-Fi microchip with full TCP/IP stack and
microcontroller
capability, is used to send this data to the
ThingSpeak server
The ThingSpeak server, an open-source
Internet of Things (IoT)
application and
API
, is used to collect and store sensor data in the cloud and develop IoT applications. This allows users to monitor the
battery status
remotely from anywhere in the world via their smartphones or computer dashboards. The server displays the battery voltage, load voltage, current, and power, providing a comprehensive overview of the
battery’s condition
in both charging and discharging states.
Check our previous similar project for 3.7V Lithium-Ion/Lithium-Polymer Batteries:
IoT Based Battery Status Monitoring System using ESP8266
IoT Battery Monitoring System with DIY LiPo Charger
Bill of Materials:
The following are the components required for building the IoT-Based 12V Battery Monitoring System Project.
S.N.
Components
Quantity
Purchase Links
NodeMCU ESP8266 or Wemos D1 Mini Board
Amazon
AliExpress
SunFounder
INA226 Current Sensor
Amazon
AliExpress
Jumper Wires
Amazon
AliExpress
SunFounder
Breadboard
Amazon
AliExpress
SunFounder
Micro-USB Cable
Amazon
AliExpress
12V Lead-Acid Battery
Amazon
AliExpress
Circuit Design & Schematic:
Let us move to the project part. We could have used
INA219 Current Sensor
for this project, but INA226 has voltage limitations of 26V and the maximum current it can measure is ±3.2A.
The
INA226
can measure the voltage up to
36V
and the current up to
30A
. The current setting is based on the shunt resistance that needs to be changed based on current requirements. Follow the
INA226 Interfacing Guide
for learning more about current settings.
Let us take a look at the schamtic of IoT Based 12V Battery Monitoring System with ESP8266.
The
SDA
and
SCL
pins of INA226 are connected to the D2 & D1 pins of the ESP8266 Board. The
Vin+
pin should be connected to a power source and the
Vin-
to the load as shown in the design schematic. The INA226 Sensor has VBus Pin, which is used to measure the Load Voltage. Therefore we need to connect the
VBus
pin to Vin- pin.
You may use a breadboard for connection or design your own custom PCB.
Setting up Thingspeak
In order to Monitor the
Battery Data
on Thingspeak Server, you first need to Setup the
Thingspeak
. To set up the Thingspeak Server, visit
https://thingspeak.com/
. Create an account or simply sign in if you created the account earlier. Then create a new channel with following details.
The parameters that we are gonna measure is Battery Voltage, Load Voltage, Current and Power. Therefore, we need to create a 4 parameters.
Then go to the API section of the dashboard and copy the
API Key
. This API key is needed in the code part.
Now your Thingspeak account setup is complete.
Source Code/Program
Let us move to the programming part of IoT Based 12V Battery Monitoring System with ESP8266. The code requires
INA226 Library
for compilation. First add the library to the Arduino IDE.
From the following lines, change the WiFi SSID, Password & Thingspeak API Key.
String
apiKey
=
"**********"
;
const
char
*
ssid
=
"**********"
;
// Enter your WiFi Network's SSID
const
char
*
pass
=
"**********"
;
// Enter your WiFi Network's Password
Here is a complete code for this project.
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <INA226_WE.h>
#define I2C_ADDRESS 0x40
String
apiKey
=
"**********"
;
const
char
*
ssid
=
"**********"
;
// Enter your WiFi Network's SSID
const
char
*
pass
=
"**********"
;
// Enter your WiFi Network's Password
const
char
*
server
=
"api.thingspeak.com"
;
INA226_WE
ina226
=
INA226_WE
(
I2C_ADDRESS
)
;
WiFiClient
client
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
;
// wait until serial comes up on Arduino Leonardo or MKR WiFi 1010
Wire
begin
(
)
;
ina226
init
(
)
;
/* Set Resistor and Current Range
if resistor is 5.0 mOhm, current range is up to 10.0 A
default is 100 mOhm and about 1.3 A*/
ina226
setResistorRange
(
0.1
1.3
)
;
// choose resistor 0.1 Ohm and gain range up to 1.3A
/* If the current values delivered by the INA226 differ by a constant factor
from values obtained with calibrated equipment you can define a correction factor.
Correction factor = current delivered from calibrated equipment / current delivered by INA226*/
ina226
setCorrectionFactor
(
0.93
)
;
Serial
println
(
"INA226 Current Sensor Example Sketch - Continuous"
)
;
ina226
waitUntilConversionCompleted
(
)
;
//if you comment this line the first data might be zero
Serial
println
(
"Connecting to "
)
;
Serial
println
(
ssid
)
;
WiFi
begin
(
ssid
pass
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
delay
(
)
;
Serial
(
"*"
)
;
}
Serial
println
(
""
)
;
Serial
println
(
"WiFi connected"
)
;
}
void
loop
(
)
{
float
shuntVoltage_mV
=
0.0
;
float
loadVoltage_V
=
0.0
;
float
batteryVoltage_V
=
0.0
;
float
current_mA
=
0.0
;
float
power_mW
=
0.0
;
ina226
readAndClearFlags
(
)
;
shuntVoltage_mV
=
ina226
getShuntVoltage_mV
(
)
;
batteryVoltage_V
=
ina226
getBusVoltage_V
(
)
;
current_mA
=
ina226
getCurrent_mA
(
)
;
power_mW
=
ina226
getBusPower
(
)
;
loadVoltage_V
=
batteryVoltage_V
+
(
shuntVoltage_mV
/
1000
)
;
Serial
(
"Battery Voltage"
)
;
Serial
(
batteryVoltage_V
)
;
Serial
println
(
"V"
)
;
Serial
(
"Load Voltage: "
)
;
Serial
(
loadVoltage_V
)
;
Serial
println
(
"V"
)
;
Serial
(
"Current: "
)
;
Serial
(
current_mA
)
;
Serial
println
(
"mA"
)
;
Serial
(
"Power: "
)
;
Serial
(
power_mW
)
;
Serial
println
(
"mW"
)
;
if
(
!
ina226
overflow
)
{
Serial
println
(
"Values OK - no overflow"
)
;
}
else
{
Serial
println
(
"Overflow! Choose higher current range"
)
;
}
if
(
client
connect
(
server
)
)
{
String
postStr
=
apiKey
;
postStr
+=
"&field1="
;
postStr
+=
String
(
batteryVoltage_V
)
;
postStr
+=
"&field2="
;
postStr
+=
String
(
loadVoltage_V
)
;
postStr
+=
"&field3="
;
postStr
+=
String
(
current_mA
)
;
postStr
+=
"&field4="
;
postStr
+=
String
(
power_mW
)
;
postStr
+=
"\r\n\r\n\r\n\r\n"
;
client
(
"POST /update HTTP/1.1\n"
)
;
delay
(
)
;
client
(
"Host: api.thingspeak.com\n"
)
;
delay
(
)
;
client
(
"Connection: close\n"
)
;
delay
(
)
;
client
(
"X-THINGSPEAKAPIKEY: "
+
apiKey
+
"\n"
)
;
delay
(
)
;
client
(
"Content-Type: application/x-www-form-urlencoded\n"
)
;
delay
(
)
;
client
(
"Content-Length: "
)
;
delay
(
)
;
client
(
postStr
length
(
)
)
;
delay
(
)
;
client
(
"\n\n\n\n"
)
;
delay
(
)
;
client
(
postStr
)
;
delay
(
)
;
}
client
stop
(
)
;
Serial
In this project, we will build an
IoT-based 12V Battery Monitoring System
using
ESP8266
and
INA226
DC Current Sensor. This system is specifically designed for monitoring
lead-acid batteries
, which are widely used in automotive, solar, and other high-capacity applications. The primary goal of this system is to ensure the
optimal performance
and
longevity
of the battery by preventing
overcharging
or excessive
discharging
, which can lead to battery damage or system failure.
In this setup, we are using the
INA226 sensor
, a high-precision current and power monitor, to provide accurate readings of the
battery’s voltage
, load voltage,
current
, and
power
. These readings are crucial for maintaining the
health
and
efficiency
of the battery. The ESP8266, a low-cost Wi-Fi microchip with full TCP/IP stack and
microcontroller
capability, is used to send this data to the
ThingSpeak server
The ThingSpeak server, an open-source
Internet of Things (IoT)
application and
API
, is used to collect and store sensor data in the cloud and develop IoT applications. This allows users to monitor the
battery status
remotely from anywhere in the world via their smartphones or computer dashboards. The server displays the battery voltage, load voltage, current, and power, providing a comprehensive overview of the
battery’s condition
in both charging and discharging states.
Check our previous similar project for 3.7V Lithium-Ion/Lithium-Polymer Batteries:
IoT Based Battery Status Monitoring System using ESP8266
IoT Battery Monitoring System with DIY LiPo Charger
Bill of Materials:
The following are the components required for building the IoT-Based 12V Battery Monitoring System Project.
S.N.
Components
Quantity
Purchase Links
NodeMCU ESP8266 or Wemos D1 Mini Board
Amazon
AliExpress
SunFounder
INA226 Current Sensor
Amazon
AliExpress
Jumper Wires
Amazon
AliExpress
SunFounder
Breadboard
Amazon
AliExpress
SunFounder
Micro-USB Cable
Amazon
AliExpress
12V Lead-Acid Battery
Amazon
AliExpress
Circuit Design & Schematic:
Let us move to the project part. We could have used
INA219 Current Sensor
for this project, but INA226 has voltage limitations of 26V and the maximum current it can measure is ±3.2A.
The
INA226
can measure the voltage up to
36V
and the current up to
30A
. The current setting is based on the shunt resistance that needs to be changed based on current requirements. Follow the
INA226 Interfacing Guide
for learning more about current settings.
Let us take a look at the schamtic of IoT Based 12V Battery Monitoring System with ESP8266.
The
SDA
and
SCL
pins of INA226 are connected to the D2 & D1 pins of the ESP8266 Board. The
Vin+
pin should be connected to a power source and the
Vin-
to the load as shown in the design schematic. The INA226 Sensor has VBus Pin, which is used to measure the Load Voltage. Therefore we need to connect the
VBus
pin to Vin- pin.
You may use a breadboard for connection or design your own custom PCB.
Setting up Thingspeak
In order to Monitor the
Battery Data
on Thingspeak Server, you first need to Setup the
Thingspeak
. To set up the Thingspeak Server, visit
https://thingspeak.com/
. Create an account or simply sign in if you created the account earlier. Then create a new channel with following details.
The parameters that we are gonna measure is Battery Voltage, Load Voltage, Current and Power. Therefore, we need to create a 4 parameters.
Then go to the API section of the dashboard and copy the
API Key
. This API key is needed in the code part.
Now your Thingspeak account setup is complete.
Source Code/Program
Let us move to the programming part of IoT Based 12V Battery Monitoring System with ESP8266. The code requires
INA226 Library
for compilation. First add the library to the Arduino IDE.
From the following lines, change the WiFi SSID, Password & Thingspeak API Key.
String
apiKey
=
"**********"
;
const
char
*
ssid
=
"**********"
;
// Enter your WiFi Network's SSID
const
char
*
pass
=
"**********"
;
// Enter your WiFi Network's Password
Here is a complete code for this project.
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <INA226_WE.h>
#define I2C_ADDRESS 0x40
String
apiKey
=
"**********"
;
const
char
*
ssid
=
"**********"
;
// Enter your WiFi Network's SSID
const
char
*
pass
=
"**********"
;
// Enter your WiFi Network's Password
const
char
*
server
=
"api.thingspeak.com"
;
INA226_WE
ina226
=
INA226_WE
(
I2C_ADDRESS
)
;
WiFiClient
client
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
;
// wait until serial comes up on Arduino Leonardo or MKR WiFi 1010
Wire
begin
(
)
;
ina226
init
(
)
;
/* Set Resistor and Current Range
if resistor is 5.0 mOhm, current range is up to 10.0 A
default is 100 mOhm and about 1.3 A*/
ina226
setResistorRange
(
0.1
1.3
)
;
// choose resistor 0.1 Ohm and gain range up to 1.3A
/* If the current values delivered by the INA226 differ by a constant factor
from values obtained with calibrated equipment you can define a correction factor.
Correction factor = current delivered from calibrated equipment / current delivered by INA226*/
ina226
setCorrectionFactor
(
0.93
)
;
Serial
println
(
"INA226 Current Sensor Example Sketch - Continuous"
)
;
ina226
waitUntilConversionCompleted
(
)
;
//if you comment this line the first data might be zero
Serial
println
(
"Connecting to "
)
;
Serial
println
(
ssid
)
;
WiFi
begin
(
ssid
pass
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
delay
(
)
;
Serial
(
"*"
)
;
}
Serial
println
(
""
)
;
Serial
println
(
"WiFi connected"
)
;
}
void
loop
(
)
{
float
shuntVoltage_mV
=
0.0
;
float
loadVoltage_V
=
0.0
;
float
batteryVoltage_V
=
0.0
;
float
current_mA
=
0.0
;
float
power_mW
=
0.0
;
ina226
readAndClearFlags
(
)
;
shuntVoltage_mV
=
ina226
getShuntVoltage_mV
(
)
;
batteryVoltage_V
=
ina226
getBusVoltage_V
(
)
;
current_mA
=
ina226
getCurrent_mA
(
)
;
power_mW
=
ina226
getBusPower
(
)
;
loadVoltage_V
=
batteryVoltage_V
+
(
shuntVoltage_mV
/
1000
)
;
Serial
(
"Battery Voltage"
)
;
Serial
(
batteryVoltage_V
)
;
Serial
println
(
"V"
)
;
Serial
(
"Load Voltage: "
)
;
Serial
(
loadVoltage_V
)
;
Serial
println
(
"V"
)
;
Serial
(
"Current: "
)
;
Serial
(
current_mA
)
;
Serial
println
(
"mA"
)
;
Serial
(
"Power: "
)
;
Serial
(
power_mW
)
;
Serial
println
(
"mW"
)
;
if
(
!
ina226
overflow
)
{
Serial
println
(
"Values OK - no overflow"
)
;
}
else
{
Serial
println
(
"Overflow! Choose higher current range"
)
;
}
if
(
client
connect
(
server
)
)
{
String
postStr
=
apiKey
;
postStr
+=
"&field1="
;
postStr
+=
String
(
batteryVoltage_V
)
;
postStr
+=
"&field2="
;
postStr
+=
String
(
loadVoltage_V
)
;
postStr
+=
"&field3="
;
postStr
+=
String
(
current_mA
)
;
postStr
+=
"&field4="
;
postStr
+=
String
(
power_mW
)
;
postStr
+=
"\r\n\r\n\r\n\r\n"
;
client
(
"POST /update HTTP/1.1\n"
)
;
delay
(
)
;
client
(
"Host: api.thingspeak.com\n"
)
;
delay
(
)
;
client
(
"Connection: close\n"
)
;
delay
(
)
;
client
(
"X-THINGSPEAKAPIKEY: "
+
apiKey
+
"\n"
)
;
delay
(
)
;
client
(
"Content-Type: application/x-www-form-urlencoded\n"
)
;
delay
(
)
;
client
(
"Content-Length: "
)
;
delay
(
)
;
client
(
postStr
length
(
)
)
;
delay
(
)
;
client
(
"\n\n\n\n"
)
;
delay
(
)
;
client
(
postStr
)
;
delay
(
)
;
}
client
stop
(
)
;
Serial
Technologies used
Hardware components
- ESP8266
- Arduino
- INA226
Software & tools
- Arduino IDE
- ThingSpeak
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.