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.
Basic 5 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.
Here is what one press should look like:
1. Think first (on paper, no typing yet):
- Which sleep call sleeps until something wakes it? Which UNO pins can wake it from the deepest sleep?
- Put these in order: blink, go to sleep, set up the wake-up, remove the wake-up. Why does the order matter?
- What will you see if you hold the button down?
2. Code it. Start from the Add LowPower step. Wire the button from D2 to GND.
3. Upload and observe. Put the meter in series with the supply. Press the button a few times.
It works if:
- One 200 ms blink per press, as in the diagram.
- You have written down the current between presses, with units.
- You can say what happens when the button is held down, and why.
Challenge 1 5 min
Goal: Sleep 32 seconds (4 × SLEEP_8S in a loop), then read a sensor + print, then sleep again. Useful for slow data loggers.
1. Think first (on paper, no typing yet):
- The longest single sleep is 8 s. How do you get 32?
- Write the jobs inside loop() in order.
- If you print just before sleeping, what can happen to the last characters? How do you wait for them to leave?
2. Code it. Use any analog sensor on A0. Read, print, then sleep for 32 s.
3. Upload and observe. Leave the Serial Monitor open with timestamps on, for a few minutes.
It works if:
- A new line appears about every 32 s. A few seconds either way is normal.
- No line is cut off halfway.
Challenge 2 5 min
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).
1. Think first (on paper, no typing yet):
- Which library calls start advertising, and which put the chip into deep sleep?
- How will you put the meter in series when the Nano runs from a battery?
- Predict the two readings. How many times bigger will one be?
2. Code it. Write one sketch that advertises for 10 s, then deep-sleeps for 10 s, and repeats.
3. Upload and observe. Read the current in each state.
It works if:
- Two readings with units: advertising and deep sleep.
- You have worked out how many times bigger the advertising current is.
Challenge 3 · 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.
Extra Mission 5 min
Part 1 — Design a device that sleeps most of its life
Many good gadgets do one quick job and then sleep for hours. On paper, design one. Ideas: a post-box alert, a plant that asks for water, a door counter for a school library.
Your design must include:
- What wakes it: a timer, a button or a sensor interrupt.
- The job it does while awake, and how long that takes.
- Which sleep mode it uses, and which parts it switches off.
- A rough duty cycle: seconds awake per hour.
Part 2 — Make it
Build the core with the LowPower library. Your board must wake on your chosen trigger and do its job, such as an LED flash or a reading. Then it goes straight back to sleep. Measure the current awake and asleep with your multimeter.
Bring back next class: your uploaded sketch, a photo of the circuit with the meter connected, and your awake and asleep current readings.