power-budget-calculator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePower 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 --interactiveOr calculate for a single component:
bash
uv run --no-project scripts/calculate_power.py --component ESP32 --mode deep_sleep --duty 95Load a project configuration:
bash
uv run --no-project scripts/calculate_power.py --json assets/example-project.json --output report.mdList 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 --listWhen 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:
- Microcontroller (model and operating mode)
- All sensors and modules
- Displays
- Actuators (motors, LEDs, relays)
- Communication (WiFi, Bluetooth, LoRa)
- Operating profile (always on vs. duty cycle)
向用户询问:
- 微控制器(型号和工作模式)
- 所有传感器和模块
- 显示屏
- 执行器(电机、LED、继电器)
- 通信模块(WiFi、蓝牙、LoRa)
- 工作配置文件(持续运行 vs 占空比)
Step 2: Calculate Power Budget
步骤2:计算功耗预算
Run for guided calculation, or use this template:
scripts/calculate_power.py --interactivemarkdown
undefined运行进行引导式计算,或使用以下模板:
scripts/calculate_power.py --interactivemarkdown
undefinedPower 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
持续运行组件
| Component | Voltage | Current | Power | Notes |
|---|---|---|---|---|
| [name] | [V] | [mA] | [mW] | [conditions] |
| ... | ... | ... | ... | ... |
| Subtotal | - | [mA] | [mW] | - |
| 组件 | 电压 | 电流 | 功率 | 备注 |
|---|---|---|---|---|
| [名称] | [V] | [mA] | [mW] | [条件] |
| ... | ... | ... | ... | ... |
| 小计 | - | [mA] | [mW] | - |
Active Mode Only
仅活跃模式组件
| Component | Voltage | Current | Power | Duty % |
|---|---|---|---|---|
| [name] | [V] | [mA] | [mW] | [%] |
| ... | ... | ... | ... | ... |
| Subtotal | - | [mA] | [mW] | - |
| 组件 | 电压 | 电流 | 功率 | 占空比 % |
|---|---|---|---|---|
| [名称] | [V] | [mA] | [mW] | [%] |
| ... | ... | ... | ... | ... |
| 小计 | - | [mA] | [mW] | - |
Peak Current Events
峰值电流事件
| Event | Current | Duration | Frequency |
|---|---|---|---|
| [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] mAI_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 = [结果] mABattery 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- [功耗优化建议]
- [电池类型推荐]
- [睡眠模式配置]
undefinedCurrent Draw Database
电流消耗数据库
Microcontrollers
微控制器
Arduino (ATmega328P @ 5V)
Arduino (ATmega328P @ 5V)
| Mode | Current | Notes |
|---|---|---|
| Active (16MHz) | 15-20mA | No peripherals |
| Idle | 6mA | CPU stopped, peripherals on |
| Power-down | 0.1µA | Only WDT/external interrupt |
| With USB-Serial | +50mA | CH340/FTDI chip always on |
| 模式 | 电流 | 备注 |
|---|---|---|
| Active (16MHz) | 15-20mA | No peripherals |
| Idle | 6mA | CPU stopped, peripherals on |
| Power-down | 0.1µA | Only WDT/external interrupt |
| With USB-Serial | +50mA | CH340/FTDI chip always on |
ESP32 (WROOM-32)
ESP32 (WROOM-32)
| Mode | Current | Notes |
|---|---|---|
| Active (WiFi TX) | 160-260mA | Peak during transmission |
| Active (WiFi RX) | 95-100mA | Listening |
| Active (no WiFi) | 20-68mA | CPU only |
| Modem-sleep | 20mA | WiFi off, CPU on |
| Light-sleep | 0.8mA | CPU paused |
| Deep-sleep | 10µA | RTC only |
| Hibernation | 5µA | RTC off |
| 模式 | 电流 | 备注 |
|---|---|---|
| Active (WiFi TX) | 160-260mA | Peak during transmission |
| Active (WiFi RX) | 95-100mA | Listening |
| Active (no WiFi) | 20-68mA | CPU only |
| Modem-sleep | 20mA | WiFi off, CPU on |
| Light-sleep | 0.8mA | CPU paused |
| Deep-sleep | 10µA | RTC only |
| Hibernation | 5µA | RTC off |
ESP32-C3
ESP32-C3
| Mode | Current | Notes |
|---|---|---|
| Active (WiFi TX) | 320mA peak | Brief spikes |
| Active (BLE) | 50-100mA | During advertising |
| Active (no radio) | 25-35mA | CPU at 160MHz |
| Light-sleep | 130µA | Auto wake |
| Deep-sleep | 5µA | RTC on |
| 模式 | 电流 | 备注 |
|---|---|---|
| Active (WiFi TX) | 320mA peak | Brief spikes |
| Active (BLE) | 50-100mA | During advertising |
| Active (no radio) | 25-35mA | CPU at 160MHz |
| Light-sleep | 130µA | Auto wake |
| Deep-sleep | 5µA | RTC on |
RP2040 (Pico)
RP2040 (Pico)
| Mode | Current | Notes |
|---|---|---|
| Active (both cores) | 25-50mA | Depends on clock |
| Single core | 15-25mA | One core dormant |
| Dormant | 0.18mA | Wake on GPIO/RTC |
| Sleep | 1.3mA |
| 模式 | 电流 | 备注 |
|---|---|---|
| Active (both cores) | 25-50mA | Depends on clock |
| Single core | 15-25mA | One core dormant |
| Dormant | 0.18mA | Wake on GPIO/RTC |
| Sleep | 1.3mA |
RP2040 (Pico W)
RP2040 (Pico W)
| Mode | Current | Notes |
|---|---|---|
| WiFi active | 50-150mA | During TX |
| WiFi idle | 30-40mA | Connected, listening |
| WiFi off | 25-50mA | Radio disabled |
| 模式 | 电流 | 备注 |
|---|---|---|
| WiFi active | 50-150mA | During TX |
| WiFi idle | 30-40mA | Connected, listening |
| WiFi off | 25-50mA | Radio disabled |
Sensors
传感器
| Sensor | Active | Sleep | Notes |
|---|---|---|---|
| DHT22 | 1.5mA | 50µA | During read |
| BME280 | 0.35mA | 0.1µA | Forced mode |
| BMP280 | 0.27mA | 0.1µA | |
| MPU6050 | 3.8mA | 5µA | All axes |
| DS18B20 | 1.5mA | 1µA | During conversion |
| HC-SR04 | 15mA | 2mA | No true sleep |
| VL53L0X | 19mA | 5µA | During ranging |
| MAX30102 | 600µA | 0.7µA | Low power mode |
| BH1750 | 120µA | 1µA | Power down mode |
| GPS (NEO-6M) | 45mA | 11mA | Backup mode |
| 传感器 | 活跃状态 | 睡眠状态 | 备注 |
|---|---|---|---|
| DHT22 | 1.5mA | 50µA | During read |
| BME280 | 0.35mA | 0.1µA | Forced mode |
| BMP280 | 0.27mA | 0.1µA | |
| MPU6050 | 3.8mA | 5µA | All axes |
| DS18B20 | 1.5mA | 1µA | During conversion |
| HC-SR04 | 15mA | 2mA | No true sleep |
| VL53L0X | 19mA | 5µA | During ranging |
| MAX30102 | 600µA | 0.7µA | Low power mode |
| BH1750 | 120µA | 1µA | Power down mode |
| GPS (NEO-6M) | 45mA | 11mA | Backup mode |
Displays
显示屏
| Display | Active | Off/Sleep | Notes |
|---|---|---|---|
| 16x2 LCD (backlight) | 80-120mA | 1mA | Backlight dominates |
| 16x2 LCD (no backlight) | 1-2mA | 1mA | |
| SSD1306 OLED 128x64 | 8-20mA | 10µA | Depends on content |
| SSD1306 OLED 128x32 | 5-15mA | 10µA | |
| ST7735 TFT | 20-40mA | 20mA | Backlight always on |
| ILI9341 TFT | 50-80mA | 50mA | |
| E-Paper 2.9" | 8mA | 0µA | Only during refresh |
| 显示屏 | 活跃状态 | 关闭/睡眠状态 | 备注 |
|---|---|---|---|
| 16x2 LCD (backlight) | 80-120mA | 1mA | Backlight dominates |
| 16x2 LCD (no backlight) | 1-2mA | 1mA | |
| SSD1306 OLED 128x64 | 8-20mA | 10µA | Depends on content |
| SSD1306 OLED 128x32 | 5-15mA | 10µA | |
| ST7735 TFT | 20-40mA | 20mA | Backlight always on |
| ILI9341 TFT | 50-80mA | 50mA | |
| E-Paper 2.9" | 8mA | 0µA | Only during refresh |
Communication Modules
通信模块
| Module | TX Peak | RX/Idle | Sleep | Notes |
|---|---|---|---|---|
| ESP8266 (module) | 170mA | 70mA | 20µA | Deep sleep |
| NRF24L01 | 11.3mA | 13.5mA | 0.9µA | |
| HC-05 Bluetooth | 40mA | 8mA | 2mA | |
| RFM95 LoRa | 120mA | 10mA | 0.2µA | |
| SIM800L GSM | 2A peak | 15mA | 1mA | Needs big cap! |
| 模块 | 发射峰值 | 接收/空闲 | 睡眠 | 备注 |
|---|---|---|---|---|
| ESP8266 (module) | 170mA | 70mA | 20µA | Deep sleep |
| NRF24L01 | 11.3mA | 13.5mA | 0.9µA | |
| HC-05 Bluetooth | 40mA | 8mA | 2mA | |
| RFM95 LoRa | 120mA | 10mA | 0.2µA | |
| SIM800L GSM | 2A peak | 15mA | 1mA | Needs big cap! |
Actuators
执行器
| Component | Current | Notes |
|---|---|---|
| LED (typical) | 10-20mA | Through resistor |
| RGB LED (each color) | 20mA | Per channel |
| WS2812B NeoPixel | 60mA max | Full white |
| SG90 Servo (idle) | 10mA | No load |
| SG90 Servo (moving) | 200-500mA | Under load |
| MG996R Servo | 500-900mA | Under load |
| Small DC motor | 100-500mA | Varies with load |
| 5V Relay module | 70-100mA | Coil energized |
| Buzzer (passive) | 30mA |
| 组件 | 电流 | 备注 |
|---|---|---|
| LED (typical) | 10-20mA | Through resistor |
| RGB LED (each color) | 20mA | Per channel |
| WS2812B NeoPixel | 60mA max | Full white |
| SG90 Servo (idle) | 10mA | No load |
| SG90 Servo (moving) | 200-500mA | Under load |
| MG996R Servo | 500-900mA | Under load |
| Small DC motor | 100-500mA | Varies with load |
| 5V Relay module | 70-100mA | Coil 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]
│
GNDDuty 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
常见电池类型
| Type | Voltage | Typical Capacity | Notes |
|---|---|---|---|
| CR2032 | 3V | 220mAh | Very low current only |
| 2x AA Alkaline | 3V | 2500mAh | Good for low power |
| 3x AA Alkaline | 4.5V | 2500mAh | Direct to 5V systems |
| 4x AA Alkaline | 6V | 2500mAh | With LDO to 5V |
| 18650 Li-ion | 3.7V | 2000-3500mAh | Rechargeable, popular |
| LiPo 1S | 3.7V | Various | Flat, light |
| 9V Alkaline | 9V | 500mAh | Poor energy density |
| 类型 | 电压 | 典型容量 | 备注 |
|---|---|---|---|
| CR2032 | 3V | 220mAh | 仅适用于极低电流场景 |
| 2节AA碱性电池 | 3V | 2500mAh | 适合低功耗场景 |
| 3节AA碱性电池 | 4.5V | 2500mAh | 直接为5V系统供电 |
| 4节AA碱性电池 | 6V | 2500mAh | 通过LDO转换为5V |
| 18650锂离子电池 | 3.7V | 2000-3500mAh | 可充电,使用广泛 |
| 1S LiPo电池 | 3.7V | 多种规格 | 扁平轻便 |
| 9V碱性电池 | 9V | 500mAh | 能量密度低 |
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/cell18650/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 / _____
= _____ 小时
= _____ 天