Capstone · #19 of 48
Power Budget + Measurement
Calculating Battery Lifetime
Why it matters
Power budget tells you if your design will work. Without it, you’re guessing how long the battery will last.
The idea
What Is a Power Budget?
A power budget calculates total energy consumption:
- Active mode: Current × time
- Sleep mode: Current × time
- Total: Sum of all modes
- Battery capacity: Total energy available
Typical Values
ESP32 power consumption:
- Active (Wi‑Fi off): ~40mA
- Active (Wi‑Fi on): ~80mA
- Deep sleep: ~10µA
- Wi‑Fi transmit: ~170mA
Calculation
For 5-minute cycle:
- Active: 80mA × 3s = 240mAs
- Sleep: 10µA × 297s = 2.97mAs
- Total: ~243mAs per cycle
Battery Lifetime
For 2000mAh battery:
- Capacity: 2000mAh × 3600s/h = 7,200,000mAs
- Cycles: 7,200,000 / 243 ≈ 29,600 cycles
- Lifetime: 29,600 × 5min ≈ 103 days
Measurement
Use multimeter in current mode:
- Break circuit (series measurement)
- Measure active current
- Measure sleep current (may need µA range)
- Verify calculations
Demo
Adjust Active Current, Active Time, Sleep Current, and Sleep Time to see how battery lifetime changes.
Watch for:
- Total energy per cycle — lower is better
- Battery lifetime — days/months/years
- Impact of active time — reducing active time dramatically improves lifetime
E/cycle: 243 mA·s lifetime: 103 days
Key takeaways
- Power budget = sum of (current × time) for all modes
- Deep sleep is essential — 10µA vs 80mA active
- Minimize active time to maximize battery lifetime
- Measure actual current consumption to verify calculations
Going deeper
Real-world power consumption varies with temperature, battery age, and component tolerances. Always add a 20–30% safety margin. For production, use a power profiler (like Nordic Power Profiler) to measure actual consumption. Consider battery self-discharge (~5% per month for LiPo).
Math details
Power budget formula:
E_cycle = (I_active × t_active) + (I_sleep × t_sleep)
Where:
E_cycle = energy per cycle (mAs)
I_active = active current (mA)
t_active = active time (s)
I_sleep = sleep current (µA, convert to mA)
t_sleep = sleep time (s)
Battery lifetime:
Cycles = Battery_capacity (mAs) / E_cycle
Lifetime = Cycles × Cycle_time
Example:
I_active = 80mA, t_active = 3s → 240mAs
I_sleep = 10µA = 0.01mA, t_sleep = 297s → 2.97mAs
E_cycle = 243mAs
Battery: 2000mAh = 7,200,000mAs
Cycles = 7,200,000 / 243 = 29,600
Lifetime = 29,600 × 5min = 148,000min = 103 days
Implementation
LLM Prompt: Power Budget Calculator
Write Rust function to calculate power budget and battery lifetime.
Input: active current, active time, sleep current, sleep time, battery capacity.
Output: energy per cycle, cycles, lifetime (days). Include validation:
warn if lifetime < 30 days (may need optimization).
Lab Exercise
- Measure active current with multimeter (series measurement)
- Measure sleep current (may need µA range)
- Time each operation (sensor read, Wi‑Fi connect, transmit)
- Calculate power budget — verify < 300mAs per cycle
- Calculate battery lifetime — verify > 90 days
Mastery