🛠 Low-power : mode power-down et watchdog

Arduino Nano (Classic, ATmega328P) · avance · Schéma : IMG-nano-classic-avance-9-nanoc-low-power-watchdog.svg — Arduino Nano sur batterie avec LED de faible consommation, réveil périodique par watchdog en mode power-down du ATmega328P

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials