Learning Goals 5 min
A Nano running at full pace draws ~30 mA — a 2000 mAh battery lasts 66 hours. The SAME Nano in deep sleep draws ~5 µA — same battery lasts 50 years. The trick is to sleep most of the time and wake up only when needed. By the end of this lesson you will:
- Compare the 3 power states: active, idle / standby, deep sleep / power-down.
- Wake the chip from sleep using the watchdog timer (periodic) and external interrupts (event-driven).
- Measure your sketch's actual current with a multimeter (µA range) and pick the lowest viable power mode.
Warm-Up 10 min
Hardware:
- Arduino board (Nano / Pro Mini works best — minimal extra circuitry; UNO has USB chip burning extra mA).
- Multimeter with µA range.
- LED + 220 Ω + battery + power switch.
Why sleep matters
| State | Current | 2000 mAh battery life |
|---|---|---|
| UNO running flat out | 50 mA | 40 hours |
| Nano running flat out | 30 mA | 66 hours |
| Nano idle sleep | ~15 mA | 5 days |
| Nano power-down (proper deep sleep) | ~5 µA | ~50 years (battery shelf-life-limited) |
| Pro Mini 3.3V + brown-out off + deep sleep | ~0.5 µA | ~500 years (theoretically) |
The same chip, the same code, vastly different battery lives. Cluster G is about choosing the right sleep mode and waking only when needed.
New Concept · AVR sleep + wake sources 25 min
The 5 sleep modes (AVR / ATmega328)
| Mode | What sleeps | What wakes it | Approx current |
|---|---|---|---|
| Idle | CPU clock | Any interrupt | ~15 mA |
| ADC noise reduction | CPU + most clocks | ADC complete, INT0/1 | ~6 mA |
| Power-save | CPU + most clocks; T2 still runs | Timer 2, INT0/1, watchdog | ~1 mA |
| Standby | Like power-save, but oscillator still on for quick wake | Same as power-save | ~1.5 mA |
| Power-down | Everything except external interrupts + watchdog | INT0/1 (level / rise / fall), watchdog | ~5 µA |
Power-down is the workhorse for battery projects. Wake on a button press (INT0/INT1) or a periodic watchdog tick.
Library: LowPower by Rocket Scream
#include <LowPower.h>
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// Wake up briefly, do work
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
digitalWrite(LED_BUILTIN, LOW);
// Sleep 8 seconds (watchdog wake)
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}Every 8 seconds: chip wakes, blinks LED for 50 ms, sleeps again. Average current: ~50 mA × 50 ms + 5 µA × 8 s ≈ 0.3 mA average. Vs continuously running (~30 mA), that's 100× longer battery.
Sleep durations: SLEEP_15Ms, 30Ms, 60Ms, ..., 1S, 2S, 4S, 8S. For longer, call powerDown in a loop.
Wake on external interrupt
const int WAKE_PIN = 2;
void onWake() { /* dummy; ISR must exist */ }
void setup() {
pinMode(WAKE_PIN, INPUT_PULLUP);
}
void loop() {
attachInterrupt(digitalPinToInterrupt(WAKE_PIN), onWake, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(digitalPinToInterrupt(WAKE_PIN));
// After waking — do work
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
}Button press → INT0 fires → chip wakes from SLEEP_FOREVER → LED blinks → goes back to sleep. Average current: essentially zero between presses. A doorbell on a coin cell that lasts 5 years.
BOD (Brown-Out Detector)
The brown-out detector wakes the chip if VCC dips below a threshold. Useful for reliability — without ~25 µA. For maximum battery life, disable with BOD_OFF as shown.
What you can't do in deep sleep
Most peripherals power down. You can't do delay() (Timer 0 is off), Serial.print() (USART off until you call Serial.begin again), millis() (counter frozen). Wake up first, do work, sleep again.
Worked Example · Measure your actual current 25 min
Setup
- Pro Mini + battery (AAA pack, 3.3 V version).
- Multimeter set to µA range.
- Probe in series with the battery + lead.
Baseline
Upload an empty sketch (only setup + loop). Read current. Pro Mini at 3.3 V: typically ~5 mA. UNO: 30+ mA. Note this is the "active doing nothing" baseline.
Add LowPower
#include <LowPower.h>
void setup() {}
void loop() {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}Upload, switch to µA. Should drop to ~5–10 µA on a Pro Mini. ~3000× lower than running flat out.
Add a wake-on-press
The §3 second sketch. Press the button → meter spikes to ~5 mA briefly → returns to µA after.
Profile your real project
For any battery build, measure current in two cases:
- Active doing work (e.g. reading IMU + publishing): how long does it last?
- Asleep waiting: how long is the chip asleep per minute?
Average current = (active mA × active duration + sleep mA × sleep duration) / total duration. Compare to battery mAh to estimate runtime.
Try It Yourself 15 min
Goal: Build a button-pressed doorbell that wakes the chip, blinks an LED for 200 ms, and goes back to sleep. Measure µA between presses.
Goal: Sleep 32 seconds (4 × SLEEP_8S in a loop), then read a sensor + print, then sleep again. Useful for slow data loggers.
Goal: On the Nano 33 BLE, use the ArduinoLowPower library (different name, similar API). Measure: BLE-advertising current vs deep-sleep current. The 9-axis-sensor board has even lower sleep current (~1 µA).
Mini-Challenge · Compute your build's runtime 10 min
For one battery project (plant monitor, doorbell, etc.):
- Measure active mA + active duration per cycle.
- Measure sleep mA + sleep duration per cycle.
- Compute weighted average.
- Divide battery mAh by average → runtime in hours.
- Compare to your previous estimate without sleep.
You'll usually find 10×–100× improvements with proper sleep.
Recap 5 min
Sleep modes trade responsiveness for power. Power-down at ~5 µA is the standard for battery projects. Wake via watchdog (periodic) or external interrupt (event). The LowPower library hides the AVR register tweaking. Tomorrow: pick the right battery for the project.
- Sleep mode
- A reduced-power state where some peripherals are turned off. AVR has 5 levels.
- Power-down
- The deepest sleep — only the watchdog and external interrupt logic stay alive. ~5 µA on AVR.
- Watchdog timer
- An independent oscillator + counter. Can be configured to wake the chip after up to 8 s. ±10% accurate.
- External interrupt
- A wake source triggered by a pin change. INT0 (D2) and INT1 (D3) on UNO. Pin-change interrupts on more pins.
- Brown-out detector (BOD)
- Voltage-sag reset circuit. Useful for reliability; consumes ~25 µA. Disable for maximum battery life.
- LowPower library
- Rocket Scream's wrapper for AVR sleep. One-line API:
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); - Active vs sleep duty cycle
- The fraction of time the chip is active. 1% active + 99% sleep = ~99× battery savings.
Homework 5 min
- Measure your Pro Mini / Nano in deep sleep with a µA meter.
- Build the wake-on-button doorbell. Confirm µA between presses.
- Read ahead to ARD-L04-38 (Battery Selection).