Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » IoT Based Battery Status Monitoring System using ESP8266
ESP8266 Projects IoT Projects

IoT Based Battery Status Monitoring System using ESP8266

Mamtaz AlamBy Mamtaz AlamUpdated:November 11, 20245 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
IoT Based Battery Monitoring System ESP8266
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

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.ComponentsQuantityPurchase Links
2NodeMCU ESP8266 or Wemos D1 Mini Board1Amazon | AliExpress
3TP4056 Battery Charging Module1Amazon | AliExpress
4Resistor 100K2Amazon | AliExpress
5Micro-USB Cable2Amazon | AliExpress
63.7V Li-ion Battery1Amazon | 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.

Lithium-Ion Battery

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.

IoT Based Battery Monitoring System

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.

IoT Based Battery Monitoring System


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.

1
2
3
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.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#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(100);
    Serial.print("*");
  }
  Serial.println("");
  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(sensorValue);
  Serial.print("\t Output Voltage = ");
  Serial.print(voltage);
  Serial.print("\t Battery Percentage = ");
  Serial.println(bat_percentage);
  delay(1000);
 
  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");
    delay(100);
    client.print("Host: api.thingspeak.com\n");
    delay(100);
    client.print("Connection: close\n");
    delay(100);
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    delay(100);
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    delay(100);
    client.print("Content-Length: ");
    delay(100);
    client.print(postStr.length());
    delay(100);
    client.print("\n\n");
    delay(100);
    client.print(postStr);
    delay(100);
  }
  client.stop();
  Serial.println("Sending....");
  delay(15000);
}
 
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

Open the Serial Monitor after uploading the code. The ESP8266 will try connecting to the WiFi Network. Once it connects to the WiFi Network, it will display the Analog Value along with Battery Voltage & Percentage.

Then go to the private view of Thingspeak Dashboard. The Battery Voltage and Battery Percentage will fill the graph. The graph will rise up when the device is charging and will go down when it’s discharging.


Fixing Voltage Value and Calibration

The circuit is designed to fix 100K pair of resistors. But most of the resistors have a tolerance of ±5%. Because of this resistor values may be between 95K to 105K. As a result, the output voltage and the analog signal output both are affected.

In order to fix this issue, you can compare the voltage difference between the Serial Monitor reading and Multimeter reading. Read the output voltage value at the TP4056 output terminal using a multimeter.

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


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

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

This will fix any error in the voltage reading. So this is how we can design IoT Based Battery Status Monitoring System using ESP8266 and get the reading on Thingspeak Server.

Incase you want an accurate battery status monitoring device, they you can use MAX17043 fule gauge IC which removes all the limiatations of measuring battery percentage by this method.


Video Tutorial & Guide: IoT Based Battery Monitoring System

IoT Based Battery Charging/Discharging Status + Voltage Monitoring System with ESP8266
Watch this video on YouTube.

If you want to monitor the Solar power using the same Thingspeak Server, you may refer to Solar Power Monitoring System project for managing the Solar Panel.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIoT MQTT Based Heart Rate Monitor using ESP8266 & Arduino
Next Article LoRa Based Soil Moisture Monitoring on LoRa ESP32 WebServer

Related Posts

IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20261K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

Updated:February 1, 20261K
View 5 Comments

5 Comments

  1. Ed on August 16, 2021 5:10 AM

    In your voltage divider calculation you seem to ignore the fact the Wemos has an onboard voltage divider

    Reply
  2. Hamza Rauf on December 22, 2021 6:37 AM

    Its Good turorial, thank you for sharing,
    In this prroject you are using 3.7V and 500 MAh Battery…!, can we use same method(circuit and code) for 8000 MAh
    and 3.7 V battery?

    Reply
  3. dfssdf sdfsdf on April 15, 2022 6:34 AM

    it shouldnt really matter since youre measuring voltage not mAh/Wh

    Reply
  4. Richard on November 15, 2022 4:23 PM

    I wish in these type of examples, you wouldn’t overcomplicate it by adding in an aspect like ThingSpeak. It just makes the resulting code harder to understand for newbies and adds another level of complexity. Just Serial Print it and let us format the data how we will!

    Reply
  5. Martin Winfield on March 17, 2023 6:15 AM

    I have built this project, but find the readings to be wildly incorrect when you look at lower of higher voltages than the one you calibrate it for (12 volt) 10 volts then reads 7 volts.14 volts reads 16 volts. Can you advise of a fix to make it more accurate. Thanks.

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • How to use ADS1220 24-Bit ADC Module with Arduino
    How to use ADS1220 24-Bit ADC Module with Arduino
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • Control Stepper Motor with A4988 Driver & Raspberry Pi Pico
    Control Stepper Motor with A4988 Driver & Raspberry Pi Pico
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.