We've already shown that 1 milliamp-hour is 3.6 Coulombs. We also know than 1 Volt applies 1 Joule of energy to each Coulomb of charge. Putting those together, we can calculate the actual energy storage for some of the common battery sizes:

1.5V AAA cell 1.5V AA cell 1.5V C cell 1.5V D cell
3V CR1220 coin cell 3V CR1620 coin cell 3V CR2032 coin cell
3.7V LiPo pack 3.7V 18650 LiPo |
5.4J 5.4J 5.4J 5.4J
10.8J 10.8J 10.8J
13.7J 13.7J |
1,200mAh 2,700mAh 8,000mAh 12,000mAh
40mAh 80mAh 240mAh
100mAh 2,200mAh |
6,480J 14,580J 42,300J 64,800J
432J 864J 2,592J
1,370J 30,140J |

When you put cells in series, the Joules per millamp-hour add together. Each cell in a 4.5V 3xAA pack adds 5.4J, for a total of 16.2J per milliamp-hour. The total energy stored in the pack is 43,740J.

A 4.5V circuit that uses 10mA consumes 45mW of power, or 0.045J per second. A quick comparison with the pack's stored energy shows that the pack should last a little less than a million seconds, or about 270 hours.

## Putting the units to work

Now let's go back to that example of an ESP8266 that wakes up once every ten minutes, uses 5mA to read a sensor for maybe 100ms, then makes a Wifi connection that uses 80mA for an average of, say, 12 seconds before shutting down again.

The ESP8266 runs at 3.3V, and let's assume that the sensor does too. 5mA @ 3.3V consumes 16.5mW or 0.016.5 Joules per second. The sensor is active for 100ms, so it uses a total of 0.00165 Joules during that time:

Sensor |
3.3V |
5mA |
16.5mW |
0.1s |
0.00165J |
- |

The Wifi connection uses 80mA @ 3.3V, which comes to 264mW or 0.264J/s. Running the connection for 12 seconds consumes 3.168 Joules.

Adding the two together, let's call the average work 3.17 Joules each time the ESP8266 wakes up:

Sensor Wifi
Awake |
3.3V 3.3V
- |
5mA 80mA
- |
16.5mW 264mW
- |
0.1s 12s
- |
0.00167J 3.168J
3.17J |
- -
3.17J/cycle |

The ESP8266 spends the rest of its time sleeping, and let's say it draws 70uA during that time.

70uA @ 3.3V is 231uW, or 231 millionths of a Joule per second.

The ESP8266 spends 12.1 seconds awake per 10-minute cycle, and sleeps the remaining 587.9 seconds. That means the ESP8266 uses 0.136 Joules per cycle sleeping.

Its total energy consumption per cycle is about 3.3 Joules:

Sensor Wifi
Awake Asleep Sum |
3.3V 3.3V
- 3.3V - |
5mA 80mA
- 70uA - |
16.5mW 264mW
- 231uW - |
0.1s 12s
- 587.9s - |
0.00165J 3.168J
3.17J 0.136J 3.3J |
- -
3.17J/cycle 0.136J/cycle 3.3J/cycle |

Now it's time to convert what we have into values that are more convenient to work with.

Each cycle is 600 seconds long and consumes 3.3 Joules of energy. If we just divide the energy by the time we get 0.0055 Joules per second, or an average power of 5.5mW.

If we divide 5.5mW by 3.3V, we get an average current of 1.67mA.

*(running that through Ohm's Law, the system consumes about the same amount of energy as a 2k resistor that's always connected between 3.3V and GND)*

We can also scale the 5.5mW up to an average rate of 19.8 Joules per hour:

Sensor Wifi
Awake Asleep Sum
Equivalent |
3.3V 3.3V
- 3.3V -
3.3V |
5mA 80mA
- 70uA -
1.67mA |
16.5mW 264mW
- 231uW -
5.5mW |
0.1s 12s
- 587.9s -
3600s |
0.00165J 3.168J
3.17J 0.136J 3.3J
19.8J |
- -
3.17J/cycle 0.136J/cycle 3.3J/cycle
19.8J/hr |

If we want to power the ESP8266 from the 3xAA battery pack that holds 43,740 Joules of energy, it's tempting to use that value of 19.8J/hr and think we can get more than 2,000 hours of battery life.

That's wrong though: the battery pack's voltage is 4.5V, while we've done all of our other calculations for a circuit running at 3.3V.

The difference in voltage has to be burned off as heat in the 3.3V regulator, and that's another kind of work.

That's where calculating the average current comes in:

The difference between 4.5V and 3.3V is 1.2V, and if we multiply that by the 1.67mA calculated above, we get 2mW of power consumption in the regulator.

Multiplying 0.002J/s by 3600 seconds tells us the voltage regulator uses about 7.2J per hour.

Adding that to the 19.8J/hr the ESP8266 uses gives us a total power consumption of 27J/hr from a 4.5V power source:

Sensor Wifi
Awake Asleep Sum
Equivalent Regulator Sum |
3.3V 3.3V
- 3.3V -
3.3V 1.2V 4.5V |
5mA 80mA
- 70uA -
1.67mA 1.67mA 1.67mA |
16.5mW 264mW
- 231uW -
5.5mW 2mW 7.5mW |
0.1s 12s
- 587.9s -
3600s 3600s 3600s |
0.00165J 3.168J
3.17J 0.136J 3.3J
19.8J 7.2J 27J |
- -
3.17J/cycle 0.136J/cycle 3.3J/cycle
19.8J/hr 7.2J/hr 27J/hr |

Based on that estimate, we can expect the 3xAA pack to last around 1620 hours (about 67 days):

Sensor Wifi
Awake Asleep Sum
Equivalent Regulator Sum
Project 3 x AA pack |
3.3V 3.3V
- 3.3V -
3.3V 1.2V 4.5V
4.5V 4.5V |
5mA 80mA
- 70uA -
1.67mA 1.67mA 1.67mA
- - |
16.5mW 264mW
- 231uW -
5.5mW 2mW 7.5mW
- - |
0.1s 12s
- 587.9s -
3600s 3600s 3600s
1620hr - |
0.00165J 3.168J
3.17J 0.136J 3.3J
19.8J 7.2J 27J
43,740J 43,740J |
- -
3.17J/cycle 0.136J/cycle 3.3J/cycle
19.8J/hr 7.2J/hr 27J/hr
27J/hr - |

## Learning from the results

The most interesting thing all that tells us is that we're wasting a *lot* of energy in the voltage regulator.. almost 40% of the total.

If we switch to a 2200mAh 3.7V 18650 LiPo, the 3.3V voltage regulator will only have to drop 0.4V.

Using the same 1.67mA estimate for the average current, that reduces the regulator's power consumption to 670uW, which scales up to about 2.4J/hr.

Adding that to the ESP8266's consumption of 19.8J/hr gives us a total of 22.2J/hr:

Sensor Wifi
Awake Asleep Sum
Equivalent Regulator Sum
Project 18650 LiPo |
3.3V 3.3V
- 3.3V -
3.3V 0.4V 3.7V
3.7V 3.7V |
5mA 80mA
- 70uA -
1.67mA 1.67mA 1.67mA
- - |
16.5mW 264mW
- 231uW -
5.5mW 668uW 6.168mW
- - |
0.1s 12s
- 587.9s -
3600s 3600s 3600s
1357hr - |
0.00165J 3.168J
3.17J 0.136J 3.3J
19.8J 2.4J 22.2J
30,125J 30,135J |
- -
3.17J/cycle 0.136J/cycle 3.3J/cycle
19.8J/hr 2.4J/hr 22.2J/hr
22.2J/hr - |

The 18650 holds 30,140J, so we can expect it to last around 1357 hours (about 56 days)

We still lose energy in the voltage regulator, but only about 11% of the total.

The LiPo doesn't last quite as long as the 3xAA pack, but the 3xAA pack wastes almost four times as much energy as the LiPo.