🛠 Deep-sleep 7 µA et réveil externe (EXT0)

Arduino Nano ESP32 · avance · Schéma : IMG-nano-esp32-avance-2-nanoesp32-deep-sleep-ext0.svg — Carte en deep-sleep (microampères), bouton de réveil sur une broche EXT0 et minuteur de secours.

Objectives

Reach the SoC consumption floor (7 µA in deep-sleep, 240 µA in light-sleep according to docs-db) and wake the Nano ESP32 via an external event (button) with a safety timer wake-up. In deep-sleep, the program restarts from setup: state only survives in RTC memory.

Hardware

Complete code

#include <esp_sleep.h>
#include <driver/gpio.h>

RTC_DATA_ATTR uint32_t reveils = 0;          // survit au deep-sleep (RTC slow)
const gpio_num_t BROCHE_REVEIL = GPIO_NUM_0; // EXT0 : GPIO0-15 (à confirmer)

void setup {
  Serial.begin(115200);
  delay(1500);
  reveils++;
  esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause;
  Serial.printf("Réveil n°%lu (cause %d : 4=EXT0, 5=timer)\n",
                (unsigned long)reveils, (int)cause);
  esp_sleep_enable_ext0_wakeup(BROCHE_REVEIL, 0);        // niveau bas
  esp_sleep_enable_timer_wakeup(60ULL * 1000000ULL);     // filet de 60 s
  Serial.println("Deep-sleep...");
  delay(100);                        // laisse le port série se vider
  esp_deep_sleep_start;
}

void loop {}   // jamais atteint : tout se passe dans setup

Expected verification

Each time the button is pressed (or every 60 s by default), the board restarts, prints the wake-up counter — which resumes where it left off thanks to RTC_DATA_ATTR — then goes back to sleep. The ammeter displays a few µA at rest.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials