A sensor node on two AA batteries should last two years, not two weeks. Power optimization in embedded systems is about understanding where energy goes and eliminating waste.
Understand your power budget
Start by measuring current consumption at each operating mode. A typical STM32 microcontroller runs at 20mA in active mode, 1mA in sleep mode, and 1µA in standby. Two AA batteries give you roughly 2000mAh. Simple math tells you how long your device will last in each mode.
Sleep modes are your best tool
The biggest win comes from spending as much time as possible in low-power sleep modes. Wake up only when you have to do work.
// Run computation
process_sensor_data();
// Sleep until next scheduled wake or external interrupt
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
WFI (Wait for Interrupt) halts the CPU while keeping peripherals running. Deeper sleep modes turn off more of the chip but take longer to wake up from.
Reduce clock speed when possible
Power consumption scales with clock frequency. If your task does not need to run at 168 MHz, run it at 8 MHz. Many MCUs support dynamic frequency scaling.
Manage peripheral power
Turn off peripherals when not in use. Disable clocks to unused peripherals — they still consume power even when not actively used. Power down sensors between readings.
Wireless is expensive
WiFi and Bluetooth radio consumes 100-250mA during transmission. Keep transmission windows short. Buffer data and send in bursts rather than continuous connections. Use BLE advertising instead of BLE GATT connections when possible.
Optimize ADC sampling
Use DMA to transfer ADC data without CPU involvement. Sample at the lowest rate that meets your requirements. Use hardware averaging to reduce noise rather than software filtering.
Every milliwatt saved extends battery life. Profile your power consumption, identify the biggest consumers, and tackle them in order of impact.



