Microcontroller Tutorials

Arduino, Raspberry Pi, PIC, Beaglebone Resources

Arduino LiPo Battery Monitor

This Arduino LiPo battery monitor and charger features the TP4056 breakout board. The voltage of the battery is displayed on a Nokia 3310/5110 LCD with the Arduino Nano as the microcontroller.



The TP4056 breakout board input ports are microUSB and +, - pads. The output ports are and OUT+, OUT-, B+, B- pads.

Image result for TP4056

Naturally, the input voltage should be 5V DC on both the USB port and the +, - terminals. The battery is connected to the B+ and B- terminals. The current voltage of the battery is readable through the OUT+ and OUT- pads.

Once the input voltage and battery is connected, one of the on-board LED lights up. The red LED turns on when the battery is still charging. The green LED turns on when the charging reaches the full-charge voltage of 4.2 V. Here lies the limitation of the LED indication because some LiPo batteries are rated to 3.7 V. Obviously, the LED would not turn green for these batteries because it won’t reach 4.2 V.

So I had the idea of creating a battery monitor for my 3.7 V LiPo battery. The voltage of the battery will be fed to any of the analog pins of the arduino and then displayed on the LCD.

Wiring Diagram

Arduino LiPo Battery Monitor

The circuit gets its power from the battery itself. To avoid ADC reading errors due to the possible drift in battery voltage, I used the internal reference voltage of the arduino nano/atmega328p. This 1.1V reference voltage doesn’t drift with supply voltage so it’s a good thing. However, this would also mean that the maximum voltage that can be feed to A0 is 1.1V. So, I had to include a voltage divider circuit to reduce the input voltage at A0. The expected maximum input voltage is equal to the full-charge voltage of the battery, 3.7 V. I decided to use the following resistor values:

The maximum input voltage now would be

This is now well within the 1.1 V max limit!

Arduino Sketch

The required library for the sketch is Adafruit’s GFX and PCD8544 libraries. See my Arduino Nokia 3310 LCD tutorial for more information.

Noticed this line?

This is the reference voltage I was talking about. This is used in calculating the real voltage value later one.

To use the internal reference, this line is required:

On the loop(), I just needed to read the voltage on the A0 pin:

I then converted this value to voltage with a couple of lines:

My discussion on arduino sensor interfacing showed how to calculate the voltage from the raw value. Basically, the minimum voltage the arduino can read is Aref/1023 = 1.075 mV. So let’s say the input voltage from the battery is 1.7 V, which is brought down to 0.34 V by the voltage divider, the ADC value would be:

To convert this value to the actual voltage, I just reverse the formula above: divide by 1023 and then multiply by the reference voltage (1.1 V) and the voltage divider factor (1/0.2 = 5):

I also added some bars below the voltage value as seen:

Arduino LiPo Battery Monitor actual setup

This uses the fillRectangle() function of the graphics library. I draw one rectangle for every ¼ value of the full-charge voltage.

It looks bad but I promise to create better graphics on future updates 🙂

Did you find this project useful? Please drop a comment below!

2 thoughts on “Arduino LiPo Battery Monitor

  1. I was looking at this tutorial and also the one regarding the SIM800L.
    My present project includes both modules, the SIM800L and the TP4056.
    Two questions please:
    1. Can I use the TP4056 as an UPS? The 3.7v LiPo should provide power to an Arduino in case of main power loss.
    If main power is normal it should charge the LiPo and also provide the Arduino with power.
    2. I realized that the output of the TP4056 shows 3.5V while the LiPo itself shows 4.1V. Is this normal?
    It's powered from a PC with USB.
    Thanks in advance!

  2. Great tutorial, i have as goal of use a TP4056 with a lipo 3.7V but i don't know if the board stop the charge when the lipo is full charge. Else, i should to use a relay for stop charge ?

    Sorry for my bad langage 🙁 my english is very bad...

Leave a Reply

Your email address will not be published. Required fields are marked *