IoT Based Battery Status Monitoring System using ESP8266
IoT based Battery Monitoring System using ESP8266 to monitor the battery charging/discharging, Voltage & Percentage. Source Code & Circuit
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelIntermediate
- Available atAjvika Labs, Kakinada
About this project
Overview: IoT Based Battery Monitoring System using ESP8266
In this project, we will build an
IoT based Battery Monitoring System
using
ESP8266
where you can monitor the
battery charging/discharging
status along with
Battery Voltage
&
Percentage
As we know, the battery is the most important component for any device as it powers the entire system. So, it is important to monitor the
voltage level of the battery
as improper or excess charging/discharging may lead to damage to the Battery or System Failure. Most of the
electrical/electronics devices
has a separate system called
Battery Management System (BMS)
. The BMS monitors all the properties of the battery like the
voltage, current, temperature
&
auto cut-off system
. This ensures the safety and proper handling of
Lithium-Ion
or
Lithium Polymer
batteries.
Earlier BMS only monitors the condition of the battery and alarms the user via a
battery indicator
. But now due to the use of the
Internet of Things
, we can directly notify the users remotely. They can check the battery status on their smartphones or Computer dashboards from anywhere in the world.
In this
IoT-based Battery Monitoring System
, we will use
Wemos D1 Mini
with
ESP8266 Chip
to send the battery status data to
ThingSpeak cloud
. The Thingspeak will display the battery voltage along with the battery percentage in both the charging and discharging cases. A very precise version of this project can be checked at
DIY LiPo Charger with IoT Battery Voltage Monitor
, as this contains a customized PCB baord. In case you wanna monitor a Lead-Acid Battery, you can check
12V Battery Monitoring System
project.
Bill of Materials
You will need the following components for the IoT Based Battery Monitoring System Project. You can purchase all the components online from Amazon.
S.N.
Components
Quantity
Purchase Links
NodeMCU ESP8266 or Wemos D1 Mini Board
Amazon
AliExpress
TP4056 Battery Charging Module
Amazon
AliExpress
Resistor 100K
Amazon
AliExpress
Micro-USB Cable
Amazon
AliExpress
3.7V Li-ion Battery
Amazon
AliExpress
Lithium-Ion Batteries
A
lithium-ion
battery or
Li-ion
battery is a type of
rechargeable battery
. Lithium-ion batteries are commonly used for portable electronics and electric vehicles.
In this battery, lithium ions move from the
negative electrode
through an electrolyte to the
positive electrode
during discharge, and back when charging. Li-ion batteries use an intercalated lithium compound as the material at the positive electrode and typically
graphite
at the negative electrode. The batteries have a high energy density, no memory effect and low self-discharge.
Nominal, Maximum & Cut-off Voltage
I’ve been using several Lithium-Ion batteries for quite some time across multiple projects. Some of these batteries come with an attached Battery Management System Circuit, providing over-voltage protection, balanced charging, and short-circuit protection.
Typically, Lithium-Ion batteries have a nominal voltage of 3.7V. When fully charged, their maximum voltage can reach up to 4.2±0.5V. Manufacturer datasheets usually state the cut-off voltage to be around 3V, though this can vary based on the battery type and its specific applications. The battery I frequently use has a discharge cut-off voltage of 2.8V. However, there are also batteries available with a cut-off voltage as low as 2.5V.
Circuit & Schematic Designing
We will design a system to monitor this battery voltage along with charging and discharging status. For the microcontroller, we use
Wemos D1 Mini
which has an
ESP8266
wifi-enabled chip. You can also use the
NodeMCU ESP8266 Board
. This WiFi chip can connect to the WiFi network and uploads the data regularly to the server.
You can use the
TP4056
module to charge the battery as its best suited for Battery Management Applications. The
MCP73831
IC can also be used instead of TP4056.
The ESP8266 Chip can only support the input analog voltage of
3.3V
. But Battery voltage goes up to
4.2V
. Hence we have to form a
voltage divider network
to lower down the input voltage.
Voltage Divider Network Calculations
The Battery Maximum voltage is 4.2V and the cut of voltage is 2.8V. Anything lesser than 3.3V will be easily supported by ESP8266 Analog Pin.
We have to first step down the upper voltage level. The
source voltage
is
4.2V
and there is a pair of
100K resistors
. This will give an output of
2.1V
. Similarly, the
minimum voltage
is
2.8V
as a cutoff voltage which steps down to 1.4V using the same voltage divider network. Hence, both the upper and lower voltage is supported by
ESP8266 Analog Pin
Here is a complete assembly of the project. This is the same connection as shown in the
circuit diagram
. For testing, you can use a Lithium-Ion Battery of any capacity. For example, I am using a Battery with a capacity
1950mAh
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.
Then go to the API section of the dashboard and copy the
API Key
. This API key is needed in the code part.
Source Code/Program
Here is the source code for
IoT Based Battery Status Monitoring System
using
ESP8266
. Replace the WiFi
SSID
Password
and
API Key
in the code.
String
apiKey
=
"**************"
;
// Enter your Thingspeak API Key
const
char
*
ssid
=
"**************"
;
// Enter your WiFi Network's SSID
const
char
*
pass
=
"**************"
;
// Enter your WiFi Network's Password
Now copy the following code and upload it to your NodeMCU or Wemos D1 Mini Board.
#include <ESP8266WiFi.h>
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"
;
int
analogInPin
=
A0
;
// Analog input pin
int
sensorValue
;
// Analog Output of Sensor
float
calibration
=
0.36
;
// Check Battery voltage using multimeter & add/subtract the value
int
bat_percentage
;
WiFiClient
client
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
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
(
)
{
sensorValue
=
analogRead
(
analogInPin
)
;
float
voltage
=
(
(
(
sensorValue *
3.3
)
/
1024
)
*
+
calibration
)
;
//multiply by two as voltage divider network is 100K & 100K Resistor
bat_percentage
=
mapfloat
(
voltage
2.8
4.2
)
;
//2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage
if
(
bat_percentage
>=
)
{
bat_percentage
=
;
}
if
(
bat_percentage
<=
)
{
bat_percentage
=
;
}
Serial
(
"Analog Value = "
)
;
Serial
(
sensorValue
)
;
Serial
(
"\t Output Voltage = "
)
;
Serial
(
voltage
)
;
Serial
(
"\t Battery Percentage = "
)
;
Serial
println
(
bat_percentage
)
;
delay
(
1000
)
;
if
(
client
connect
(
server
)
)
{
String
postStr
=
apiKey
;
postStr
+=
"&field1="
;
postStr
+=
String
(
voltage
)
;
postStr
+=
"&field2="
;
postStr
+=
String
(
bat_percentage
)
;
postStr
+=
"\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"
)
;
d
In this project, we will build an
IoT based Battery Monitoring System
using
ESP8266
where you can monitor the
battery charging/discharging
status along with
Battery Voltage
&
Percentage
As we know, the battery is the most important component for any device as it powers the entire system. So, it is important to monitor the
voltage level of the battery
as improper or excess charging/discharging may lead to damage to the Battery or System Failure. Most of the
electrical/electronics devices
has a separate system called
Battery Management System (BMS)
. The BMS monitors all the properties of the battery like the
voltage, current, temperature
&
auto cut-off system
. This ensures the safety and proper handling of
Lithium-Ion
or
Lithium Polymer
batteries.
Earlier BMS only monitors the condition of the battery and alarms the user via a
battery indicator
. But now due to the use of the
Internet of Things
, we can directly notify the users remotely. They can check the battery status on their smartphones or Computer dashboards from anywhere in the world.
In this
IoT-based Battery Monitoring System
, we will use
Wemos D1 Mini
with
ESP8266 Chip
to send the battery status data to
ThingSpeak cloud
. The Thingspeak will display the battery voltage along with the battery percentage in both the charging and discharging cases. A very precise version of this project can be checked at
DIY LiPo Charger with IoT Battery Voltage Monitor
, as this contains a customized PCB baord. In case you wanna monitor a Lead-Acid Battery, you can check
12V Battery Monitoring System
project.
Bill of Materials
You will need the following components for the IoT Based Battery Monitoring System Project. You can purchase all the components online from Amazon.
S.N.
Components
Quantity
Purchase Links
NodeMCU ESP8266 or Wemos D1 Mini Board
Amazon
AliExpress
TP4056 Battery Charging Module
Amazon
AliExpress
Resistor 100K
Amazon
AliExpress
Micro-USB Cable
Amazon
AliExpress
3.7V Li-ion Battery
Amazon
AliExpress
Lithium-Ion Batteries
A
lithium-ion
battery or
Li-ion
battery is a type of
rechargeable battery
. Lithium-ion batteries are commonly used for portable electronics and electric vehicles.
In this battery, lithium ions move from the
negative electrode
through an electrolyte to the
positive electrode
during discharge, and back when charging. Li-ion batteries use an intercalated lithium compound as the material at the positive electrode and typically
graphite
at the negative electrode. The batteries have a high energy density, no memory effect and low self-discharge.
Nominal, Maximum & Cut-off Voltage
I’ve been using several Lithium-Ion batteries for quite some time across multiple projects. Some of these batteries come with an attached Battery Management System Circuit, providing over-voltage protection, balanced charging, and short-circuit protection.
Typically, Lithium-Ion batteries have a nominal voltage of 3.7V. When fully charged, their maximum voltage can reach up to 4.2±0.5V. Manufacturer datasheets usually state the cut-off voltage to be around 3V, though this can vary based on the battery type and its specific applications. The battery I frequently use has a discharge cut-off voltage of 2.8V. However, there are also batteries available with a cut-off voltage as low as 2.5V.
Circuit & Schematic Designing
We will design a system to monitor this battery voltage along with charging and discharging status. For the microcontroller, we use
Wemos D1 Mini
which has an
ESP8266
wifi-enabled chip. You can also use the
NodeMCU ESP8266 Board
. This WiFi chip can connect to the WiFi network and uploads the data regularly to the server.
You can use the
TP4056
module to charge the battery as its best suited for Battery Management Applications. The
MCP73831
IC can also be used instead of TP4056.
The ESP8266 Chip can only support the input analog voltage of
3.3V
. But Battery voltage goes up to
4.2V
. Hence we have to form a
voltage divider network
to lower down the input voltage.
Voltage Divider Network Calculations
The Battery Maximum voltage is 4.2V and the cut of voltage is 2.8V. Anything lesser than 3.3V will be easily supported by ESP8266 Analog Pin.
We have to first step down the upper voltage level. The
source voltage
is
4.2V
and there is a pair of
100K resistors
. This will give an output of
2.1V
. Similarly, the
minimum voltage
is
2.8V
as a cutoff voltage which steps down to 1.4V using the same voltage divider network. Hence, both the upper and lower voltage is supported by
ESP8266 Analog Pin
Here is a complete assembly of the project. This is the same connection as shown in the
circuit diagram
. For testing, you can use a Lithium-Ion Battery of any capacity. For example, I am using a Battery with a capacity
1950mAh
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.
Then go to the API section of the dashboard and copy the
API Key
. This API key is needed in the code part.
Source Code/Program
Here is the source code for
IoT Based Battery Status Monitoring System
using
ESP8266
. Replace the WiFi
SSID
Password
and
API Key
in the code.
String
apiKey
=
"**************"
;
// Enter your Thingspeak API Key
const
char
*
ssid
=
"**************"
;
// Enter your WiFi Network's SSID
const
char
*
pass
=
"**************"
;
// Enter your WiFi Network's Password
Now copy the following code and upload it to your NodeMCU or Wemos D1 Mini Board.
#include <ESP8266WiFi.h>
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"
;
int
analogInPin
=
A0
;
// Analog input pin
int
sensorValue
;
// Analog Output of Sensor
float
calibration
=
0.36
;
// Check Battery voltage using multimeter & add/subtract the value
int
bat_percentage
;
WiFiClient
client
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
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
(
)
{
sensorValue
=
analogRead
(
analogInPin
)
;
float
voltage
=
(
(
(
sensorValue *
3.3
)
/
1024
)
*
+
calibration
)
;
//multiply by two as voltage divider network is 100K & 100K Resistor
bat_percentage
=
mapfloat
(
voltage
2.8
4.2
)
;
//2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage
if
(
bat_percentage
>=
)
{
bat_percentage
=
;
}
if
(
bat_percentage
<=
)
{
bat_percentage
=
;
}
Serial
(
"Analog Value = "
)
;
Serial
(
sensorValue
)
;
Serial
(
"\t Output Voltage = "
)
;
Serial
(
voltage
)
;
Serial
(
"\t Battery Percentage = "
)
;
Serial
println
(
bat_percentage
)
;
delay
(
1000
)
;
if
(
client
connect
(
server
)
)
{
String
postStr
=
apiKey
;
postStr
+=
"&field1="
;
postStr
+=
String
(
voltage
)
;
postStr
+=
"&field2="
;
postStr
+=
String
(
bat_percentage
)
;
postStr
+=
"\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"
)
;
d
Technologies used
Hardware components
- ESP8266
Software & tools
- 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.