Water meter: will the battery last?
Work out a battery's life in days from the meter's sleep, wake-up and radio currents. A medium embedded C problem (Low-power design techniques), run and…
medium · Low-power design techniques · power-budget · units · overflow · product
Product: Smart water meter (Energy)
Requirement. A water meter is sealed underground and must run for 15 years on its battery. Before the hardware is built, firmware estimates the battery's life from a power budget:
- it sleeps at
sleep_uamicroamps all the time, - every
period_sseconds it wakes atactive_mamilliamps foractive_msmilliseconds, - once a day its radio transmits at
tx_mamilliamps fortx_ms_per_daymilliseconds in total.
Only 80 % of the battery's capacity_mah is usable (temperature and ageing). Return the battery life in whole days (rounded down). period_s divides 86,400 exactly.
Units help: one mA for one ms is one µA for one s (a µA·s).
Starter code
uint32_t battery_life_days(uint32_t capacity_mah, uint32_t sleep_ua, uint32_t active_ma, uint32_t active_ms,
uint32_t period_s, uint32_t tx_ma, uint32_t tx_ms_per_day) {
uint32_t per_day = sleep_ua * 86400 + active_ma * active_ms * (86400 / period_s) + tx_ma * tx_ms_per_day;
return capacity_mah * 3600000 * 80 / 100 / per_day;
}Example tests
Waking every second
printf("%u\n", battery_life_days(2400, 5, 3, 20, 1, 120, 2000));Expected output:
1180Waking every minute
printf("%u\n", battery_life_days(2400, 5, 3, 20, 60, 120, 2000));Expected output:
9113Learn it first
- Low-power design techniques · Battery budgets, duty cycling, sleep modes and wake sources.
More Low-power design techniques problems
- How long will the battery last? · Average the current over a duty cycle and turn it into days of battery life.