ESP8266 Turn off WiFi to save power

In this tutorial we see how to turn off ESP8266 WiFi, There are two methods to turn off wifi first is to use simple ESP8266WiFi.h Library and use WiFi.mode(WIFI_OFF); and another method to use  WiFi.forceSleepBegin(); By turning wifi off you can save some power. or using only (WIFI_STA) station mode you can hide ESPs own Access point.

Turn off ESP8266 WiFi

ESP8266 WiFi Example Code

 * Turn off ESP8266 WiFi

#include <ESP8266WiFi.h>

//                    Power on setup

void setup() {

  Serial.println("Turning WiFi Off");

  //WiFi.mode(WIFI_AP);   //To Turn on WiFi in Specific Mode like WIFI_STA or WIFI_AP
  //Turn off WiFi
  WiFi.mode(WIFI_OFF);    //This also works
  //WiFi.forceSleepBegin(); //This also works

//  WiFi.mode(WIFI_AP);   //This line hides the viewing of ESP as wifi network    
//  WiFi.begin(ssid, password);

//                    Main Program Loop
void loop() {

You control WiFi using wifi.setmode(). ESP8266’s WiFi is very versatile. You can be a client and/or an access point. You can get your IP from DHCP or static.

Per default, ESP8266 start in STATION_AP mode (as client and access point).


Configures the WiFi mode to use. NodeMCU can run in one of four WiFi modes:

  • Station mode (WIFI_STA), where the NodeMCU device joins an existing network
  • Access point (WIFI_AP) mode, where it creates its own network that others can join
  • Station + AP mode (WIFI_AP_STA), where it both creates its own network while at the same time being joined to another existing network
  • WiFi off (WIFI_OFF)

When using the combined Station + AP mode, the same channel will be used for both networks as the radio can only listen on a single channel.


WiFi configuration will be retained until changed even if device is turned off.


wifi.setmode(mode[, save])
--Resume wifi from timed or indefinite sleep


In below picture you will see Before turning off wifi and after turning off wifi scan results

  1. Before turning WiFi Off it shows ESP_47A070  MAC address last six digits.
  2. After Turning WiFi Off

Leave a Reply