ENع
→Power budgets
الدرس 43 · Low power and reliability

Power budgets and battery life

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

14 دقيقة11 خطوة5 أسئلةAdvanced
عن هذا الدرس

How long will a battery device last? Write a power budget: every state the device is in, the current it draws there and for how long. Follow one wake-up of an ESP32 soil sensor (deep sleep at 10 µA, sensing at 31 mA, Wi-Fi at 240 mA), add up the charge, find the 0.86 mA average and turn a 3,000 mAh cell into about 146 days. Then see which levers matter: the radio, how often it wakes, and sleep itself. The Hardware lessons “How batteries work” and “Power supplies” explain capacity and regulators; here we spend that capacity.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 43 · تفاعلي
01 / 11

Where the charge goes

A battery holds a fixed amount of charge. A power budget lists each state a device is in, the current it draws there and for how long. Our example: an ESP32 soil sensor that reports every 10 minutes.

power budget  every state the device is in:
              current (mA) and time (s)
device        ESP32 soil sensor, 3,000 mAh cell
cycle         sleep -> wake, sense -> send -> sleep

// ESP32 (Arduino core): soil sensor on GPIO34, one report every 10 minutes
const uint64_t T = 600ULL * 1000000ULL;  // 600 s, in microseconds

void sendReading(int m) {
  // join Wi-Fi and send m: the connectivity lessons show how
}

void setup() {
  setCpuFrequencyMhz(80);
  int m = analogRead(34);
  sendReading(m);
  esp_sleep_enable_timer_wakeup(T);
  esp_deep_sleep_start();
}

void loop() {}  // never reached: waking from deep sleep boots again
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Where the charge goes

    A battery holds a fixed amount of charge. A power budget lists each state a device is in, the current it draws there and for how long. Our example: an ESP32 soil sensor that reports every 10 minutes.

    power budget  every state the device is in:
                  current (mA) and time (s)
    device        ESP32 soil sensor, 3,000 mAh cell
    cycle         sleep -> wake, sense -> send -> sleep
    
    // ESP32 (Arduino core): soil sensor on GPIO34, one report every 10 minutes
    const uint64_t T = 600ULL * 1000000ULL;  // 600 s, in microseconds
    
    void sendReading(int m) {
      // join Wi-Fi and send m: the connectivity lessons show how
    }
    
    void setup() {
      setCpuFrequencyMhz(80);
      int m = analogRead(34);
      sendReading(m);
      esp_sleep_enable_timer_wakeup(T);
      esp_deep_sleep_start();
    }
    
    void loop() {}  // never reached: waking from deep sleep boots again
  2. Sleep: 10 µA for 600 s

    Most of the time the chip is in deep sleep. The processors and most memory are off; only a small real-time clock (RTC) keeps counting. The datasheet gives 10 µA. That lasts 600 seconds.

    lines 5-6   esp_sleep_enable_timer_wakeup(T); esp_deep_sleep_start();
    deep sleep  CPUs, most RAM, digital peripherals off
                RTC timer + RTC memory on: 10 µA
    time        600 s  (T = 600,000,000 µs)
    charge      0.01 mA x 600 s = 6 mA·s
  3. Sense: 31 mA for 1 s

    The RTC timer wakes the chip and setup() starts again from the top. With the processor at 80 MHz and the radio off, it draws up to 31 mA. Reading the sensor takes about 1 second.

    wake        the program boots again: setup() from line 1
    line 2      setCpuFrequencyMhz(80);
    line 3      int m = analogRead(34);   0..4095 (12 bits)
    current     20 to 31 mA at 80 MHz, radio off: budget 31
    charge      31 mA x 1 s = 31 mA·s
  4. Send: 240 mA for 2 s

    Now Wi-Fi joins the network and sends the reading. The radio transmits at up to 240 mA. Joining and sending take about 2 seconds, so we budget 240 mA for the whole 2 seconds.

    line 4      sendReading(m);   join Wi-Fi, send
    transmit    240 mA (802.11b, +19.5 dBm)
    receive     95 to 100 mA
    budget      240 mA for all 2 s: a cautious figure
    charge      240 mA x 2 s = 480 mA·s
  5. Charge = current × time

    Charge is current times time. In milliamp-seconds (mA·s): sleep 0.01 × 600 = 6, sense 31 × 1 = 31, send 240 × 2 = 480. One whole cycle of 603 seconds uses 517 mA·s.

    state     mA    s  mA·s
    sleep   0.01  600     6
    sense     31    1    31
    send     240    2   480
    total         603   517
    
    charge (mA·s) = current (mA) x time (s)
  6. The average current

    Spread that charge over the whole cycle: 517 mA·s ÷ 603 s = 0.86 mA. To the battery the device looks like a steady 0.86 mA load, even though it really draws short bursts.

    average  = charge / cycle time
             = 517 mA·s / 603 s
             = 0.857 mA
    asleep 99.5% of the time, but the bursts set the average
  7. Battery life

    Capacity is in milliamp-hours (mAh). A 3,000 mAh cell can give 0.86 mA for 3,000 ÷ 0.86 ≈ 3,500 hours. That is about 146 days, almost five months on one charge.

    capacity  3,000 mAh  (1 mAh = 3,600 mA·s)
    life      = capacity / average current
              = 3,000 mAh / 0.857 mA
              = 3,499 h = 145.8 days
    per day   20.6 mAh
  8. The radio is the cost

    Of the 517 mA·s, the send uses 480: 93%. Sleep is only about 1%. So shaving microamps off sleep barely helps here. Sending less often, or for less time, is the big lever.

    sleep     6 mA·s    1.2%
    sense    31 mA·s    6.0%
    send    480 mA·s   92.8%
    total   517 mA·s  100.0%
    
    cut the biggest row first
  9. Without sleep: 4 days

    If the chip never slept and stayed awake at 31 mA, the same cell would last 3,000 ÷ 31 ≈ 97 hours: about 4 days. Sleep is what turns days into months.

    always awake  31 mA, radio off
    life          3,000 mAh / 31 mA = 96.8 h
                  = 4.0 days
    with sleep    145.8 days: 36 times longer
  10. Wake every 30 minutes

    Set the timer to 30 minutes (1,800 s). Each cycle now uses 529 mA·s over 1,803 s: 0.29 mA on average. The battery lasts about 426 days, almost three times longer.

    line 5    T = 1800ULL * 1000000ULL;  // 30 min
    sleep     0.01 mA x 1,800 s = 18 mA·s
    cycle     529 mA·s / 1,803 s = 0.293 mA
    life      3,000 / 0.293 = 10,225 h = 426.0 days
  11. Leave a margin

    Real cells give less. A lithium-ion cell loses 1 to 2% of its charge a month on its own, and its protection circuit about 3% more. Cold, regulators and LEDs cost too. Budget with a safety margin.

    self-discharge   1-2% a month (after the first day)
    protection       about 3% a month more
    also             cold, the regulator, LEDs, a USB chip
    so               measure the real board, keep a margin

اختبار يتاح بعد الخطوة الأخيرة.