power-budget-calculator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Power Budget Calculator

功耗预算计算器

Estimates power consumption and battery life for embedded projects.
为嵌入式项目估算功耗和电池寿命。

Resources

资源

  • scripts/calculate_power.py - Python calculator with component database, duty cycle support, battery life estimation
  • references/component-database.md - Comprehensive current draw reference from datasheets
  • assets/example-project.json - Sample project configuration
  • scripts/calculate_power.py - 带有组件数据库、占空比支持、电池寿命估算功能的Python计算器
  • references/component-database.md - 来自数据手册的全面电流消耗参考资料
  • assets/example-project.json - 示例项目配置

Quick Start

快速开始

Run the calculator interactively:
bash
uv run --no-project scripts/calculate_power.py --interactive
Or calculate for a single component:
bash
uv run --no-project scripts/calculate_power.py --component ESP32 --mode deep_sleep --duty 95
Load a project configuration:
bash
uv run --no-project scripts/calculate_power.py --json assets/example-project.json --output report.md
List all components in database:
bash
uv run --no-project scripts/calculate_power.py --list
以交互模式运行计算器:
bash
uv run --no-project scripts/calculate_power.py --interactive
或针对单个组件进行计算:
bash
uv run --no-project scripts/calculate_power.py --component ESP32 --mode deep_sleep --duty 95
加载项目配置:
bash
uv run --no-project scripts/calculate_power.py --json assets/example-project.json --output report.md
列出数据库中的所有组件:
bash
uv run --no-project scripts/calculate_power.py --list

When to Use

使用场景

  • "How long will my battery last?"
  • "What size battery do I need?"
  • "How much current does my project draw?"
  • Planning battery-powered projects
  • Optimizing for low power
  • "我的电池能续航多久?"
  • "我需要多大规格的电池?"
  • "我的项目消耗多少电流?"
  • 规划电池供电项目
  • 低功耗优化

Workflow

工作流程

Step 1: Gather Component List

步骤1:收集组件列表

Ask user for:
  1. Microcontroller (model and operating mode)
  2. All sensors and modules
  3. Displays
  4. Actuators (motors, LEDs, relays)
  5. Communication (WiFi, Bluetooth, LoRa)
  6. Operating profile (always on vs. duty cycle)
向用户询问:
  1. 微控制器(型号和工作模式)
  2. 所有传感器和模块
  3. 显示屏
  4. 执行器(电机、LED、继电器)
  5. 通信模块(WiFi、蓝牙、LoRa)
  6. 工作配置文件(持续运行 vs 占空比)

Step 2: Calculate Power Budget

步骤2:计算功耗预算

Run
scripts/calculate_power.py --interactive
for guided calculation, or use this template:
markdown
undefined
运行
scripts/calculate_power.py --interactive
进行引导式计算,或使用以下模板:
markdown
undefined

Power Budget: [Project Name]

功耗预算:[项目名称]

Operating Conditions

工作条件

  • Supply Voltage: [V]
  • Operating Modes: [Active/Sleep cycles]
  • Duty Cycle: [X% active, Y% sleep]
  • 供电电压:[V]
  • 工作模式:[活跃/睡眠周期]
  • 占空比:[X% 活跃,Y% 睡眠]

Component Current Draw

组件电流消耗

Always-On Components

持续运行组件

ComponentVoltageCurrentPowerNotes
[name][V][mA][mW][conditions]
...............
Subtotal-[mA][mW]-
组件电压电流功率备注
[名称][V][mA][mW][条件]
...............
小计-[mA][mW]-

Active Mode Only

仅活跃模式组件

ComponentVoltageCurrentPowerDuty %
[name][V][mA][mW][%]
...............
Subtotal-[mA][mW]-
组件电压电流功率占空比 %
[名称][V][mA][mW][%]
...............
小计-[mA][mW]-

Peak Current Events

峰值电流事件

EventCurrentDurationFrequency
[WiFi TX][mA][ms][per hour]
............
事件电流持续时间频率
[WiFi 发射][mA][ms][每小时]
............

Power Calculations

功耗计算

Average Current

平均电流

I_avg = (I_active × t_active + I_sleep × t_sleep) / t_total
I_avg = ([X]mA × [Y]s + [Z]mA × [W]s) / [T]s
I_avg = [result] mA
I_avg = (I_active × t_active + I_sleep × t_sleep) / t_total
I_avg = ([X]mA × [Y]s + [Z]mA × [W]s) / [T]s
I_avg = [结果] mA

Battery Life Estimate

电池寿命估算

Capacity: [X] mAh
Efficiency factor: 0.8 (80% usable)
Effective capacity: [X × 0.8] mAh

Runtime = Effective capacity / I_avg
Runtime = [X] mAh / [Y] mA
Runtime = [Z] hours ([days] days)
容量:[X] mAh
效率系数:0.8(80% 可用)
有效容量:[X × 0.8] mAh

续航时长 = 有效容量 / I_avg
续航时长 = [X] mAh / [Y] mA
续航时长 = [Z] 小时([天数] 天)

Recommendations

建议

  • [Power optimization suggestions]
  • [Battery type recommendation]
  • [Sleep mode configuration]
undefined
  • [功耗优化建议]
  • [电池类型推荐]
  • [睡眠模式配置]
undefined

Current Draw Database

电流消耗数据库

Microcontrollers

微控制器

Arduino (ATmega328P @ 5V)

Arduino (ATmega328P @ 5V)

ModeCurrentNotes
Active (16MHz)15-20mANo peripherals
Idle6mACPU stopped, peripherals on
Power-down0.1µAOnly WDT/external interrupt
With USB-Serial+50mACH340/FTDI chip always on
模式电流备注
Active (16MHz)15-20mANo peripherals
Idle6mACPU stopped, peripherals on
Power-down0.1µAOnly WDT/external interrupt
With USB-Serial+50mACH340/FTDI chip always on

ESP32 (WROOM-32)

ESP32 (WROOM-32)

ModeCurrentNotes
Active (WiFi TX)160-260mAPeak during transmission
Active (WiFi RX)95-100mAListening
Active (no WiFi)20-68mACPU only
Modem-sleep20mAWiFi off, CPU on
Light-sleep0.8mACPU paused
Deep-sleep10µARTC only
Hibernation5µARTC off
模式电流备注
Active (WiFi TX)160-260mAPeak during transmission
Active (WiFi RX)95-100mAListening
Active (no WiFi)20-68mACPU only
Modem-sleep20mAWiFi off, CPU on
Light-sleep0.8mACPU paused
Deep-sleep10µARTC only
Hibernation5µARTC off

ESP32-C3

ESP32-C3

ModeCurrentNotes
Active (WiFi TX)320mA peakBrief spikes
Active (BLE)50-100mADuring advertising
Active (no radio)25-35mACPU at 160MHz
Light-sleep130µAAuto wake
Deep-sleep5µARTC on
模式电流备注
Active (WiFi TX)320mA peakBrief spikes
Active (BLE)50-100mADuring advertising
Active (no radio)25-35mACPU at 160MHz
Light-sleep130µAAuto wake
Deep-sleep5µARTC on

RP2040 (Pico)

RP2040 (Pico)

ModeCurrentNotes
Active (both cores)25-50mADepends on clock
Single core15-25mAOne core dormant
Dormant0.18mAWake on GPIO/RTC
Sleep1.3mA
模式电流备注
Active (both cores)25-50mADepends on clock
Single core15-25mAOne core dormant
Dormant0.18mAWake on GPIO/RTC
Sleep1.3mA

RP2040 (Pico W)

RP2040 (Pico W)

ModeCurrentNotes
WiFi active50-150mADuring TX
WiFi idle30-40mAConnected, listening
WiFi off25-50mARadio disabled
模式电流备注
WiFi active50-150mADuring TX
WiFi idle30-40mAConnected, listening
WiFi off25-50mARadio disabled

Sensors

传感器

SensorActiveSleepNotes
DHT221.5mA50µADuring read
BME2800.35mA0.1µAForced mode
BMP2800.27mA0.1µA
MPU60503.8mA5µAAll axes
DS18B201.5mA1µADuring conversion
HC-SR0415mA2mANo true sleep
VL53L0X19mA5µADuring ranging
MAX30102600µA0.7µALow power mode
BH1750120µA1µAPower down mode
GPS (NEO-6M)45mA11mABackup mode
传感器活跃状态睡眠状态备注
DHT221.5mA50µADuring read
BME2800.35mA0.1µAForced mode
BMP2800.27mA0.1µA
MPU60503.8mA5µAAll axes
DS18B201.5mA1µADuring conversion
HC-SR0415mA2mANo true sleep
VL53L0X19mA5µADuring ranging
MAX30102600µA0.7µALow power mode
BH1750120µA1µAPower down mode
GPS (NEO-6M)45mA11mABackup mode

Displays

显示屏

DisplayActiveOff/SleepNotes
16x2 LCD (backlight)80-120mA1mABacklight dominates
16x2 LCD (no backlight)1-2mA1mA
SSD1306 OLED 128x648-20mA10µADepends on content
SSD1306 OLED 128x325-15mA10µA
ST7735 TFT20-40mA20mABacklight always on
ILI9341 TFT50-80mA50mA
E-Paper 2.9"8mA0µAOnly during refresh
显示屏活跃状态关闭/睡眠状态备注
16x2 LCD (backlight)80-120mA1mABacklight dominates
16x2 LCD (no backlight)1-2mA1mA
SSD1306 OLED 128x648-20mA10µADepends on content
SSD1306 OLED 128x325-15mA10µA
ST7735 TFT20-40mA20mABacklight always on
ILI9341 TFT50-80mA50mA
E-Paper 2.9"8mA0µAOnly during refresh

Communication Modules

通信模块

ModuleTX PeakRX/IdleSleepNotes
ESP8266 (module)170mA70mA20µADeep sleep
NRF24L0111.3mA13.5mA0.9µA
HC-05 Bluetooth40mA8mA2mA
RFM95 LoRa120mA10mA0.2µA
SIM800L GSM2A peak15mA1mANeeds big cap!
模块发射峰值接收/空闲睡眠备注
ESP8266 (module)170mA70mA20µADeep sleep
NRF24L0111.3mA13.5mA0.9µA
HC-05 Bluetooth40mA8mA2mA
RFM95 LoRa120mA10mA0.2µA
SIM800L GSM2A peak15mA1mANeeds big cap!

Actuators

执行器

ComponentCurrentNotes
LED (typical)10-20mAThrough resistor
RGB LED (each color)20mAPer channel
WS2812B NeoPixel60mA maxFull white
SG90 Servo (idle)10mANo load
SG90 Servo (moving)200-500mAUnder load
MG996R Servo500-900mAUnder load
Small DC motor100-500mAVaries with load
5V Relay module70-100mACoil energized
Buzzer (passive)30mA
组件电流备注
LED (typical)10-20mAThrough resistor
RGB LED (each color)20mAPer channel
WS2812B NeoPixel60mA maxFull white
SG90 Servo (idle)10mANo load
SG90 Servo (moving)200-500mAUnder load
MG996R Servo500-900mAUnder load
Small DC motor100-500mAVaries with load
5V Relay module70-100mACoil energized
Buzzer (passive)30mA

Sleep Mode Configurations

睡眠模式配置

ESP32 Deep Sleep Template

ESP32 Deep Sleep Template

cpp
#include <esp_sleep.h>

#define uS_TO_S_FACTOR 1000000ULL
#define TIME_TO_SLEEP 60  // seconds

void setup() {
    // Do measurements here
    
    // Configure wake-up source
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
    
    // Enter deep sleep
    esp_deep_sleep_start();
}

void loop() {
    // Never reached
}
cpp
#include <esp_sleep.h>

#define uS_TO_S_FACTOR 1000000ULL
#define TIME_TO_SLEEP 60  // seconds

void setup() {
    // Do measurements here
    
    // Configure wake-up source
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
    
    // Enter deep sleep
    esp_deep_sleep_start();
}

void loop() {
    // Never reached
}

Arduino Power-Down Template

Arduino Power-Down Template

cpp
#include <avr/sleep.h>
#include <avr/wdt.h>

void enterSleep() {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_mode();  // Sleep here
    sleep_disable();
}

// Wake on watchdog or external interrupt
ISR(WDT_vect) {
    // Wake up
}
cpp
#include <avr/sleep.h>
#include <avr/wdt.h>

void enterSleep() {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_mode();  // Sleep here
    sleep_disable();
}

// Wake on watchdog or external interrupt
ISR(WDT_vect) {
    // Wake up
}

Power Optimization Checklist

功耗优化清单

Hardware

硬件

  • Remove power LED (saves 5-10mA)
  • Remove USB-Serial chip for battery operation
  • Use LDO with low quiescent current (<10µA)
  • Add MOSFET to power-gate high-current peripherals
  • Use pull-downs on unused pins
  • Disable ADC when not reading
  • 移除电源LED(节省5-10mA)
  • 电池供电时移除USB-Serial芯片
  • 使用静态电流低的LDO(<10µA)
  • 添加MOSFET为高电流外设供电门控
  • 对未使用的引脚使用下拉电阻
  • 不读取时禁用ADC

Software

软件

  • Use sleep modes between readings
  • Reduce clock speed if possible
  • Batch data and transmit less frequently
  • Turn off WiFi/BLE when not needed
  • Disable brown-out detector in deep sleep
  • Use interrupts instead of polling
  • 读数间隔使用睡眠模式
  • 尽可能降低时钟速度
  • 批量处理数据并减少传输频率
  • 不需要时关闭WiFi/BLE
  • 深度睡眠时禁用欠压检测器
  • 使用中断而非轮询

Design Patterns

设计模式

Power Gating:
       VCC
    [P-MOSFET] ← GPIO (LOW = ON)
    [Sensor/Module]
       GND
Duty Cycling Formula:
I_average = (I_active × T_active + I_sleep × T_sleep) / T_total

Example: Sensor reads every 5 minutes
- Active: 50mA for 2 seconds
- Sleep: 10µA for 298 seconds

I_avg = (50mA × 2s + 0.01mA × 298s) / 300s
I_avg = (100 + 2.98) / 300
I_avg = 0.34mA

With 2000mAh battery:
Runtime = 2000mAh × 0.8 / 0.34mA = 4706 hours = 196 days
供电门控:
       VCC
    [P-MOSFET] ← GPIO (LOW = ON)
    [Sensor/Module]
       GND
占空比计算公式:
I_average = (I_active × T_active + I_sleep × T_sleep) / T_total

示例:传感器每5分钟读取一次
- 活跃状态:50mA,持续2秒
- 睡眠状态:10µA,持续298秒

I_avg = (50mA × 2s + 0.01mA × 298s) / 300s
I_avg = (100 + 2.98) / 300
I_avg = 0.34mA

使用2000mAh电池:
续航时长 = 2000mAh × 0.8 / 0.34mA = 4706小时 = 196天

Battery Reference

电池参考资料

Common Battery Types

常见电池类型

TypeVoltageTypical CapacityNotes
CR20323V220mAhVery low current only
2x AA Alkaline3V2500mAhGood for low power
3x AA Alkaline4.5V2500mAhDirect to 5V systems
4x AA Alkaline6V2500mAhWith LDO to 5V
18650 Li-ion3.7V2000-3500mAhRechargeable, popular
LiPo 1S3.7VVariousFlat, light
9V Alkaline9V500mAhPoor energy density
类型电压典型容量备注
CR20323V220mAh仅适用于极低电流场景
2节AA碱性电池3V2500mAh适合低功耗场景
3节AA碱性电池4.5V2500mAh直接为5V系统供电
4节AA碱性电池6V2500mAh通过LDO转换为5V
18650锂离子电池3.7V2000-3500mAh可充电,使用广泛
1S LiPo电池3.7V多种规格扁平轻便
9V碱性电池9V500mAh能量密度低

Voltage Over Discharge

过放电压

18650/LiPo Discharge Curve:
Capacity%   Voltage
─────────────────────
100%        4.2V
80%         3.9V
50%         3.7V
20%         3.5V
0%          3.0V (cut-off!)

Never discharge below 3.0V - damages cell!
Alkaline AA Discharge:
Capacity%   Voltage (per cell)
─────────────────────────────
100%        1.5V
50%         1.2V
0%          0.9V

Many devices stop working below 1.1V/cell
18650/LiPo放电曲线:
容量%   电压
─────────────────────
100%        4.2V
80%         3.9V
50%         3.7V
20%         3.5V
0%          3.0V (截止电压!)

切勿放电至3.0V以下 - 会损坏电池!
AA碱性电池放电:
容量%   单节电压
─────────────────────────────
100%        1.5V
50%         1.2V
0%          0.9V

许多设备在单节电压低于1.1V时停止工作

Quick Calculator

快速计算器

Enter your values:

Always-on current: ______ mA
Active current: ______ mA
Active time: ______ seconds
Sleep current: ______ mA  
Sleep time: ______ seconds
Battery capacity: ______ mAh

Average current = (Active_mA × Active_s + Sleep_mA × Sleep_s) / Total_s
                = (_____ × _____ + _____ × _____) / _____
                = _____ mA

Runtime = Capacity × 0.8 / Average_current
        = _____ × 0.8 / _____
        = _____ hours
        = _____ days
输入你的数值:

持续运行电流:______ mA
活跃状态电流:______ mA
活跃持续时间:______ 秒
睡眠状态电流:______ mA  
睡眠持续时间:______ 秒
电池容量:______ mAh

平均电流 = (活跃电流_mA × 活跃时长_s + 睡眠电流_mA × 睡眠时长_s) / 总时长_s
                = (_____ × _____ + _____ × _____) / _____
                = _____ mA

续航时长 = 容量 × 0.8 / 平均电流
        = _____ × 0.8 / _____
        = _____ 小时
        = _____ 天