Sleep mode of ESP8266

Hi

I am working on a project in which I am using ESP8266 for Wi-Fi. I want to enable deep sleep mode to save power in my application.

Is there any separate library required to download for deep sleep mode or by just writing my code for deep sleep mode is sufficient?

No separate library needed but if your using the ESP.deepSleep() then GPIO16 needs connecting to RST pin so the ultra low power timer can wake the sleeping ESP8266.

Inlcude the <ESP8266WiFi.h> library. Then you can enable sleep modes. I have found the wifi on the ESP to be quite tricky. In some conditions it wont connect.

Here is some code that I have found well working:

include <ESP8266WiFi.h>



//Connecting to wifi:

WiFi.forceSleepWake(); //Wake up wifi-chip from sleep
yield(); //give OS control to wake up wifi. delay(1) works also

  WiFi.mode( WIFI_STA);  //Lets put it to station mode
  WiFi.begin(ssid, password);
  byte timeout = 60;

  while (WiFi.status() != WL_CONNECTED || timeout != 0){
    timeout--;      
    delay(500);
    Serial.println("Connecting to WiFi");
  }

  Serial.println( "Connected" );
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP()); //kerro IP osote



// put ESP to deep sleep and wake up with radio enabled:

   WiFi.disconnect(true);  //if this line is missing, you wont get to the promised 20 uA current consumption while sleeping
    yield();
    ESP.deepSleep(1e6, WAKE_RF_DEFAULT);  //put device to sleep for 1 second and wake up with wifi radio enabled



// put ESP to deep sleep and wake up with radio disabled:

  WiFi.disconnect(true);
  yield();
  ESP.deepSleep(60e6, WAKE_RF_DISABLED);   //sleep for 60 seconds and wake up with radio disabled



//When waking up with radio enabled but you want to do something else before connecting to wifi, put these lines first in your void loop() (to save power). ESP connects otherrwise directly to last used wifi:

 WiFi.mode( WIFI_OFF );
  WiFi.forceSleepBegin();
  yield();  //yield or delay(1) is needed to give control to the OS

I am not using NodeMCU. I am using very basic ESP8266 module which has 8 pins only. It does not have any GPIO16 pin.

I have connected VCC and CH_PD of ESP8266 with 3.3V of Arduino UNO, GND with GND and RX and TX of ESP8266 with Pin 4 and 3 respectively of Arduino UNO.

Now if I want to enable deep sleep mode for ESP8266 then, is there need to change any hardware configuration or by simply writing code as per suggestion by including library ESP8266WiFi.h work....

@NusNus, would you mind putting those snippets into the context of a sketch that actually compiles (setup, loop, etc)? It would be nice to see where each one should be applied.

RX and TX of ESP8266 with Pin 4 and 3 respectively of Arduino UNO.

The RX through a voltage divider i hope ? and you are using swSerial on the Uno for communicating with the ESP ? if you just want to save power how about connecting the CH_PD via a voltage divider to an Arduino pin, then you can control power on from there. Btw i have experienced ESP-01 's breaking by connecting them to Arduino pins (even with voltage divider) at either power-up or power-down (one or the other i turn it off, and turn it on and then it's f%^$ed. )

Supreet:
I am not using NodeMCU. I am using very basic ESP8266 module which has 8 pins only. It does not have any GPIO16 pin.

You will need to practice your soldering skills then or use a different ESP8266 package. I have soldered GPIO16 (circled in red) to EXT_RSTB (circled in blue on the chip and the broken out pin) on some ESP01 modules but it’s not fun.
Clipboard-1.jpg