October 09, 2021

Battery Life Calculator: Theory and Java Software

When faced with the design of a battery-powered device the first question we must answer is: How much the batteries will last?

The answer to the above question determines how often the battery will need to be replaced, and even allows you to distinguish a viable design or product from one that is not. Suppose you have installed a couple of thousand sensors and some time later you find out that the batteries last only a couple of weeks. Congratulations, you've just messed up your life.

For a device with only one consumption state (constant current consumption) this is relativelly straight forward, but for devices with multiple consumption states it is not.

Briot Tracer Scanner Repair

In this post I present how to estimate battery life and a JavaFX software to not only obtain the battery life given different consumption states of a device, but also to evaluate how much a variation of one of the two parameters (time or current) of each state will affect the battery life.

Single State Consumption Device

Some simplifications are necessary to facilitate the calculation of battery life, otherwise it could be a very complicated and convoluted task.

  • The internal resistance of the battery is constant.
  • The voltage of the battery does not vary.
  • The capacity (total energy) of the battery does not depend on the discharge rate.
  • Temperature and temperature variations are not taken into account.

With these simplifications the battery is an ideal device (ideal voltage source) with zero resistance and constant voltage, as long as there is energy left in it.

The energy capacity of a battery is a characteristic that reflects the amount of energy stored in it and is expressed in Ampere-hour ($\class{inlineFormula}{\rm{Ah}}$). Therefore we can calculate, under the above conditions, the battery life given the current consumption of a device. If we have a device that consumes a constant current $\class{inlineFormula}{\rm{I}}$, the battery life ($\class{inlineFormula}{\rm{B_{dur}}}$) given the battery capacity ($\class{inlineFormula}{\rm{B_{cap}}}$) can be calculated as:

$$ \class{formula}{\rm{B_{dur} = \frac{B_{cap}}{I}}} \qquad (1) $$
If we have an LS R976 OSRAM LED connected to a 6LR61 Energizer 9V battery through a resistor of $\class{inlineFormula}{\rm{390 \Omega}}$, the current through the LED is: $\class{inlineFormula}{\rm{I=\frac{(9,0-2,0)}{320}\simeq 17,95mA}}$. Given the battery capacity ($\class{inlineFormula}{\rm{B_{cap}=600mAh}}$) then the battery will last: $\class{inlineFormula}{\rm{B_{dur} \simeq \frac{600}{17,95} = 33,4h}}$.

The above example is under ideal conditions and should be interpreted as the maximum theoretical battery life. In real conditions the battery life will always be shorter, due to the simplifications made above. The further the actual conditions are from the ideal conditions, the shorter the battery life will be.

Multi-State Consumption Device

If the device has more than one consumption state: How can we estimate the battery life?

The answer is actually simple: we must determine the average current consumption and substitute it in $\class{inlineFormula}{\rm{(1)}}$.

For a time function $\class{inlineFormula}{\rm{I(t)}}$, its average is calculated as:

$$ \class{formula}{\rm{\overline{I} = \int_{0}^{\infty}{ I(t) \cdot dt} }} \qquad (2) $$

If the function $\class{inlineFormula}{\rm{I(t)}}$ (the current consumption) is periodic with period T then we can express (2) as:

$$ \class{formula}{\rm{\overline{I} = \frac{\displaystyle\int_{0}^{T}{ I(t) \cdot dt}}{T} }} \qquad (3) $$

If the function $\class{inlineFormula}{\rm{I(t)}}$ has $\class{inlineFormula}{\rm{n}}$ different consumption states, with a constant current $\class{inlineFormula}{\rm{I_n}}$ for a time $\class{inlineFormula}{\rm{T_n}}$ in each, then (3) can be expressed as:

$$\class{formula}{\rm{\overline{I} = \frac{ \left( \displaystyle\sum_{0}^{n}{ I_n \cdot T_n } \right) }{T} }} \qquad (4) $$

Finally, substituting (4) in (1):

$$ \class{formula}{\rm{B_{dur} = \frac{B_{cap} \cdot T }{ \left( \displaystyle\sum_{0}^{n}{ I_n \cdot T_n} \right) }}} \qquad (5) $$

Multi-State Consumption Device Example

As an example, we will apply equation (5) to a device with a consumption profile as shown in the following image.

Current Consumption Profile
Tri-State Current Consumption Profile

Hence (5) becomes:

$$ \class{formula}{\rm{B_{dur} = \frac{B_{cap} \cdot (t_1+t_2+t_3) }{ \left( I_1 \cdot t_1 + I_2 \cdot t_2 + I_3 \cdot t_3 \right) }}} \qquad (6) $$

Assume that the required values are as indicated in the following table and that the battery capacity is $\class{inlineFormula}{\rm{2500mAh}}$.

State Current Time
$\class{inlineFormula}{\rm{S_1: Active\ sensing}}$ $\class{inlineFormula}{\rm{I_1=40mA}}$ $\class{inlineFormula}{\rm{t_1=3.2s}}$
$\class{inlineFormula}{\rm{S_2: Active\ TX}}$ $\class{inlineFormula}{\rm{I_2=160mA}}$ $\class{inlineFormula}{\rm{t_2=0.8s}}$
$\class{inlineFormula}{\rm{S_3: Sleep}}$ $\class{inlineFormula}{\rm{I_3=1.2\mu A}}$ $\class{inlineFormula}{\rm{t_3=3600s}}$

We can then calculate the battery life:

$$ \class{formula}{\rm{B_{dur} = \frac{2500 \cdot (3.2 + 0.8 + 3600) }{ \left( 40 \cdot 3.2 + 160 \cdot 0.8 + 1.2x10^{-3} \cdot 3600 \right) }}} \simeq 34611\ h $$

In some cases it is better to present this value using another scale, such as day or year:

$$ \class{formula}{\rm{B_{dur} \simeq 1442\ d \simeq 3.95\ y }} $$

Software to Calculate the Battery Life for a Multi-State Device

Applying the formula (5) as shown above, we can estimate the battery life for any device with multiple consumption states, given the required values. We only need an easy and practical way to perform such a calculation.

I could have implemented a software to estimate battery life using the formula (5) in Octave or even in LibreOffice Calc, but why should I choose such a simple solution when I can learn to develop an application using JavaFX for the first time?

I'm not a software developer, I can program in Java but I'm pretty sure there must be more efficient, elegant or even correct ways to program this software.

We are actually presented with the opportunity to present in a graph how much the battery life will change when one of the parameters (time or current) changes a certain percentage around its defined value. This way you can easily see how much room there is to improve the battery life.

The following figure shows the application interface.

Battery Life Calculator Java Software GUI Graphical User Interface
Battery Life Calculator Java Software - Graphical User Interface

The following figure shows the result obtained when we put in the application the values of the example presented above. It can be verified that the result is the same as the result of substituting in (6) the values of the example.

Battery Life Calculator Java Software Example of Use
Battery Life Calculator Java Software - Example of Use

The graph shows that if you need more than 5 years of estimated battery life and the only parameter that can be modified is the time duration of the Active Sens state, then we must reduce its duration to less than $\class{inlineFormula}{\rm{1.75s}}$.

The function of each GUI element is self-explanatory, but for completeness, the function of each is explained below:

GUI Element Description
Battery Capacity The capacitiy of the battery in mAh must be specified in this field
Variation Allows to select the desired percentage variation of the selected parameter (Time or Current) for the battery life graph
State Allows you to select the status (from the status table) to be used in the graph of battery life
Parameter Allows to select the parameter (Time or Current) to be used in the battery life graph
States (Table) Table containing all the consumption states and the parameters of each one
Add (Button) Add an Empty state to the state table (after adding a state you must correct its parameters, otherwise it is not considered for battery life estimation)
Remove (Button) Removes the selected consumption state from the table
Scale Allows to select the scale used for battery life estimation (also modifies the scale of the graph)
Battery Life It presents the estimation of the battery life based on the valid states of the state table and the selected scale

Software logic/characteristics:

  • This is a JavaFX application distributed as a standalone java application. To run it you must extract the contents of the zip file and execute $\class{inlineFormula}{\rm{ \verb|./bin/batteryLifeCalculator.sh| }}$ in the terminal.
  • It uses the data contained in the state table and the battery capacity to estimate the battery life according to formula (5).
  • It presents in a line graph how much the battery life estimate changes according to the combination of selections: Percent Variation, State, and Parameter.
  • If a value is zero, empty or contains letters, then indicate the error by changing the background of the field containing the error (both for the "Current" and "Time" fields of the table, as well as for the battery capacity).
  • States can be added and removed from the state table using the buttons provided below it. If the number of valid states is one or less, the chart is hidden as it does not make sense to present a variation for a single state.
  • When adding a state it is necessary to correct at least the current and time values. The new status will not be taken into account for the battery life estimation until the data is valid. (current > 0, and time > 0).

Software known problems:

  • Sometimes the chart loses its defined style. To fix this, just make a change in one of the comboboxes to force an update of the chart. (I have not found a way to stop this from happening).

I hope you find this application useful. If you encounter any problems you can report them by writing a comment on this post. I can't promise a quick fix, or even a solution but I will try (remember I am not a software developer).

This is the first version of the battery life calculator and there are some things to improve or add to the application. I hope I can find the time to do it, stay close.

Remember that the results presented by this application are based on the formula (5) and that some simplifications have been made to obtain it. The actual battery life may differ greatly if the conditions of use deviate too much from normal conditions.

In the following link you can download the standalone java application.

Download the standalone Battery Life Calculator (v 1.0) Java Software
(Copyright 2021 Diego Bouvier - GPLv3)

In the following link you can download the source code of the application (IntelliJ IDEA project).

Download the source code of Battery Life Calculatr (v 1.0) (IntelliJ IDEA project)
(Copyright 2021 Diego Bouvier - GPLv3)

No comments: