🛠 Deep-sleep 7 µA et réveil externe (EXT0)
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
- 1 × Arduino Nano ESP32 + USB-C cable
- 1 × button between a wake-up pin and GND
- A micro-ammeter in series with the power supply to measure actual consumption
- >
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
- Believing that loop resumes after wake-up: deep-sleep = complete restart, state only in RTC memory.
- Choosing a pin beyond GPIO15 for EXT0 on S3: wake-up never occurs.
- Forgetting the backup timer: if the button is wired incorrectly, the board appears dead.
- Comparing the advertised 7 µA (SoC only) to the full board: LEDs, regulators, and the MP2322 converter add their own consumption.
Other tutorials for this board
Code examples for this board
connexion-wifi.inoArduinopoint-acces.inoArduinoble-capteur.inoArduinoneoled-rgb.inoArduinoadc-12bits.inoArduinopreferences.inoArduino