Understanding Deep Sleep Mode
Deep sleep mode is an energy-efficient state that empowers the ESP-01S module to save power, making it ideal for battery-driven applications. During deep sleep, the module consumes minimal power, often operating in the microampere range. Achieving this level of energy efficiency involves deactivating most internal components, including the CPU, Wi-Fi, and peripherals.
To awaken from deep sleep, the ESP-01S can be programmed to respond to timers and GPIO pins, which is crucial for precision timing and event-driven applications.
Enabling deep sleep for timed wake-ups necessitates a hardware adjustment. This involves connecting pin 8 (XPD_DCDC) on the ESP8266 chip to the reset pin of the module. This modification is a fundamental step to unlock the deep sleep functionality.
Using Deep Sleep in Code
Once your hardware is prepared, you can activate deep sleep with a single line of code within your Arduino IDE sketch:
ESP.deepSleep(60 * 1000000);
In this example, the module will slumber for 60 seconds (equivalent to 60 million microseconds). If you prefer to specify the sleep duration in seconds, you can use a variable like this:
ESP.deepSleep(sleepSecs * 1000000);
The maximum value you can set for the deepSleep function is 4,294,967,295, which translates to slightly over 71 minutes. However, if you call deepSleep with a zero like this:
The module will remain in deep sleep until it detects a rising edge (Low to High transition) on the reset pin. In such cases, the hardware modification becomes unnecessary, offering flexibility in how you employ deep sleep for your ESP-01S-based projects.