5 years, 6 months ago.

How to measure battery percentage

Hi All,

I am pretty new to mbed and also new to electronics in general. I am trying to develop a small application that checks the battery percentage and based on that it will make an HTTP connection to our server. I am using an MTQ-H5-B01 dragonfly on a UDK2 board, and a 3.7v Lithium Polymer battery.

So my questions are:

1) How to get the voltage and measure the battery percentage?

2) If measured, how to know if voltage measured is coming from battery or direct plugin?

I have checked the below links but they are not providing required results:



Regards, Dawit

To mesure the battery-voltage you need some kind of reference-voltage, e.g. a linear-regulator or the supply of the mcu, then you can compare the two voltages (via analog-in and a voltage-divider). The plug-in-detection could be managed with a digital-in-pin connected to the supply-line of the charging-circuit (pay attention on on the maximum input-voltage and use a voltage-divider is needed). Some battery-charger-ICs provide informations about the battery, I don't know your board, maybe you can use something like that.

posted by Theo Bestenlehner 06 Aug 2017

1 Answer

5 years, 6 months ago.


It's almost impossible to accurately predict battery percentage from voltage alone.

This stack exchange article is a good introduction:


Cheers, Nick

Accepted Answer