3.7V Lipo & Lithium Ion battery monitoring:
3.7V Lipo & Lithium Ion battery monitoring using ESP8266, TP4056, & Blynk 2.0- In this tutorial, you will learn how to make a 3.7V Lipo and Lithium Ion Battery Monitoring System using Nodemcu ESP8266 WiFi Module, TP4056 1S battery charger, SSD1306 Oled display Module, and the New Blynk V2.0.
You need to be very careful while working on battery-powered projects as you are not supposed to Overcharge and Over-discharge your Lipo or Lithium Ion battery. Overcharging can make your battery explode and it has practically happened to me. Being an engineer, when I knew all about it, I still made the most stupid decision by purchasing this battery charger.
You can clearly see there is no protection circuit. The Lipo Battery overcharged and caught fire. Thank God I was at home so I quickly put out the fire. So, just don’t purchase a cheap battery charger; buy the one that has a charge protection circuit. Like this Imax charger; I have been using it for months and until now its working just fine.
Anyway, just like Overcharging, the battery over-discharging is also not a good thing because if you continuously over-discharge or completely drain your battery it will tremendously reduce the battery life span. Just take a look at this Lipo battery, I used it to fly my racing drone.
It looks like a new battery as I have been charging it using my Imax charger, but its dead now because of over-discharging as I was pushing it to its maximum limits. There wasn’t any voltage monitoring system so I had no idea when to stop flying the drone.
Now, you can imagine what’s going to happen to this 3.7V Lipo battery if I directly connect it to ESP32, or ESP8266, or any other 3.3V controller board If there is no voltage monitoring and automatic disconnection circuitry, this Lipo battery won’t survive for long. But what if we monitor the battery voltage and also add a pair of mosfets so that when the battery voltage increases above or drops below certain threshold values the controller will immediately connect/disconnect the battery. This will definitely protect the battery from exploding and it will also increase the battery life span.As this is a basic article, so I won’t make things complicated.
I have also designed my own single cell 3.7V Lipo and Lithium ion battery charger, I will explain this in one of my upcoming articles and videos. Anyway, for now we will focus on how to monitor the battery voltage and percentage. For this I decided to use this low-cost TP4056 battery charger.
TP4056 is best for charging single cell Lithium Ion and Lipo batteries.
The TP4056 board has this DW01 battery protection IC that is designed to take care of Overcharge, Over-discharge and Overcurrent for single cell Lithium Ion or Lipo battery-powered systems.
So, you simply connect your 3.7V battery and leave everything else to this module it will make sure your battery stays safe. So, I am going to use this Battery charger module. So, let’s go ahead and start the soldering. I am using my Andonstar digital Microscope for recording the video clips and for capturing high-quality images, and I am going to use the ATEtool Soldering Station.
You can see I have soldered the Red and Black wires of the 3.7V Lipo battery with the B+ and B- contacts on the TP4056 battery charger module. And using these output wires I can power up my 3.3v controller boards, 3.3V sensors, and small coreless dc motors, etc. Now, using my cell phone charger I can charge my single-cell Lipo and lithium-ion batteries. Now, the next part is to monitor the voltage and charge percentage.
For this, I connected everything as per the circuit diagram. And as usual, before I am going to explain the circuit diagram, Blynk cloud dashboard, and blynk IoT App setup first let’s watch this 3.7V Lipo & Lithium Ion battery monitoring system in action.
Feel free to visit their website https://jlcpcb.com/SKL to not only find out what awesome PCB and Assembly services they offer, but also to easily upload your Gerber files and thus order affordable and high-quality PCBs quickly. You will only need to pay 2 dollars for 1- 4 layers PCBs, and 0 dollars for your PCB assembly. Besides this JLCPCB also offers industrial 3D printing services starting at only 1 dollar.
You can see everything is powered up. My ESP8266 and cell phone both are connected to the WiFi. You can see the voltage and percentage on the Blynk IoT cell phone App, on the Blynk Cloud dashboard, and also on the Oled display module. At first, the voltage was a bit OFF, so I used a digital multimeter to find the actual voltage and then I changed the calibration value in the programming, it took me around 5 minutes to complete the calibration.
So, if on your side, the measured voltage is different from the actual battery voltage then play with the calibration value until your measured voltage value matches the digital multimeter value.
Now, I am going to connect some LEDs and you will see a change in the battery voltage.
Its working exceptionally well. Now, you can add conditions in the programming to turn ON the buzzer or an Led when the voltage increases above 4 volts or when the voltage falls below 2 volts. Anyway, using this battery voltage monitoring system you can monitor your battery voltage and percentage from anywhere in the world. For demonstration purposes, I am using a small Lipo battery but in reality, you will need to connect a slightly bigger battery if want more battery backup time.
I am sure by now, you might have got an idea of how does this system work. So, without any further delay let’s get started!!!
Other Tools and Components:
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
3.7V Battery Voltage Monitoring, Circuit:
On the Left side, you can see a 5V regulated power supply based on the LM7805 linear voltage regulator. Using this regulated power supply I can power up the Nodemcu ESP8266 WiFi module using a 12V adaptor, battery, or a solar panel. If you don’t want to use this it’s okay, you can use your 3.7V Lipo or Lithium Ion battery to power up the Nodemcu module. But, It’s good to have different power sources. Anyway, you can see the battery red and black wires are connected with the B+ and B- contacts of the TP4056.
Two resistors are connected in series across the OUT+ and OUT- contacts. These 100K ohm resistors make the voltage divider circuit. You can see a wire from the middle of this voltage divider is connected with the A0 analog pin of the Nodemcu module for measuring the voltage. And make sure you connect the ground of the TP4056 charger module with the ground of the Nodemcu module.
The SSD1306 I2C Oled display module SDA and SCL pins are connected with the SDA and SCL pins on the Nodemcu ESP8266 WiFi module. D1 is the SCL and D2 is the SDA. While the VCC and GND pins of the Oled display module are connected with the Nodemcu module 3.3V and GND pins.
ESP8266 Development board:
These are the PCB boards, I received from the JLCPCB as you can see the quality is really great. The silkscreen is quite clear and the Black Solder mask looks amazing.
This is how my Nodemcu ESP8266 Development board looks after soldering all the components. I use this development board for testing all my ESP8266-based projects. Now let’s start with the Blynk Web dashboard setup.
Blynk V2.0 Web Dashboard Setup:
If you are just starting with the New Blynk V2.0 then I highly recommend, you should read my getting started article on the Blynk V2.0 and NodeMCU ESP8266. Any, after you have logged in into your Blynk Cloud account; click on the New Template, write the Template name, select the hardware, set the connection type, and write some description, and then finally, click on the Done button.
Under the Info tab you will see the template name, hardware, connection type, description, and some credentials on the right side including the BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME.
Then Click on the Datastreams Tab and select New Datastream, you will see Digital, Analog, Virtual Pin, Enumerable, and Location. From this drop-down menu select Virtual Pin this is what we need.
Then enter the name to the Datastream and select the pin and click on the create button.
Now the virtual pin is created, in the similar way, we will add another virtual variable for the battery percentage.
Now, you can see the two virtual variables are ready.
Then click on the web dashboard and drag the gauge to the dashboard and click on Settings Gear of the gauge.
Select the title name, Datastream, and then click on the Save button.
Now the gauge is created and in similar way we will add another gauge for the battery percentage.
You can see the two gauges are added one for the Voltage and the other one for the Battery Percentage. Next, click on the search button and then click on the new device
Then click on From Template.
Select your project, Battery monitoring. Don’t get confused with Getting started, it another project.
Then copy the following credentials
Now paste these credentials in the code. Don’t copy these credentials, use yours.
Battery Monitoring Code:
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID “TMPLj9Yp1rak”
#define BLYNK_DEVICE_NAME “Battery monitoring”
#define BLYNK_AUTH_TOKEN “pNLmOPuCgjeASQ6SOsK8G-Q_xZCo7ROK”
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
intanalogInPin = A0; // Analog input pin
// Check Battery voltage using multimeter & add/subtract the value
float calibration = 0.36;
// Your WiFi credentials.
// Set password to “” for open networks.
charssid = “AndroidAP3DEC”;
char pass = “electroniclinic”;
charauth = BLYNK_AUTH_TOKEN;
// Debug console
Blynk.begin(auth, ssid, pass);
sensorValue = analogRead(analogInPin);
//multiply by two as voltage divider network is 100K & 100K Resistor
voltage = (((sensorValue * 3.3) / 1024) * 2 – calibration);
//2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage
bat_percentage = mapfloat(voltage, 2.8, 4.2, 0, 100);
if (bat_percentage>= 100)
bat_percentage = 100;
if (bat_percentage<= 0)
bat_percentage = 1;
//send data to blynk
Blynk.virtualWrite(V0, voltage); // for battery voltage
Blynk.virtualWrite(V1, bat_percentage); // for battery percentage
Serial.print(“Analog Value = “);
Serial.print(“Output Voltage = “);
Serial.print(“Battery Percentage = “);
floatmapfloat(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;
Before you upload the program, first of all, make sure, you have installed your Nodemcu ESP8266 Board, if not then follow my tutorial on Nodemcu ESP8266. You will also need to install the New Blynk V2.0 library for this you can watch my getting started articles on Blynk v2.0 and ESP32, and Blynk v2.0 and ESP8266. Besides this, you will also need to install libraries for the SSD1306 Oled display module. Anyway, after you have installed your Nodemcu ESP8266 board and all the required libraries, then you can upload your program to Nodemcu ESP8266 WiFi Module. Now, you should be able to monitor your battery voltage and percentage on the Blynk Cloud Dashboard.
So far everything is working and I am able to monitor the voltage and battery percentage. Next, we will setup Blynk IoT cell phone Application.
Blynk IoT Mobile dashboard:
Download and install Blynk IoT Application on your cell phone. While logging into your account make sure you use the same Gmail ID.
Then click on the setting
Then click on the add button to add a Gauge.
Then click on the gauge give it a name and link a variable “datastream” the same as we did on the Blynk Cloud Dashboard.
The same exact way do it for the percentage.
Then give a title and set the font size
In the similar way we will add another gauge for the battery percentage.
My Blynk IoT Mobile App is also ready. For the practical demonstration watch video tutorial, link is given below.
Watch Video Tutorial: