🛠 Sommeil profond et réveil par watchdog
Objectives
Reduce the Nano Every's power consumption for a battery-powered sensor: put the core to sleep in SLEEP_MODE_PWR_DOWN and wake it up periodically using the ATmega4809 watchdog. On this family, the watchdog triggers a reset by default: we use this reset as an alarm, distinguishing a watchdog restart from a normal startup.
Hardware
- 1 × Arduino Nano Every
- External power supply (battery/LiPo via VIN) to measure the actual gain — the USB bridge module remains powered as long as USB is connected
- Optional: microammeter or power consumption measurement module
Complete code
// Sommeil profond, reveil ~1 s via watchdog (reset comme alarme)
#include <avr/sleep.h>
#include <avr/wdt.h>
void setup {
pinMode(LED_BUILTIN, OUTPUT);
wdt_reset;
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // mode le plus profond
sleep_disable; // armement a la volee
wdt_enable(WDTO_1S); // delai 1 s
}
void loop {
digitalToggle(LED_BUILTIN); // signal d'activite brève
delay(50);
wdt_reset; // eviter le reset immediat
sleep_enable;
sleep_cpu; // dort jusqu'au reset WDT
// A ce point : le watchdog a reinitialise la carte, setup tourne
// a nouveau avant de revenir ici.
}
Expected verification
LED 13 blinks briefly every second. Between two blinks, the core is off: when powered by battery and with USB disconnected, a microammeter should show an average significantly lower than active mode (the exact gain depends on the mode and any peripherals left active).
Common errors
- Measuring the gain with USB connected: the serial bridge module and its regulator consume power constantly; without power on VIN and with the cable disconnected, the measurement is meaningless.
- Forgetting periodic
wdt_reset: the watchdog resets the board during operation instead of serving as a clock. - Confusing models: on the 328P, you exit sleep via a watchdog interrupt; on the 4809 family, the default behavior is a reset — structure your code as "short task → sleep".
- Expecting
millisto continue: during deep sleep, the Arduino counter stops; after waking up, rely on an external RTC clock if you need accurate time. - Peripherals left powered (blinking LED on a module, sensor in heating mode): they drain the budget faster than the core.
- In case of an unexplained reset, check the reset cause register before suspecting the code.
Other tutorials for this board
Code examples for this board
multi-serie.inoArduinoadc-filtre.inoArduinointerrupt-bouton.inoArduinonvm-consignes.inoArduinosommeil-every.inoArduinowatchdog-secours.inoArduino