IoT Based Battery Status Monitoring System using ESP8266

In this blog, we will create an IoT-based Battery Monitoring System using the ESP8266 in this project, which will allow you to monitor the battery charging/discharging status as well as Battery Voltage and Percentage.

Proposed System

The battery is the most vital component of any smartphone because it powers the entire system. As a result, it’s critical to keep an eye on the battery’s voltage level, as improper or excessive charging/discharging can damage the battery or cause system failure. A distinct mechanism known as the Battery Management System is found in most electrical/electronic devices (BMS). The BMS keeps track of the voltage, current, temperature, and auto-cut-off mechanism of the battery. This guarantees that Lithium-Ion or Lithium Polymer batteries are handled safely and correctly.

Earlier, the BMS just monitored the battery’s state and alerted the user via a battery indicator. However, thanks to the Internet of Things, we can now notify users directly from afar. From anywhere in the world, they may monitor the battery status on their smartphones or computer dashboard.

We’ll utilize a Wemos D1 Mini with an ESP8266 chip to communicate battery status data to the ThingSpeak cloud in this IoT-based Battery Monitoring System. In both charging and discharging modes, the Thingspeak will display the battery voltage as well as the battery percentage.

Components Required

  • NodeMCU or Wemos D1 Mini Board
  • TP4056 Lithium-Ion Battery Charging Module
  • Resistors-100k
  • 5V Micro-USB Data Cable
  • Lithium-Ion Battery

Lithium-Ion Batteries

A lithium-ion battery, sometimes known as a Li-ion battery, is a rechargeable battery type. Portable electronics and electric cars frequently employ lithium-ion batteries.

Lithium ions flow from the negative electrode to the positive electrode through an electrolyte during discharge and return during charging in this battery. The positive electrode of a lithium-ion battery is made of an intercalated lithium compound, while the negative electrode is usually made of graphite. The batteries feature a high energy density, a low self-discharge rate, and no memory effect.

Nominal, Maximum & Cut-off Voltage

These are the few Lithium-Ion batteries that I’ve been utilizing for several of my projects for a long time. Over-voltage protection, balanced charging, short-circuit protection, and other functions are provided by a basic Battery Management System Circuit added to some batteries.

The nominal voltage of most Lithium-Ion batteries is 3.7V. When the battery is fully charged, the maximum voltage is 4.20.5. The manufacturer’s datasheet explicitly states that the cut-off voltage is 3V and that it changes depending on the battery type and use. The discharge cut-off voltage on the battery I’m using is 2.8V. You can also acquire batteries with a 2.5V cut-off voltage.

Circuit & Schematic Designing

We’ll create a mechanism to keep track of the battery’s voltage, as well as its charging and discharging state. We use a Wemos D1 Mini microcontroller with an ESP8266 wifi-enabled chip as the microcontroller. The NodeMCU ESP8266 Board can also be used. This WiFi chip can connect to a WiFi network and send data to a server on a regular basis.

IoT Based Battery Monitoring System

The TP4056 module is best suited for Battery Management Applications and can be used to charge the battery. Instead of TP4056, the MCP73831 IC can be utilised.

The ESP8266 chip can only accept a 3.3V analog input voltage. However, the battery voltage rises to 4.2V. As a result, we must create a voltage divider network to reduce the input voltage.

Voltage Divider Network Calculations

The battery’s maximum voltage is 4.2V, with a voltage cutoff of 2.8V. The ESP8266 Analog Pin can readily support voltages lower than 3.3V.

First, we must lower the highest voltage level. The source voltage is 4.2V, and there are two 100K resistors in the circuit. This will result in a 2.1V output. Similarly, using the same voltage divider network, the minimum voltage is 2.8V as a cutoff value that drops down to 1.4V. As a result, the ESP8266 Analog Pin supports both the upper and lower voltages.

The project is seen in its entirety below. The circuit diagram shows that this is the same connection. A Lithium-Ion Battery of any capacity can be used for testing. For example, I’m using a 1950mAh battery.

IoT Based Battery Monitoring System

Setting up Thingspeak

In order to Monitor the Battery Data on Thingspeak Server, you first need to set up the Thingspeak. To set up the Thingspeak Server, visit Create an account or simply login in if you already have one. Then make a new channel with the following information.

Then navigate to the dashboard’s API section and copy the API Key. This API key is required for the code section.

Source Code/Program

The source code for the ESP8266-based IoT Battery Status Monitoring System is available here. In the code, change the WiFi SSID, Password, and API Key.

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

Copy and paste the code below into 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 = “”;

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.println(“Connecting to “);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)
Serial.println(“WiFi connected”);

void loop()
sensorValue = analogRead(analogInPin);
float voltage = (((sensorValue * 3.3) / 1024) * 2 + calibration); //multiply by two as voltage divider network is 100K & 100K Resistor

bat_percentage = mapfloat(voltage, 2.8, 4.2, 0, 100); //2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage

if (bat_percentage >= 100)
bat_percentage = 100;
if (bat_percentage <= 0)
bat_percentage = 1;

Serial.print(“Analog Value = “);
Serial.print(“\t Output Voltage = “);
Serial.print(“\t Battery Percentage = “);

if (client.connect(server, 80))

String postStr = apiKey;
postStr += “&field1=”;
postStr += String(voltage);
postStr += “&field2=”;
postStr += String(bat_percentage);
postStr += “\r\n\r\n”;

client.print(“POST /update HTTP/1.1\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: ” + apiKey + “\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
return (x – in_min) * (out_max – out_min) / (in_max – in_min) + out_min;

IoT Based Battery Monitoring System using ESP8266 on Thingspeak

After uploading the code, open the Serial Monitor. The ESP8266 will make an attempt to connect to the WiFi network. It will display the Analog Value, Battery Voltage, and Percentage once it connects to the WiFi Network.

Then go to Thingspeak Dashboard’s private view. The graph will be filled with the Battery Voltage and Battery Percentage. When the device is charging, the graph will climb, and when it is discharging, it will fall.

Fixing Voltage Value and Calibration

The circuit is intended to connect a pair of 100K resistors. However, the majority of resistors have a 5% tolerance. As a result, resistor values may range from 95K to 105K. Both the output voltage and the analog signal output are changed as a result.

You can resolve this problem by comparing the voltage difference between the Serial Monitor and Multimeter readings. Using a multimeter, measure the output voltage at the TP4056 output terminal.

Subtract the Multimeter voltage value from the value obtained on the Serial Monitor.

In the following line of the code add this calibration factor.

float calibration = 0.36; // Check Battery voltage using multimeter & add/subtract the value

This will correct any voltage reading errors. So, utilizing the ESP8266 and the Thingspeak Server, we can create an IoT-based Battery Status Monitoring System. If you want an accurate battery status monitoring device, you can use the MAX17043 full gauge IC, which eliminates all of the limitations of this way of determining battery %.


I hope all of you understand how to design an IoT Based Battery Status Monitoring System using ESP8266. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.