The first question in any battery-powered project: how long will it last? The basic calculation is very simple, but the difference between a project that lasts a day and one that lasts two months usually comes down to one thing: sleep mode.
In this article we'll calculate battery life step by step, see why the number printed on the battery isn't always what you get, and how to measure your project's real consumption instead of guessing it.
The basic formula
Hours = (capacity in mAh ÷ current in mA) × 0.85
The 0.85 is a realistic margin, because a battery never delivers its full capacity: the circuit cuts out before the battery is completely empty, and capacity drops with high current, temperature and age.
Example: a 2000 mAh battery and an ESP32 running all the time, drawing about 80 mA:
- (2000 ÷ 80) × 0.85 ≈ 21 hours. Less than a day!
The secret: average current
Most IoT projects don't need to run all the time. A temperature sensor, for example, only needs to wake up every 10 minutes, take a reading, send it and go back to sleep.
Average = (active current × fraction of time active) + (sleep current × fraction of time asleep)
Example: the same ESP32 wakes for 10 seconds every 10 minutes (1.7% of the time), and draws about 10 µA in deep sleep:
- Average ≈ 80 × 0.0167 + 0.01 × 0.983 ≈ 1.34 mA
- Life ≈ (2000 ÷ 1.34) × 0.85 ≈ 1266 hours ≈ 52 days
From one day to about two months, without changing the battery! And notice something important: in this example the wake time is what eats the battery. Those 10 seconds account for 1.33 mA of the 1.34. So if you cut the wake time to 5 seconds, battery life almost doubles. But cutting sleep current from 10 to 5 µA would make no visible difference. Focus your effort on the part that consumes the most. The code and settings are in the ESP32 deep sleep article.
mAh or Wh?
mAh tells you how much current a battery gives for how long, but not at what voltage. A 2000 mAh lithium cell at 3.7 V stores 7.4 Wh of energy, while a 2000 mAh battery at 12 V stores 24 Wh, more than three times as much.
The difference shows up when there's a voltage converter between the battery and the circuit. If you run a 5 V circuit drawing 200 mA from a lithium cell through a boost module with 85% efficiency:
- Power at 5 V = 5 × 0.2 = 1 W.
- Power drawn from the battery = 1 ÷ 0.85 ≈ 1.18 W.
- Battery current at 3.7 V ≈ 1.18 ÷ 3.7 ≈ 320 mA, not 200!
So when voltages change it's more accurate to work in Wh: life = battery energy in Wh × efficiency ÷ load power in W. The same goes for power banks: the 10,000 mAh on the label is rated at the 3.7 V of the cells, and at the 5 V output you'll actually get about 6000 to 6500 mAh.
Typical consumption of common parts
These are rough figures for comparison; the real reference is measuring it yourself:
| Part | Approximately |
|---|---|
| Arduino Uno (whole board) | 45 – 50 mA |
| Arduino Nano | 20 – 30 mA |
| ESP32 with Wi-Fi on | 80 – 120 mA average, peaks up to 300 mA while transmitting |
| ESP32 chip in deep sleep | about 10 µA |
| Power LED on any module | 2 – 5 mA |
| Small OLED display | 10 – 20 mA depending on how much is lit |
| Small servo while moving | 100 – 500 mA |
Notice that the little power LED on the board alone can draw 200 times more than the whole chip asleep.
How to measure real consumption
- Multimeter in series: disconnect the positive wire and put the multimeter, set to mA, between the battery and the circuit. Good for steady currents. Be aware that many multimeters have enough internal resistance on the mA range to cause a voltage drop that resets the circuit during current peaks. The right method is in the multimeter article.
- Sleep mode: switch the meter to the µA range after the circuit goes to sleep, not before, so the wake-up peak doesn't blow the fuse.
- Changing current: a multimeter shows random numbers with Wi-Fi because the current changes within milliseconds. Here a module like the INA219 measures current frequently and you average it in code. See current sensing in projects.
- The patient method: fully charge the battery, run the project, and log the voltage, or the last time it sent data, every few hours. Slow, but it measures everything together.
Why does the battery die sooner than calculated?
- The board, not just the chip: development boards have a regulator, a power LED and a USB chip. They can draw a few milliamps even while the chip sleeps, which ruins the whole calculation. Measure the board's real current with a multimeter.
- Wake time longer than expected: connecting to Wi-Fi alone can take a few seconds at high current (momentarily hundreds of milliamps). Measure the actual time.
- The regulator: an old linear regulator can draw a milliamp or more by itself. Look for an LDO with a quiescent current in microamps. The comparison is in the 7805 and LDO regulators article.
- Cut-off voltage: the circuit can stop working while the battery still has charge, because the voltage dropped below what the regulator or chip needs.
- Temperature: severe cold noticeably reduces available capacity, and severe heat shortens the battery's own lifespan.
- Self-discharge: a battery empties by itself even with no load. Alkaline cells lose about 2 to 3% per year, lithium about 2 to 3% per month, and standard NiMH can lose 20% or more in the first month. In a project meant to last a year, that matters.
- Fake capacity: 18650 cells labelled 9800 mAh, for example, hold far less. The best genuine cells are around 3500 mAh. More in the battery types article.
Tips for longer life
- Use deep sleep and wake the chip as rarely as possible.
- Turn off LEDs and sensors you don't need, or power them from a GPIO pin or a transistor you can switch off.
- Send data in batches instead of every reading on its own.
- Choose a regulator with a low quiescent current, or run the circuit straight from the battery if the voltage suits it.
- Shorten wake time: a static IP instead of DHCP saves seconds on every Wi-Fi wake-up.
- If the project sits somewhere sunny, a small panel and a charger let it live without ever changing the battery. See solar panels for projects.
FAQ
If I connect two batteries in parallel, will life double? Yes, the capacity adds up and the voltage stays the same, provided both batteries are the same type, condition and voltage before connecting. Series connection raises voltage, not life.
Is a 9 V PP3 battery good for an Arduino? It will run for a few hours. Its capacity is small (about 500 mAh), and the board's linear regulator burns half its energy as heat going from 9 to 5 V.
How do I know from code that the battery is nearly empty? Measure its voltage with a voltage divider on an ADC pin and send an alert when it drops below a threshold. The method is in the voltage divider article.
Calculate it in a second
The battery life calculator works out life from capacity and consumption, and has a mode for average current with sleep. And if you're designing a battery pack, try the 18650 battery pack calculator.