Budget battery life from duty cycle
Turn the module guide's battery-life and measurement path into an auditable duty-cycle sensitivity budget.

Battery Bruno
Inspect the measured current terms and the datasheet condition before trusting a lifetime number.
Predict the reading, then compare it with the measurement.
Python 3 in your browser (JupyterLite)
Python · no installOpen the notebook in your browser and run each Python cell; no install or account is needed.
Three ways to run: use JupyterLite here with no install; run main.py locally from the downloadable lab folder; or open the same notebook in Google Colab.
Steps
Step 1
- Do
- Run the first code cell in the JupyterLite notebook editor and inspect the input record.
- You will see
Run the cell. You should see:
- Synthetic Falstad model (seed 0), 5 V, 100 Hz, 20% duty.
- active=4.978865 mA; sleep=0.050050 mA.
- Energizer CR2032: typical 254 mAh to 2.0 V.
- Rating condition: 15 kΩ at 21 °C; ~0.2 mA load.
- STEP 1 inputs and their limits recorded
- Why it matters
- The capacity rating condition and measured current source limit what this calculation can claim.
Code for step 1# Step 1 — inputs from the real Falstad run and the cited cell datasheet. active_ma = 4.978864757359792 sleep_ma = 0.05004999950000526 duty = 0.20 capacity_mah = 254.0 print('Synthetic Falstad model (seed 0), 5 V, 100 Hz, 20% duty') print(f'active={active_ma:.6f} mA; sleep={sleep_ma:.6f} mA') print(f'circuit SHA-256={"dd98be08f7ad19b2cdec0d92676cf8a3d7f40e76bca4001040a539c6bde8f424"}') print('Energizer CR2032: typical 254 mAh to 2.0 V') print('Rating condition: 15 kΩ at 21 °C; ~0.2 mA load') print('STEP 1 inputs and their limits recorded')
Step 1 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 2
- Do
- Run the second code cell in the notebook editor and inspect the weighted-current calculation.
- You will see
Run the cell. You should see:
- I_avg = duty*I_active + (1-duty)*I_sleep.
- active share=0.995773 mA.
- sleep share=0.040040 mA.
- at 20% duty: I_avg=1.035813 mA.
- STEP 2 weighted current computed
- Why it matters
- A full-cycle current budget must weight each state by its duration.
Code for step 2# Step 2 — time-weighted current from the two observed states. def average_ma(d): return active_ma*d + sleep_ma*(1-d) mean_ma = average_ma(duty) print('I_avg = duty*I_active + (1-duty)*I_sleep') print(f'active share={duty*active_ma:.6f} mA') print(f'sleep share={(1-duty)*sleep_ma:.6f} mA') print(f'at 20% duty: I_avg={mean_ma:.6f} mA') print(f'0%={average_ma(0):.6f} mA; 100%={average_ma(1):.6f} mA') print('STEP 2 weighted current computed')
Step 2 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 3
- Do
- Run the third code cell in the notebook editor and inspect the ideal-life estimate.
- You will see
Run the cell. You should see:
- Ideal life = rated capacity / average current.
- capacity=254 mAh; average=1.035813 mA.
- life=245.22 h = 10.22 days.
- continuous active life=51.02 h; continuous sleep=5074.93 h.
- STEP 3 ideal budget calculated
- Why it matters
- The ideal division gives a screening estimate in hours, with no pulse-load correction.
Code for step 3# Step 3 — idealized lifetime estimate, in hours and days. life_h = capacity_mah / mean_ma print('Ideal life = rated capacity / average current') print(f'capacity={capacity_mah:.0f} mAh; average={mean_ma:.6f} mA') print(f'life={life_h:.2f} h = {life_h/24:.2f} days') print(f'continuous active life={capacity_mah/active_ma:.2f} h') print(f'continuous sleep life={capacity_mah/sleep_ma:.2f} h') print('STEP 3 ideal budget calculated')
Step 3 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 4
- Do
- Run the fourth code cell in the notebook editor and inspect the sweep table and plotted curve.
- You will see
Run the cell. You should see:
- duty % | avg mA | ideal days
- 0 | 0.050 | 211.46
- 10 | 0.543 | 19.49
- 20 | 1.036 | 10.22
- 30 | 1.529 | 6.92
- 40 | 2.022 | 5.24
- 50 | 2.514 | 4.21
- 60 | 3.007 | 3.52
- 70 | 3.500 | 3.02
- 80 | 3.993 | 2.65
- 90 | 4.486 | 2.36
- 100 | 4.979 | 2.13
- STEP 4 eleven-point sensitivity sweep plotted
- Why it matters
- Changing duty across eleven cases shows sensitivity beyond one nominal point.
Code for step 4# Step 4 — plot sensitivity; every plotted point comes from the same equation. from IPython.display import display, SVG sweep = [(d, average_ma(d), capacity_mah/average_ma(d)/24) for d in [i/10 for i in range(11)]] print('duty % | avg mA | ideal days') for d, current, days in sweep: print(f'{d*100:6.0f} | {current:6.3f} | {days:10.2f}') print('STEP 4 eleven-point sensitivity sweep plotted') width,height=560,300 points=' '.join(f'{55+d*450:.1f},{250-(days/max(x[2] for x in sweep))*205:.1f}' for d,_,days in sweep) ticks=''.join(f'<text x="{55+d*450:.1f}" y="275" text-anchor="middle" font-size="12">{d*100:.0f}%</text>' for d,_,_ in sweep[::2]) svg=f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}"><rect width="{width}" height="{height}" fill="white"/><text x="55" y="25" font-size="16">Ideal days vs duty cycle</text><path d="M55 42V250H510" stroke="#333" fill="none"/>{ticks}<polyline points="{points}" fill="none" stroke="#1565c0" stroke-width="3"/><text x="280" y="298" text-anchor="middle" font-size="12">Duty cycle</text><text x="5" y="55" font-size="12">days</text></svg>' display(SVG(svg))
Step 4 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 5
- Do
- Run the fifth code cell in the notebook editor and compare the design changes.
- You will see
Run the cell. You should see:
- baseline=10.22 days at 20% duty.
- half sleep current=10.42 days.
- half active current=19.67 days.
- half usable capacity=5.11 days.
- Capacity rating condition differs from this ~1 mA model.
- STEP 5 sensitivity and boundary compared
- Why it matters
- The dominant current term and usable capacity bound the decision.
Code for step 5# Step 5 — compare one design change at the reference duty. half_sleep = capacity_mah/(active_ma*duty + sleep_ma/2*(1-duty))/24 half_active = capacity_mah/(active_ma/2*duty + sleep_ma*(1-duty))/24 half_capacity = capacity_mah/2/mean_ma/24 print(f'baseline={life_h/24:.2f} days at 20% duty') print(f'half sleep current={half_sleep:.2f} days') print(f'half active current={half_active:.2f} days') print(f'half usable capacity={half_capacity:.2f} days') print('Capacity rating condition differs from this ~1 mA model.') print('STEP 5 sensitivity and boundary compared')
Step 5 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
A battery-life calculator predicts four years, but the model uses datasheet sleep current, nominal battery capacity, and one successful radio transmission per cycle. What should the engineer do before accepting the result?
Return to the chapter’s knowledge checkBeyond a single lifetime figure, what is the most useful thing a battery-life tool provides?
Return to the chapter’s knowledge check
Caution
Before you start
Read this before you start.
This ideal estimate uses a CR2032 capacity rated at 15 kΩ and 21 °C, which differs from the modeled pulsed load; it does not establish actual runtime.
Technical details
- Version tested
- Version tested: JupyterLite 0.6.4, Python (Pyodide) in Chromium 151, executed in browser on 2026-10-08; captureSource playwright:jupyterlite. Date: 2026-10-08.
https://iotclass.org/labs/battery-life-duty-cycle.html