Here is the approaches to minimizing the power consumption of your ESP8266/ESP32 by coding to extend the battery life of your peripheral devices. The key aspect of this mode is that it requires a little overhead to enter and exit unto sleeping mode of the chip. There is another ways to have a better power saving techniques by using interrupts signal you can just invoke the idle mode to reduce the power consumption to the peripherals, however when external interrupt is used it allows you to receive data from the peripherals without invoking and without polling. Interrupt occurs the ESP8266 will automatically start executing the code changing the value of the digital input pin. The code which demonstrated on this article was adopted from open house automations using Arduino Core Library. For wiring and bootloading ESP8266 / ESP32 please refer to link.
Required Firmware
The deepSleep Function
[crayon-673f33be0dbdb449769368/]
Interrupt Example Code
[crayon-673f33be0dbe7177085239/]