🛠 Low-power : mode power-down et watchdog
Objectives
Reduce the power consumption of the classic Nano during sleep: put the ATmega328P into power-down mode (clocks stopped, SRAM and registers preserved) and wake it up periodically using the independent watchdog (up to ~8 s). This is the fundamental technique for any battery-powered sensor (coin cell or LiPo).
Hardware
- 1 × Classic Arduino Nano (ATmega328P) — Note: the FTDI chip and the power LED constantly draw current on the board; for true microampere measurements, use a bare 328P or disable these components.
- 1 × Battery power supply and a microammeter in series to measure the gain.
- >
Complete Code
// Sommeil power-down + reveil watchdog ~8 s (ATmega328P)
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/power.h>
ISR(WDT_vect) { /* reveil : retour naturel en loop */ }
void setup {
pinMode(LED_BUILTIN, OUTPUT);
MCUCR = 0; // reveil bas niveau
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable;
wdt_reset;
WDTCR = _BV(WDIE) | _BV(WDP3) | _BV(WDP0); // IT watchdog ~8 s
power_adc_disable; // coupe les peripheriques inutiles
power_timer1_disable;
power_usart0_disable;
}
void loop {
digitalWrite(LED_BUILTIN, HIGH); // pouls de 100 ms entre deux sommeils
delay(100);
digitalWrite(LED_BUILTIN, LOW);
wdt_reset;
WDTCR = _BV(WDIE) | _BV(WDP3) | _BV(WDP0); // rearme (bit WDTCE)
sleep_cpu; // power-down jusqu'au prochain WDT
}
Expected Verification
The microammeter shows short spikes (the 100 ms LED pulse) separated by very low plateaus: the MCU alone drops from several milliamps when active to a few microamps in power-down mode. The LED blinks every ~8 s, proving that the watchdog successfully wakes the sleep mode. Removing the sleep code immediately raises the consumption plateau.
Common Errors
- Forgetting to rearm the watchdog at each cycle: on the second delay, the watchdog expires in reset mode and the board restarts in a loop.
- Relying on the complete board for microampere measurements: the powered FTDI, power LED, and regulator consume more than the sleeping MCU; the actual gain is measured on the bare chip.
- Calling
Serial.printafter sleep without re-enablingusart0(power_usart0_enable): the serial line remains disabled, and no messages are sent. - Choosing a watchdog delay that is too short: the minimum step (~16 ms) does not justify a wake-up; group measurements to maximize sleep time.
- >
Other tutorials for this board
Code examples for this board
buzzer-melodie.inoArduinoservo-sweep.inoArduinoultrason-hcsr04.inoArduinolcd-i2c.inoArduinoeeprom-contre.inoArduinosommeil-watchdog.inoArduino