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 12V Battery Monitoring System with ESP8266
ESP8266 Projects IoT Projects

IoT Based 12V Battery Monitoring System with ESP8266

Mamtaz AlamBy Mamtaz AlamUpdated:August 10, 20233 Comments4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
IoT Based 12V Battery Monitoring System with ESP8266
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

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:

  1. IoT Based Battery Status Monitoring System using ESP8266
  2. 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.ComponentsQuantityPurchase Links
2NodeMCU ESP8266 or Wemos D1 Mini Board1Amazon | AliExpress | SunFounder
3INA226 Current Sensor1Amazon | AliExpress
4Jumper Wires10Amazon | AliExpress | SunFounder
5Breadboard1Amazon | AliExpress | SunFounder
6Micro-USB Cable1Amazon | AliExpress
712V Lead-Acid Battery1Amazon | 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.

INA226 board

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.

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.

12V Battery Monitoring ESP8266

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.

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

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#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(100);
    Serial.print("*");
  }
  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.print("Battery Voltage");
  Serial.print(batteryVoltage_V);
  Serial.println("V");
 
  Serial.print("Load Voltage: ");
  Serial.print(loadVoltage_V);
  Serial.println("V");
 
  Serial.print("Current: ");
  Serial.print(current_mA);
  Serial.println("mA");
 
  Serial.print("Power: ");
  Serial.print(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, 80)) {
 
    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.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\n\n");
    delay(100);
    client.print(postStr);
    delay(100);
  }
  client.stop();
  Serial.println("Sent Successfully :)");
  Serial.println();
  delay(3000);
}

From the Board Manager, select the NodeMCU 1.0 Board and the COM port. Then hit the upload button to upload the code to the ESP8266 Board.





Monitoring 12V Lead-Acid Battery 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 Battery Voltage, Load Voltage, Current and Power.

If nothing is connected at the load, it will only display the Battery Voltage and else everything will appear zero.

In order to test the current and power consumption, connect a Load like Motor, 12V LED Lights or anything else at the Load Terminal.

Now go to the private view of Thingspeak Dashboard. The Dashboard will shows the values of Battery Voltage, Load Voltage, Current and Power in graphical format as per time.

You may start charging the Battery using 12V Battery Charger and observe the change in Current and Voltage on the graph.


Conclusion:

In conclusion, we successfully designed and built an IoT-based 12V Battery Monitoring System that leverages the ESP8266 and INA226 DC Current Sensor for optimal monitoring of lead-acid batteries. This sophisticated system safeguards battery performance and longevity by preventing overcharging and excessive discharging, which are common culprits of battery damage and system failure. By accurately measuring vital parameters such as battery voltage, load voltage, current, and power, our system promotes effective battery health management.

Furthermore, with the integration of the ThingSpeak server, users can effortlessly monitor their battery status from anywhere around the globe, providing enhanced convenience and flexibility. This comprehensive solution therefore, not only enhances the understanding of the battery’s condition in various states but also opens the door to potential advancements in remote battery management and other IoT applications in the future.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIndustrial Automation with Amazon AWS IoT Core & ESP8266
Next Article Automatic Plant Watering System with Arduino & Soil Moisture Sensor

Related Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

Updated:June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

Updated:June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20262K
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
View 3 Comments

3 Comments

  1. Spence on August 5, 2023 2:21 AM

    Awesome project but would you please add Blynk legacy code. I still have my own Blynk legacy v1 server and find Blynks GUI so much more flexible.

    Reply
  2. Jim Martino on January 4, 2024 10:23 AM

    “users can effortlessly monitor their battery status from anywhere around the globe”
    and then absolutely nothing you can do about it because you are “anywhere around the globe” and not where the battery is.
    How about to be able remotely charge or disconnect the battery if needed?

    Reply
  3. Reader on April 2, 2024 10:20 PM

    This sophisticated system safeguards battery performance and longevity by preventing overcharging and excessive discharging, which are common culprits of battery damage and system failure.

    Huh? This just measures Current/Voltage. It doesn’t prevent anything.

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 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
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • Silicon Controlled Rectifier (SCR): Construction, Working & Applications
    Silicon Controlled Rectifier (SCR): Construction, Working & Applications
  • How to use ADS1115 16-Bit ADC Module with Arduino
    How to use ADS1115 16-Bit ADC Module with Arduino
  • IoT Based Patient Health Monitoring on ESP32 Web Server
    IoT Based Patient Health Monitoring on ESP32 Web Server
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 (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • 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.