Li-Po battery monitor [answered]

Hello, so I am planning to make a ATMgea-328 project, that I want to power with a Li-Po battery of some normal capacity (around 1000 mAh).

For protection and 5V boost, I want to use a PCB, that GreatScott designed: LiPo 5V Boost/protect EasyEda . But that circuit can only show you, that your battery is charging, or finished charging, using 2 SMD LEDs.

I want to integrate a battery percentage monitor, that can tell me the percentage while charging and while using. I saw one - again by GreatScott, but that was for monitoring a whole pack of around 17V, and required 20V for VIN.

So I had an idea to add some second arduino-compatible microcontroler, that would somehow monitor the voltage even while charging, powered straightly by the micro USB power lines and probably monitor the battery voltage by an analog pin and show the percentage on an OLED display.

The problem is I do not know how would I power it when the micro USB cable will be disconnected and running the main microcontroler from the Li-Po battery. I do not know if something like powering the second microcontroler from the same boosted 5V output of the battery and connecting the non-boosted battery output to the analog pin? Would that work?

There is a pin called areff in the ic, voltage in this pin is used as a reference voltage for the adc. So if you want to read the voltage of the battery (0 - 3.7v) ,you can connect this pin to the battery directly and you could map the analog values to give the percentage.

Why did you use the booster atmega328p work from 1.8 - 5.5v and oled works in 3.3v right??

Thanks, Akash

m_k_akash:
There is a pin called areff in the ic, voltage in this pin is used as a reference voltage for the adc. So if you want to read the voltage of the battery (0 - 3.7v) ,you can connect this pin to the battery directly and you could map the analog values to give the percentage.

Why did you use the booster atmega328p work from 1.8 - 5.5v and oled works in 3.3v right??

Thanks, Akash

Hi and thanks for the reply. I am using 5V boost, because I will be using a lot more 5V things in the full circuit (for example adressable LEDs). What about grounding? If I connect all the GNDs in the circuit toogether, will it work? And how do I read the value on the programming side? Thanks in advance

Connecting all the grounds together will work. Sorry you shouldn't connect areff directly to the battery instead you should create a 3.7 voltage divider from the booster. Because if you connect directly as the battery voltage decreases , the refference voltage also decreases along so it would show 100% all the time but if you have a constant 3.7v as reference then you could do it properly. You should figure out until which voltage the booster works. Till that voltage only the circuit works right. In the software side, its as normal as you use the analogRead function , now 1023 means 3.7 volts and 0 means 0 volts. Though if you build the circuit you can't read the voltage till it gets 0, instead it will work untill the booster works

Thank you, Akash

m_k_akash:
Connecting all the grounds together will work. Sorry you shouldn't connect areff directly to the battery instead you should create a 3.7 voltage divider from the booster. Because if you connect directly as the battery voltage decreases , the refference voltage also decreases along so it would show 100% all the time but if you have a constant 3.7v as reference then you could do it properly. You should figure out until which voltage the booster works. Till that voltage only the circuit works right. In the software side, its as normal as you use the analogRead function , now 1023 means 3.7 volts and 0 means 0 volts. Though if you build the circuit you can't read the voltage till it gets 0, instead it will work untill the booster works

Thank you, Akash

Ok, so if I understand correctly, I should connect a stable 3,7 volts to the areff and the actual battery voltage to any analog pin. And since a Li-Po battery is not supposed to be drained to 0V, The GreatScott´s boost/protect circuit shuts down at 2,9 V, so I do not think that connecting a 3,7 reference will help much, and just connecting the battery to any analog PIN and let 3,7 volts be analog value of around 760 (max charged) and the 2,9 V be around 590 (completely discharged). 760 - 590 > 100 so I will be still able to track the battery with 1% accuracy with only analog pin without any reference. Am I right? Thanks in advance.

Yes , but in that case just connect areff to 5v, so a you said 3.7 would be 760 and 2.9 will be 590, then map it to 0 to 100. areff is a part of the adc system so it should be connected some potential with reference to that voltage only the adc works. If it's 5v then the resolution will be 5/1024 and if it's 3.7v the resolution will be 3.7/1023. So resolution depends on the potential provided to areff pin

Thank you, Akash

All Gnds NEED to be connected together for things to work correctly. It gives all signals a common reference point. The only time they are not connected is when Optoisolators are used.

Sparkfun has a LiPo fuel guage board that can monitor the current from the battery and let you know how much charge has been used or is remaining

m_k_akash:
Yes , but in that case just connect areff to 5v, so a you said 3.7 would be 760 and 2.9 will be 590, then map it to 0 to 100. areff is a part of the adc system so it should be connected some potential with reference to that voltage only the adc works. If it's 5v then the resolution will be 5/1024 and if it's 3.7v the resolution will be 3.7/1023. So resolution depends on the potential provided to areff pin

Thank you, Akash

Makes sense, thanks for the help!

You are welcome its my pleasure to help you :slight_smile: :slight_smile:

The '328P has an internal voltage reference, that will not change as Vcc changes - say as Vcc drops from 4.2V with a freshly charged LiPo down to 3.7V as it discharges.

The level is 1.1V. You could use a resistor divider to get your measured signal down into the 1.1V range, and then have an unchanging reference for the ADC to make its measurements with.

https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/