0

ESP8266 Sleep Mode Low Power Solutions

5/5 - (1 vote)

sorry we are not native speakers, so the content may not be clear. We just want to share with you!

In the future, most devices will be interconnected and will communicate in real time. ESP8266 is used quite commonly so today ESPITEK introduces to you ESP8266 sleep mode. One of the problems that these devices face is power consumption. This energy consumption factor is one of the important and decisive factors for any IoT device and Project.

As we know that ESP8266 is one of the most popular modules for building any IoT project, so in this article we learn about esp8266’s deep sleep mode to save power when using it. Use ESP8266 in any IoT application. Here, I will upload the LM35 temperature sensor data to the ThingSpeak intermediate server for a period of 15 seconds, and for that 15 seconds, the ESP8266 remains in deep sleep to save power.

Read more:

ESP8266 sleep mode low power solutions

What is the ESP8266?

ESP8266 is a wifi SOC (system on a chip) produced by Espressif Systems . It is an highly integrated chip designed to provide full internet connectivity in a small package.

Reference: ESP8266

What is it good for?

ESP8266 can be used as an external Wifi module, using the standard AT Command set Firmware by connecting it to any microcontroller using the serial UART, or directly serve as a Wifi-enabled micro controller, by programming a new firmware using the provided SDK.

The GPIO pins allow Analog and Digital IO, plus PWM, SPI, I2C, etc.

This board has been around for almost a year now, and has been used mostly in IoT contexts, where we want to add connectivity for example to an Arduino project. A wide adoption has been facilitated by the very modest price, ranging from 2.50 to 10 USD depending on the features offered by the manufacturers.

Some example projects:

Technical Features

  • 802.11 b / g / n
  • Wi-Fi Direct (P2P), soft-AP
  • Built-in TCP / IP protocol stack
  • Built-in TR switch, balun, LNA, power amplifier and matching network
  • Built-in PLL, voltage regulator and power management components
  • 802.11b mode + 19.5dBm output power
  • Built-in temperature sensor
  • Support antenna diversity
  • off leakage current is less than 10uA
  • Built-in low-power 32-bit CPU: can double as an application processor
  • SDIO 2.0, SPI, UART
  • STBC, 1×1 MIMO, 2×1 MIMO
  • A-MPDU, A-MSDU aggregation and the 0.4 Within wake
  • 2ms, connect and transfer data packets
  • standby power consumption of less than 1.0mW (DTIM3)

Operating Modes in ESP8266 SoC


The esp8266 module operates in the following modes:

  1. Active mode
  2. Modem-sleep mode
  3. Light-sleep mode
  4. Deep-sleep mode

Active Mode

This is the default mode of operation, where the CPU is running normally and also the Wi-Fi and Radio are powered ON so that the SoC can transmit, receive or listen to Wi-Fi. As the CPU is functioning, all the peripherals are also active and can be used by the application.

Power Consumption in Active Mode is dependent on whether the SoC is transmitting data over Wi-Fi or receiving data. Additionally, the power consumption also depends on the type of IEE 802.11 protocol (like 802.11b, 802.11g or 802.11n) and its associated modulation (CCK, OFDM or MCS7).

The following table gives the typical power consumption values for various parameters in Active Mode. The supply voltage is 3.0V and the ambient temperature is 25 0C.

Modem–Sleep Mode

This is the first and simplest low power mode or sleep mode of ESP8266 SoC. As the name suggests, in Modem–Sleep mode, the CPU of ESP8266 SoC is operational but the Wi-Fi and Radio are disabled.

Even though the Wi-Fi Modem circuit is powered down, the chip still maintains the Wi-Fi connection. This means that there is no data transmission but only the connection.

Turning off the Wi-Fi Modem will significantly reduce the power consumption and as the CPU is still operational, the Modem–Sleep Mode can be used in applications where only the CPU must be working (like ADC, PWM or I2S).

Light–Sleep Mode

In Light–Sleep Mode, the CPU, its clock and all the internal peripherals are also suspended in addition to the Wi-Fi Modem Circuit aiding in even less power consumption.

A simple application of light–sleep mode is a Wi-Fi Switch, where the CPU can be idle when not operational but the system is connected to Wi-Fi for receiving commands (Wi-Fi transmission is also disabled).

Since the CPU of ESP8266 is suspended in Light–Sleep Mode, it cannot respond to signals and interrupts from internal peripherals. So, in order to wake-up from Light–Sleep mode, an external GPIO trigger must be applied.

NOTE: GPIO16 cannot be used for Light–Sleep wake-ups.

ESP8266 Deep Sleep Mode Sketch

With deep sleep mode, an example application looks like this:

  1. The ESP8266 connects to Wi-Fi
  2. The ESP8266 performs a task (reads a sensor, publishes an MQTT message, etc)
  3. Sleeps for a predefined period of time
  4. The ESP8266 wakes up
  5. The process is repeated over and over again
ItemModem-sleepLight-sleepDeep-sleep
Wi-FiOFFOFFOFF
System clockONOFFOFF
RTCONONON
CPUONPendingOFF
Substrate current15 mA0.4 mA~20 uA
Average current (DTIM = 1)16.2 mA1.8 mA
Average current (DTIM = 3)15.4 mA0.9 mA
Average current (DTIM = 10)15.2 mA0.55 mA
the differences between each mode

Wake up Sources

After putting the ESP8266 in deep sleep mode, there are different ways to wake it up:

  • #1 timer wake up: the ESP8266 wakes itself up after a predefined period of time
  • #2 external wake up: the ESP8266 wakes up when you press the RST button (the ESP8266 restarts)

For low-power projects, you might consider using the ESP32 board which offers more deep sleep modes and wake up sources.

NOTE: In this article, I will present 2 ways to wake up ESP8266 while in deep sleep mode!

#1 ESP8266 Sleep Mode with Timer Wake Up

Connect the RST pin of ESP8266 with the GPIO 16 i.e. D0 pin. GPIO 16 is important pin which has a WAKE feature.

esp8266 connect LM35

Connect the LM35 temperature sensor with the A0 pin of NodeMCU.

When the ESP module has HIGH on RST pin, it is in running state. As soon as it receives LOW signal on RST pin, the ESP restarts.

Set timer using deep sleep mode, once the timer ends then the D0 pin sends the LOW signal to RST pin and the module will wake up by restarting it.

Now, the hardware is ready and well configured. The temperature readings will be sent on the Thingspeak server. For this, make an account on thingspeak.com and create a channel by going through the below steps.

Signup account and channel

Now, copy the Write API key. Which will be used in the ESP code.

ESP8266 Sleep Mode Programming

#include <ESP8266WiFi.h>
String apiWritekey = "*************"; 
char ssid[] = "XXXXXXXXXX"; // enter your wifi home router ssid
char password[] = "XXXXXXXXXX" ;   // enter your wifi home router ssid
char server[] = "api.thingspeak.com";
double tempF;
double tempC;
WiFiClient client;
void connect1() {
  WiFi.disconnect();
  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("NodeMcu connected to wifi...");
}
 
void data() {
  if (client.connect(server,80))
  {  
    String Data = apiWritekey;
           Data +="&field1=";
           Data += String(tempC);
           Data += "\r\n\r\n";
 
     client.print("POST /update HTTP/1.1\n");
     client.print("Host: api.thingspeak.com\n");
     client.print("Connection: close\n");
     client.print("X-THINGSPEAKAPIKEY: "+apiWritekey+"\n");
     client.print("Content-Type: application/x-www-form-urlencoded\n");
     client.print("Content-Length: ");
     client.print(Data.length());
     client.print("\n\n");  
     client.print(Data);
     Serial.println("uploaded to Thingspeak server....");
  }
  client.stop();
}
void setup() {
  Serial.begin(115200);
  Serial.println("device is in Wake up mode");
  while (!Serial) { }
  connect1();
  int value = analogRead(A0);
  float volts=(value/1024.0)*5.0;      //conversion to volts
  tempC = volts*100.0;             //conversion to temp Celsius
  Serial.print("Temperature C: ");
  Serial.println(tempC);
  data();
  Serial.println("deep sleep for 15 seconds");
  ESP.deepSleep(15e6); 
}

void loop() {
}
Result testing sleep mode with Thingspeak

Explanation: The general principle is that we will proceed to connect the ESP8266 to the wifi specified by you, then measure the temperature of the LM35 and then convert it to the temperature. Next we will send this measured temperature value to the Thinkspeak Server every 15 seconds and repeat this process. In those 15 seconds ESP8266 will be put into deep sleep mode using the function ESP.deepSleep(15e6);. 15e6 ~ 15×10^6 microseconds.

#2 ESP8266 Deep Sleep Mode with External Wake Up

Connect the button and ESP8266

ESP8266 read button

Connect the button and ESP-01

ESP-01 read button

Upload code to test ESP8266 sleep mode

/*
 * ESP8266 Deep sleep mode example
 * Rui Santos 
 * Complete Project Details https://randomnerdtutorials.com
 */
 
void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }
  
  // Deep sleep mode for 30 seconds, the ESP8266 wakes up by itself when GPIO 16 (D0 in NodeMCU board) is connected to the RESET pin
  //Serial.println("I'm awake, but I'm going into deep sleep mode for 30 seconds");
  //ESP.deepSleep(30e6); 
  
  // 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() {
}

The ESP will only wake up when something resets the board. In this case, it’s the press of a pushbutton that pulls the RST pin to GND.

When you press the pushbutton, the ESP8266 wakes up, does the programmed task and goes back to sleep until a new reset event is triggered.

ESP-01 is in deep sleep mode it’s only using 0.3mA

Leave a Reply

Your email address will not be published.