Start with an energy budget, not a sleep mode
Most battery-powered embedded devices spend nearly all their time doing nothing. A temperature sensor might wake every few minutes, take a reading in a few milliseconds, send it, and go back to sleep. Battery life is therefore set mostly by two numbers: how much current the device draws while asleep, and how long and how often it wakes up.
Before choosing parts or writing firmware, it helps to sketch an energy budget: list every state the device can be in, how much current it draws in each and how long it spends there.
Average current and duty cycle
For a device that repeats the same cycle, the average current is roughly:
Average current = (active current × active time + sleep current × sleep time) ÷ cycle period
You can extend this with extra states, such as a separate line for radio transmission. Battery life is then approximately the battery’s usable capacity divided by the average current.
Worked example: a coin-cell sensor
Suppose a sensor node:
- Wakes every 10 seconds.
- Is active for 10 ms, drawing 5 mA.
- Sleeps the rest of the time, drawing 5 µA for the whole board.
Average current from the active part = 5 mA × 0.01 s ÷ 10 s = 5 µA. The sleep part adds almost another 5 µA. So the average is about 10 µA.
A CR2032 coin cell is commonly rated at around 220 mAh. In theory that gives 220 mAh ÷ 0.01 mA = 22,000 hours, or roughly two and a half years. In practice, expect less: coin cells deliver less capacity at higher pulse currents and low temperatures, all batteries self-discharge, and the device may stop working before the cell is completely flat.
Two lessons come out of this example:
- Sleep current matters as much as active current. Here they contribute equally. If sleep current rose to 50 µA because of a leak somewhere on the board, battery life would fall to a small fraction of the estimate.
- Waking less often is powerful. Changing the interval from 10 seconds to 60 seconds cuts the active contribution by a factor of six.
Microcontroller sleep modes explained
Almost every modern microcontroller offers several low-power modes. Names and details differ between vendors and families, so always check the reference manual and datasheet for your part, but the tiers usually look like this.
Common mode tiers
| Typical name | What’s stopped | What usually stays on | Wake-up | Relative current |
|---|---|---|---|---|
| Sleep / idle | CPU clock | Peripherals, RAM, clocks | Very fast, any interrupt | Moderate |
| Stop / deep sleep | Most clocks and many peripherals | RAM contents, selected low-power peripherals, RTC | Fast to moderate; limited wake sources | Low |
| Standby | Almost everything, often including most RAM | RTC, a few wake pins, sometimes a small backup RAM | Slower; often similar to a reset | Very low |
| Shutdown / off | Nearly everything | Wake pins only, sometimes RTC | Behaves like a reset | Lowest |
The deeper the mode, the less current it draws, but the more you give up: fewer wake sources, lost RAM contents, and longer wake-up times. In standby or shutdown modes on many parts, the firmware restarts from the reset vector and must restore any state it needs from retained memory or flash.
Wake-up sources and wake-up time
Typical wake sources include:
- A real-time clock (RTC) alarm or low-power timer, for periodic tasks.
- An external interrupt on a GPIO pin, for buttons or sensor “data ready” signals.
- A communication peripheral, such as a UART receiving a character, in the modes that support it.
- A watchdog or brown-out event.
Wake-up time matters too. If a device takes a long time to restart its clocks and peripherals, that time costs energy on every cycle. For frequent, short wake-ups, a lighter sleep mode can sometimes use less total energy than a deeper one.
Entering sleep in firmware
On Arm Cortex-M microcontrollers, the CPU enters sleep with the WFI (wait for interrupt) or WFE (wait for event) instruction. Setting the SLEEPDEEP bit in the System Control Register selects the deeper sleep state, and vendor-specific registers then choose exactly which low-power mode is used. A simplified pattern looks like this:
void enter_deep_sleep(void)
{
disable_unused_peripherals(); /* Turn off what isn't needed */
configure_wakeup_sources(); /* RTC alarm, GPIO interrupt, etc. */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; /* Request deep sleep */
__WFI(); /* Sleep until an interrupt */
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; /* Back awake */
restore_clocks_and_peripherals();
}
Most vendors provide HAL functions that wrap these steps for their specific modes, and RTOSes such as FreeRTOS and Zephyr offer “tickless idle” features that let the system sleep between scheduled tasks instead of waking on every timer tick.
A common trap: make sure a wake-up source is configured and working before entering a deep sleep mode, or the device may never wake.
Firmware techniques
Race to sleep
It is often more efficient to run quickly and then sleep than to run slowly for longer. A faster clock draws more current while active, but the work finishes sooner and the device returns to its low-power state. Whether this wins depends on the part, so measure both approaches. Large dynamic voltage and frequency scaling (DVFS) schemes are more common on application processors, but many microcontrollers offer selectable clock speeds and voltage ranges that achieve a similar trade-off.
Interrupts instead of polling
A loop that repeatedly checks a pin or a flag keeps the CPU busy. Configuring an interrupt and sleeping until it fires lets the CPU rest. This is one of the simplest and most effective changes in many projects.
Clock and peripheral management
Peripherals draw current when their clocks are running, even if the firmware isn’t using them. Enable each peripheral’s clock only while you need it, and disable it again afterwards. Use the lowest-power clock source that meets each task’s needs; many MCUs can run timers and RTCs from a low-frequency 32.768 kHz crystal or internal oscillator while the main clock is off.
Using DMA and low-power peripherals
Direct memory access (DMA) can move data between peripherals and memory while the CPU sleeps. Some microcontrollers also have low-power UARTs, timers or comparators that keep working in stop modes and only wake the CPU when something interesting happens, such as a full buffer or a voltage crossing a threshold.
Radio duty cycling
On connected devices, the radio is usually the biggest consumer of energy while active. Ways to reduce its cost include:
- Sending data in batches rather than one reading at a time.
- Lengthening Bluetooth Low Energy advertising or connection intervals where latency allows.
- Avoiding long listening periods; receiving can cost as much power as transmitting on many radios.
- Choosing a protocol suited to infrequent, small messages.
Hardware techniques
Firmware can only get the sleep current down to what the hardware allows. On many boards, the microcontroller is not the biggest drain at all.
Regulator choice and quiescent current
Every voltage regulator draws a little current just to operate, called its quiescent current (Iq). Some older or general-purpose linear regulators draw milliamps of quiescent current, which would swamp a microcontroller sleeping at a few microamps. Low-Iq regulators designed for battery products can draw from around a microamp down to below a microamp. Check the Iq at your actual load and temperature, not just the headline number.
Switching regulators are more efficient at high loads, but their efficiency can drop sharply at very light loads unless they have a dedicated light-load or low-power mode. For some designs, running the MCU directly from the battery, with no regulator at all, is the lowest-power option, as long as every part on the board tolerates the battery’s full voltage range. See our article on power supply and decoupling design for more on regulator selection.
Switching off sensors and peripherals
Sensors, displays, memory chips and radios may draw far more than the MCU when idle. Options include:
- Using the part’s own shutdown or sleep mode, if it has a low enough current.
- Powering it from a GPIO pin, if its current is small enough to stay within the pin’s rating.
- Using a load switch or MOSFET to cut its supply completely.
When a part is switched off, make sure the MCU’s pins connected to it don’t back-power it through its I/O lines, which can waste current and cause odd behaviour.
Pull-ups, dividers and other hidden leaks
Small resistors can waste surprisingly large currents:
- A 10 kΩ pull-up held low at 3.3 V draws 330 µA, which is far more than many MCUs draw asleep. Use higher values where signal speed allows, or enable pull-ups only when needed.
- A resistor divider for measuring battery voltage draws current continuously unless it is switched off between readings or made from high-value resistors.
- Status LEDs, even dim ones, draw far more than a sleeping MCU.
- Reverse-polarity protection, level shifters, USB-to-serial chips and other support parts may have their own standby currents.
Configuring unused GPIO
Floating (unconnected, unconfigured) input pins can pick up noise and cause the input circuitry to draw extra current. Configure unused pins as recommended in your MCU’s documentation, commonly as analog inputs or with a defined pull-up or pull-down. Also check the state of every output pin before sleeping, so none is driving current into a load.
Lower supply voltage
Dynamic power in digital logic rises steeply with supply voltage, so running at a lower voltage, within the specifications of all parts, can reduce consumption. Many MCUs also have internal regulator settings that trade maximum speed for lower power.
Choosing and handling the battery
The battery is part of the design, not an afterthought:
- Coin cells such as the CR2032 are small and cheap but have limited capacity and are not good at delivering high pulse currents. Radio transmissions can cause voltage dips; a capacitor near the load can help supply short bursts.
- Alkaline AA and AAA cells offer more capacity and are easy to replace, but their voltage falls steadily as they discharge.
- Lithium primary cells, such as lithium thionyl chloride types, are used for long-life sensors and meters because of their high energy density and low self-discharge, though some have limited pulse capability and specific handling considerations.
- Rechargeable lithium-ion and lithium-polymer cells suit devices with frequent use and a charging path, but need proper charge and protection circuitry and have higher self-discharge than primary lithium cells.
Check how capacity varies with temperature and load in the manufacturer’s datasheet, and design the firmware to handle a low battery gracefully, for example by reducing activity and reporting the condition before shutting down.
Measuring low-power performance
You can’t optimise what you can’t measure, and sleep currents in the microamp range are hard to measure well.
- Multimeters can measure steady sleep currents, but the shunt resistor in current ranges (the “burden voltage”) can disturb the circuit, and slow meters can’t capture short active bursts.
- Dedicated power analysers such as Nordic’s Power Profiler Kit II, the Joulescope, Qoitech’s Otii or ST’s X-NUCLEO-LPM01A measure current over a wide dynamic range and show how it changes over time. They are very useful for seeing exactly where energy goes during each wake-up.
- A current-sense resistor and an oscilloscope can show active-current waveforms, though resolving microamp sleep currents this way is difficult.
A few practical tips:
- Measure the whole board, not just the MCU, because board-level leaks are common.
- Disconnect the debug probe when measuring; on many MCUs an attached debugger keeps parts of the chip powered and raises sleep current.
- Measure across the full temperature range if the device will operate in the cold or heat, since leakage currents rise with temperature.
Common mistakes
- Measuring on a development board. Boards like the Arduino Uno include regulators, USB interface chips and LEDs that can draw tens of milliamps on their own, so even a sleeping microcontroller won’t give realistic battery life. Our guide to going from an Arduino prototype to a custom PCB covers how to design that overhead out.
- Picking an MCU on datasheet sleep current alone. The headline figure may assume conditions that don’t match your design, such as no RTC running or no RAM retained. Our guide on how to choose a microcontroller explains what to compare.
- Forgetting about the radio and sensors. These often dominate the energy budget.
- Leaving debug features on in production firmware, such as frequent logging over UART.
- Not testing over the device’s real life. Battery voltage falls over time; check the device still works reliably near the end of discharge.
A low-power checklist
- Write an energy budget with every state, its current and its duration.
- Choose a sleep mode that balances current, wake-up time and retained state.
- Use interrupts and timers to wake, never busy-wait loops.
- Turn off peripheral clocks, sensors and radios when not in use.
- Pick a regulator with low quiescent current, or consider running directly from the battery.
- Hunt down hidden leaks: pull-ups, dividers, LEDs and support chips.
- Configure every unused pin.
- Choose a battery whose capacity, pulse capability and temperature range fit the profile.
- Measure the whole board with a suitable tool, with the debugger disconnected.
- Re-measure after every hardware revision and significant firmware change.
Power is one of the core design metrics of embedded systems, and it interacts with almost every other decision in the embedded system design flow.