ESP8266 Sleep / Low Power Modes

The ESP8266 is a hungry beast when it’s doing WiFi. According to different sources on the internet it uses about 75-82 mA on average when WiFi is on! This means that you would have to change batteries every few days if it is running non-stop.

As we are not in control of the hardware/components in the microcontroller, we can’t optimize the hardware to reduce power consumption. However, we can write software to send the hardware to sleep to save power. While sleeping, the device draws much less power than while awake.

Types of Sleep

There are three types of sleep modes: modem sleep, light sleep, and deep sleep.

Image: Differences between ESP8266 sleep modes

 

No-Sleep

The No-Sleep setting will keep everything on at all times. Obviously, this is the most inefficient and will drain the most current.

Modem-sleep

Modem-sleep is the default mode for the ESP8266. However, it’s only enabled when you’re connected to an access point.

While in Modem-sleep, the ESP8266 will disable the modem (WiFi) as much as possible. It turns off the modem between DTIM Beacon intervals. This interval is set by your router.

Light-sleep

Light-sleep performs the same function as Modem-sleep, but also turns off the system clock and suspends the CPU. The CPU isn’t turned off, but rather it’s just in idle mode.

Deep-sleep

Everything is off but the Real Time Clock (RTC), which is how the computer keeps time. Since everything is off, this is the most power efficient option. In other words, in deep sleep mode, the device doesn’t do anything except for counting up till the wake up call.

The table (above) from the ESP8266 datasheet states a current of 20µA during deep sleep only for the ESP chip itself. However, ESP8266-based development boards (like NodeMcu) have several additional components like a built-in programmer, USB to serial chip, LEDs and a linear voltage regulator. Therefore, current consumption can add up to 8mA. It is important to turn off all LEDs to reduce current flow to a minimum.

With Deep-sleep Mode, the procedure can follow these steps:

  1. Perform some action (read from a sensor, write some data to EEPROM or send data via WIFI to a server)
  2. Go into deep sleep mode
  3. Sleep for n microseconds and reset
  4. Repeat

The device is woken up when a specified time has passed. However, it can’t sleep forever. The ESP8266 has a 32-Bit architecture. Thus, with the ESP8266 having a 32-bit (one bit represents one µs) sleep counter, it can only sleep for 4,294,967,295 µs, which is about 71 minutes.

 

Wake up Mechanism

The RST (Reset) pin is held high via a pull-up during the device’s active state. To reset the device the pin must be pulled to ground externally.

As soon as the watchdog timer is up (i.e. it’s time to wake up), a LOW signal is sent to GPIO16 (Pin D0). Thus, by wiring GPIO16 to RST, the device is restarted as soon as the sleep timer is up.

Wake up ESP8266 from Deep Sleep

Image: RST and GPIO16 (Wake up Pin)

Deep Sleep Example Code

/********************deepSleep_example.ino***********************/

/* ESP8266 Deep sleep mode example
 * http://ESP8266-Shop.com
 * 
 *In this example the ESP8266 goes into deep sleep mode. 
 *After 30s it wakes up sends a LOW impulse on GPIO 16 (D0 in NodeMCU board) which is connected to the rst pin. 
 *This causes a reset of the ESP8266.
 */

void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }

  // Deep sleep mode until RESET pin is connected to a LOW signal (for example pushbutton or magnetic reed switch)
  //Serial.println("I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal");
  //ESP.deepSleep(0); 
}

void loop() {
Serial.println("I'm going into deep sleep mode in 5s");
delay(5000);
 Serial.println("Now, I'm going into deep sleep mode for 30 seconds");
  ESP.deepSleep(30e6); 
}

< ESP8266 NodeMcu Pinout  Interrupts and Timers >

(Visited 2,039 times, 1 visits today)