Skip to content

Battery Life Calculation

Battery Life Calculation

This section provides a systematic method for calculating battery life in IoT button applications. By the end of this section, you will be able to:

  • Calculate energy consumption for both active and sleep periods
  • Estimate battery life based on usage patterns
  • Create a battery life budget for buyer consultations
  • Explain the factors that affect battery longevity

Before starting this section, please ensure:

Battery life is calculated using the concept of milliamp-hours (mAh) — a measure of electrical charge capacity.

Energy Consumed (mAh) = Current (mA) × Time (hours)
Example: A device drawing 60 mA for 5 seconds
= 60 mA × (5 / 3600) hours = 0.083 mAh

For a device with two states (active + sleep), total daily consumption is:

Daily Consumption = (Active Current × Active Time per Day) + (Sleep Current × Sleep Time per Day)

A button press cycle follows this pattern:

Current
80mA ┤
│ ┌───────────────────┐
│ │ Active Phase │
│ │ (WiFi + MQTT) │
│ └───────────────────┘
│ ┌──────────────
│ │ Deep Sleep Phase
~5µA ┤────────────────────┘
└─────────────────────────────────────── Time
↑ Press ↑ Back to ↑ Next Press
Button Sleep (hours/days later)
│◄── Active (~5s) ──────►│◄─── Sleep (hours to days) ──►│

Step 1: Measure or Estimate Current Values

Section titled “Step 1: Measure or Estimate Current Values”
ParameterSymbolXIAO ESP32-C3 ValueNotes
Active current (WiFi on)I_active60 mAMeasured at 3.3V
Active current (WiFi off)I_idle15 mANot used in button application
Deep sleep currentI_sleep5 µA = 0.005 mARTC + GPIO wake configured
WiFi connection timeT_wifi2-3 secondsOptimized connection
MQTT publish timeT_mqtt0.5-1 secondSingle message
Post-publish delayT_post0.5 secondsSerial flush, cleanup
Active time per press:
T_active = T_wifi + T_mqtt + T_post
= 2.5s + 0.5s + 0.5s
= 3.5 seconds
Energy per press:
E_press = I_active × (T_active / 3600)
= 60 mA × (3.5 / 3600) hours
= 0.0583 mAh per press

Step 3: Calculate Daily Energy Consumption

Section titled “Step 3: Calculate Daily Energy Consumption”

Example: 2 presses per day

Active energy:
E_active_daily = 0.0583 mAh × 2 = 0.1166 mAh
Sleep energy (24 hours minus active time):
Sleep time = 24 - (2 × 3.5 / 3600) ≈ 23.998 hours
E_sleep_daily = 0.005 mA × 23.998 h = 0.120 mAh
Total daily consumption:
E_daily = 0.1166 + 0.120 = 0.237 mAh per day

Example formulas for different usage frequencies:

Presses/DayActive Energy (mAh)Sleep Energy (mAh)Total Daily (mAh)
0 (standby)00.1200.120
10.0580.1200.178
20.1170.1200.237
50.2920.1200.412
100.5830.1200.703
201.1670.1201.287
502.9170.1193.036
Usable battery capacity = Capacity × Depth of Discharge (DoD)
For safety, use 80% DoD (avoid deep discharge):
Usable = 350 mAh × 0.8 = 280 mAh
Battery life = Usable capacity / Daily consumption
Example (350 mAh battery, 2 presses/day):
Life = 280 mAh / 0.237 mAh/day = 1,181 days ≈ 3.2 years

Battery life for common scenarios:

Battery1 Press/Day2 Presses/Day10 Presses/Day50 Presses/Day
150 mAh674 days506 days171 days40 days
300 mAh1,348 days1,012 days341 days79 days
350 mAh1,573 days1,181 days398 days92 days
500 mAh2,247 days1,685 days569 days132 days
1000 mAh4,494 days3,370 days1,138 days264 days

Real-world adjustment: These calculations assume ideal conditions. Real battery life is typically 70-85% of calculated values due to battery aging, temperature variations, and measurement tolerances.

For rapid estimation during buyer consultations, use these simplified formulas:

Battery life (days) ≈ (Battery capacity × 0.8) / (0.12 + 0.058 × Presses_per_day)
Where:
- 0.8 = usable capacity factor
- 0.12 = baseline daily sleep consumption (mAh)
- 0.058 = energy per button press (mAh)

Example (350 mAh battery, 5 presses/day):

Life ≈ (350 × 0.8) / (0.12 + 0.058 × 5)
= 280 / 0.41
≈ 683 days ≈ 22 months
FactorImpactMitigation
Battery self-discharge3-5% capacity loss/monthUse quality batteries; account in calculation
Temperature10-20% reduction in cold (< 0°C)Insulate or use appropriate chemistry
Battery aging20% capacity loss after 300 cyclesReplace batteries annually in production
WiFi signal strengthWeak signal → longer connection time → higher energyEnsure good WiFi coverage
Measurement tolerances±10% on current measurementsAdd 20% safety margin
Capacitor leakage1-5 µA additional drainMinimize external components
  • Per-press energy calculated and consistent with measurements
  • Daily consumption model accounts for actual usage pattern
  • Safety margin (20%) included in final estimate
  • Battery life estimate matches real-world results
  • Low-battery warning threshold calculated

Issue: Battery Life Shorter Than Calculated

Section titled “Issue: Battery Life Shorter Than Calculated”

Possible Causes:

  • Actual sleep current higher than measured (check GPIO states)
  • WiFi connection takes longer than expected
  • Battery capacity lower than rated (cheap batteries)
  • Temperature effects reduce effective capacity

Solution:

// Log actual active time for verification
void logActiveTime() {
static unsigned long startTime = 0;
if (startTime == 0) {
startTime = millis();
} else {
unsigned long activeMs = millis() - startTime;
Serial.print("Actual active time: ");
Serial.print(activeMs);
Serial.println(" ms");
startTime = 0;
}
}
  • Always add a 20% safety margin to calculated battery life
  • Measure actual current rather than relying on datasheet values
  • Consider the weakest link — often WiFi connection time, not sleep current
  • Monitor battery voltage in firmware to detect end-of-life
  • Use known-brand batteries — generic batteries often have lower actual capacity
  • Do not discharge LiPo below 3.0V — permanent damage and safety risk
  1. Per-press energy is ~0.058 mAh for XIAO ESP32-C3 with optimized WiFi
  2. Daily sleep consumption is ~0.12 mAh regardless of usage
  3. Usage frequency affects battery life linearly — more presses = proportionally shorter life
  4. 80% depth of discharge is a safe usable capacity limit
  5. Real life is 70-85% of calculated — add safety margins

Target Audience: Alibaba.com IoT Pre-sales Engineers
Status: ✅ Completed