How to Run Your ESP8266 for Years on a Battery

How to Run Your ESP8266 for Years on a Battery

For most of the projects I am building with the ESP8266 WiFi chip, I usually don’t care too much about the power consumption aspect. I for example build data loggers that are constantly connected to the mains electricity, and appliances controller which also have an easy access to power. However, in some cases, we want to build projects that are only powered by batteries. This is for example the case for a motion sensor that you will install in your home, or a data logger you would put in a remote location.

For those cases, you don’t want to be changing the batteries constantly. For example, an ESP8266 chip with a standard 2500mAh LiPo battery would last for about 30 hours. Not good enough. That’s why in this article, I will show you how to significantly reduce the power consumption of your ESP8266 boards using the deep sleep mode of the chip, so you can build projects that will last for years on a single battery. Let’s dive in!

Hardware & Software Requirements

Let’s first see what we need to build this project. The first thing you need is an ESP8266 board. Here, as we want the project to be low-power, the most important is to choose a board without a lot of features, so there are no extra components to reduce the battery life of your project. Here, I choose the SparkFun ESP8266 Thing as it allows to work at very low powers.

You will also need a 3.3V FTDI USB adapter, as well as a breadboard and jumper wires. Optionally, to test the power consumption part, you will also need a breadboard power supply, a multimeter, and a LiPo battery.

This is the list of the required components for this project:

You will also need the latest version of the Arduino IDE, as well as the ESP8266 board definitions.

Hardware Configuration

Let’s now assemble the project. As we just want to lower the power consumption of the board, the configuration will be quite simple here. If you just want to use the project with a low power consumption, you simply need to connect the DTR pin of the board to the XPD pin, which will make sure the chip can wake up from the deep sleep mode.

Here, I want to measure the power consumption as well, so I’ll also be using a breadboard power supply, and connect the power to a multimeter so I can measure the current flowing through the chip. Here is a closeup picture of the project:

How to Run Your ESP8266 for Years on a Battery

This is a picture from farther away, showing the connections to the multimeter:

How to Run Your ESP8266 for Years on a Battery

Reducing the Power Consumption of Your ESP8266

We are now going to see how to lower the power consumption of your ESP8266 WiFi chip. To do that, we are going to use the deep sleep functions of the chip, that will simply sleep when no actions are required. As a simple example, we are going to log a simple dummy message to Dweet.io, which is a cloud service that is used to log data online. This will for example illustrate a data logger project that will only make measurements every 10 minutes for example, and sleep the rest of the time.

This is the complete code for this part:

// Library
#include <ESP8266WiFi.h>

// WiFi settings
const char* ssid = "wifi-name";
const char* password = "wifi-password";

// Time to sleep (in seconds):
const int sleepTimeS = 10;

// Host
const char* host = "dweet.io";

void setup() 
{

  // Serial
  Serial.begin(115200);
  Serial.println("ESP8266 in normal mode");
  
  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Print the IP address
  Serial.println(WiFi.localIP());

  // Logging data to cloud
  Serial.print("Connecting to ");
  Serial.println(host);
  
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
  
  // This will send the request to the server
  client.print(String("GET /dweet/for/myesp8266?message=lowpower") + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  delay(10);
  
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  
  Serial.println();
  Serial.println("closing connection");

  // Sleep
  Serial.println("ESP8266 in sleep mode");
  ESP.deepSleep(sleepTimeS * 1000000);
  
}

void loop() 
{

}

This code is quite long, but let’s now focus on what we need for the deep sleep functions. First, we define how long we want the chip to stay in deep sleep mode. For test purposes, I set it to 10 seconds here:

const int sleepTimeS = 10;

Then, inside the setup() function of the sketch, after sending the request to Dweet.io we put the chip in deep sleep mode:

Serial.println("ESP8266 in sleep mode");
ESP.deepSleep(sleepTimeS * 1000000);

Note that here we need to put the whole code inside the setup() function of the sketch, as whenever the chip goes out of deep sleep mode, it starts again at the start of the setup() function.

You can get the whole code from the GitHub repository of the project:

https://github.com/openhomeautomation/esp8266-battery

It’s now time to test the project! First, remove the connection between DTR and XPD, so you can actually program the board. Also modify the WiFi credentials inside the code. Then, upload the code to the board, and connect the jumper cable again.

If you have a multimeter monitoring the current consumption of the ESP8266, this is what you first should see when the chip is booting:

How to Run Your ESP8266 for Years on a Battery

This is the current that is used when the board is uploading data to Dweet.io, but it is also what the chip would use if we didn’t do any kind of optimisation for power. In that case, a 2500 mAh battery would last about 28.5 hours.

After a few seconds, the chip will enter deep sleep mode, and you should immediately see the power consumption going down:

How to Run Your ESP8266 for Years on a Battery

As you can see, we already have a 10 times lower current consumption! At this rate, if we take the case of a data logger that just stays in sleep mode most of the time, the battery would now last 300 hours, or 12.5 days! It’s already a great improvement, but we can do much more with the SparkFun Thing.

Actually, most of this power is now used by … the power indicator LED on the board! This is great when you are developing applications on your desk, but not that useful when you are deploying your project in the field. Therefore, we are going to get rid of this LED here.

For newest versions of the SparkFun thing, you can simply unsolder the “PWR” jumper at the back of the board. For older versions like the one I have, you can simply cut the trace between the PWR LED and the nearby resistor. After that, just power the project again. The reading on the multimeter immediately changed to 77 uA, or 0.077 mA. This means that the same project will now last on the same battery for … 3.7 years! Of course, this doesn’t take into account the characteristics of the battery, so in reality you will end up with 1-2 years battery life for your project.

How to Go Further

In this article, we learned how to reduce the power consumption of the ESP8266 WiFi chip, so you can build projects that last for years on a single battery. Of course, this is an ideal situation, and it can’t be applied to all projects, and in reality probably the battery will be dead before the time I calculated in the article. However, this is a great solution for anybody interested in data logging projects where the device is spending most of the time doing nothing.

You can now use what you learned in the project, and build your own projects with it. You can simply use the code I used in this article, and just add a few lines to make measurements from sensors, and send those measurements to Dweet.io or another cloud platform of your choice.

Note that this article is a continuation of the very popular article I wrote before about How to Run an Arduino for Years on a Battery.

Leave a Comment

Matej Sychra 5 months ago
OK, so I've started with this and powered an OLED display and/or SigFox device through OPTRON so I'm sure the external device gets powered on only when ESP wakes up (GPIO pin ON). It seems to last for a month with 3.7V Li-Ion battery and a HTTP request every hour.
Reply
Swisscore 7 months ago
For example I want to do state sensors (open/close) for doors, I store the result in RTC eeprom and check (after 15mn deepsleep) if states are still the same or not, if yes, I don't send again datas, I save power because don't turn ON Wifi connection
Reply
Craig Larson Swisscore 6 months ago
Yes, read the comment from Frank Sommer of this blog for the "if not" state-change part of your question. In essence you disable the radio. You may need to re-sleep to re-enable the radio - I don't know as I've never tried. Separately, I have read that during sleep cycles you can store data in the RTC registers for use in your state-change condition test. It is probably in the 8266 datasheet.
Kaloyan Radomirov 7 months ago
impossible
Reply
Kzzircuit Maker 7 months ago
Thanks for this great article.... I would be using some of these tips in my project with a flow-sensor where I want to run the ESP8266 using a battery without a power-line.. Looking at the sensor H/w my initial guess was that the flow-sensor might take a lot of (continuous) power. While I can still make the ESP to go into sleep mode, the sensor should not actually sleep (ever). However, after going through the specs, looks like the sensor would use about 15mA while the ESP8266 power tests show much higher current usage with the wireless (I guess it still uses 10-15 mA in deep-sleep or modem-off states). I would use some of the tips you have shared here. Thanks!Kzzircuit (https://LexyBit.com)
Reply
Ufuk Varlık 8 months ago
Hi dear friends,I just started writing programs. I am using the STM32F0 Discovery DK (STM32F051R8) and communicated with UART. I using KEIL IDE. I made a button-led application with a server control but, the module consumes 116mA (with Discovery). How can I use the Deep sleep mode of the Wifi module? Arduino has ESP.deepSleep() function in "ESP8266WiFi.h" file. How can I write a similar or same function c code in the KEIL IDE ?Thanks for your valuable feedback :)
Reply
Didier Windey a year ago
I build a thermometer with a ds18b20 sensor. With deep sleep it wakes up every 5 minutes. It powers and reads the sensor. Then the EEPROM is read to compare to the previous reading. If more than 0.2°C difference or more than 12 cycles were ran wifi is enabled and data is send to the server. Then writes data to EEPROM en goes back to sleep.The ESP is solderd on a white adapter board (dealextreme) with the middle SMD resistor desoldered. Powered with 4 AA batteries it runs about 3 months. Cycle time is monitored and also send to the server. Most of the time a full cycle (read sensor, connect wifi, send to server) takes 7-12sec. Fixed IP or not makes no difference.
Reply
lio Didier Windey 24 days ago
Hi Didier, i'm very interesting about your code, can you send your sketch or code to my email, please ? Thk you…
Lucas Henrique a year ago
Hi friends, thanks for sharing!I'm doing a project that I can receive data at any time. Is there an economic "standby" for which ESP would not have spent as much energy waiting for a signal? For it wake up only when it gets a signal, or something.
Reply
Craig S. Thom Lucas Henrique a year ago
The radio uses the lion's share of the power, and you must have the radio on to receive anything, so, no.
Mohamed Imran a year ago
how to edit the timer in HTML User Interface
Reply
William John Goetzinger a year ago
I am using an ESP-01 module. I have removed the power and Tx LEDs. In deep sleep mode my current is still 2 mA. Any ideas why the current is this high? My power source is two 1.5V AAA cells in series.Thanks.
Reply
Didier Windey William John Goetzinger a year ago
when the voltage is lower than 3.3V the ESP is using much more current. Better use a voltage regulator with very low quiescent current
Hein Du Plessis a year ago
Is it possible to "underclock" the CPU and futher reduce power, even while sleeping?
Reply
Ulrich Gierschner Hein Du Plessis a year ago
I don't think that makes sense. The energy saving options are much more sophisticated that only reducing the frequency. I mean, the frequency will already be reduced when in sleep mode. So, don't bother with that option.
Frank Sommer Hein Du Plessis a year ago
Keep in mind, that most of the power is needed for WLAN - around 100mW. So you can reduce the power of a running ESP if you do not need WLAN by turning the ESP into deep sleep with WLAN disabled after wake up: ESP.deepSleep(<sleeptime>, WAKE_RF_DISABLED)To turn the ESP into DS with WLAN enabled after wake up use: ESP.deepSleep(<sleeptime>, WAKE_RF_DEFAULT);
Ahmad Khalaf a year ago
I use ESP as IR remote, so it needs to be awake very frequently as it could receive a command at any moment. 2200mA battery lasts less than 24 hours. Do you have any advice for significantly improving the consumption in this case?
Reply
Chris Tyler Ahmad Khalaf a year ago
You could have the ESP sleep until the IR signal and appropriate carrier (38/40 kHz) was detected.
Johan a year ago
This is interesting and the reason i chose a Feather Huzzah for my battery powered datalogger project. I use the RTC+SD (Real time clock, SD-card reader) wing shield and a DHT22 sensor. All leds off and deep sleep mode I get around 7 mA current from the battery. But after waking up once, and going back to the next sleep round, the current is 16 mA! Reset doesn't make a different, but after reset by removing the battery it goes back to sleeping at 7 mA the first sleep round, and then again 16 mA the following sleep rounds. Any ideas? Why is it even 7mA when it could be less than 1 mA? The shield and sensor? The voltage reg?
Reply
Chris Fearnley a year ago
There's another blog (see below) which suggests that a full cycle, including getting wifi up and running is only taking around half a second (rather than 3-4 seconds just for the wifi as discussed here). But that's with fixed IP; seems that DHCP is taking all the wifi startup time.https://forum.makehackvoid....[later] Yes, just confirmed with my new Adafruit Huzzah module. WiFi connect time with DHCP is 3-4 seconds. with fixed IP it is just 200 ms.
Reply
Daddy Dave a year ago
Does the ESP have a wake on state change pin? I'll do some homework on it later today. Maybe I'm missing something here, but sleeping for ten minutes is a lot of time to ignore motion in the room. The preferred method is to log all motion as it occurs then wake every x minutes or hours to send data via power hungry wifi. This is a more complicated solution, though.
Reply
Marco Schwartz Daddy Dave a year ago
Good question! Apparently it's possible: https://github.com/esp8266/.... That would be a nice addition to the project :)
Robert Aidaid 2 years ago
will it always re-connect wifi when wake?
Reply
Slartifartfast Robert Aidaid a year ago
that is settable.
Lachlan Kidd 2 years ago
so it's a sloppy write up (done at speed :-) ) but here's my low power journey with the esp8266.I reckon i can get my circuit down to 10-20uA by completely turning off the esp8266 via an ATTINY85 and a reed switchhttps://iothacking.wordpres...
Reply
Helmi Susanto 2 years ago
hey every body,i have a some question..if esp8266 in deep sleep mode, can esp8266 accessing from other device / maybe access via web browser? it just wake up on our request, and come back sleep when not an activity? isn it?
Reply
Odun Adeboye 2 years ago
hi,thanks for your article, its a good one.I have a question on the Quiescent Current of the power regulator(AMS1117-3.3v) which is min 5mA and max 11mA from the datasheet.Was the Quiescent Current considered in the calculations?
Reply
Marco Schwartz Odun Adeboye 2 years ago
I basically just measured the current drawn by the power supply directly, so the quiescent current of the regulator is already included in the calculations :)
Gus Smith 2 years ago
Hi, how did you do the math? I would like to use a sensor using esp8266. If you have 2500mah battery / 0.077 that is about 3.7 years. But where did you include the calculation for the awake power consumption of the esp8266 of 80ma when booting and sending data?
Reply
AvatarJones Gus Smith 2 years ago
Hi Gus. I posted a similar question. I *think* Mr. Schwartz's 3.7 year calc does NOT include booting or "work." Just sleeping @ 0.077 mA.Determining battery life depends on lots of factors, but you can calculate a loose, loose, LOOSE estimate this way: (battery capacity in mAh / "work" current draw in mA) * ("deepsleep" duration in seconds / "work" duration in seconds). If your board wakes up every 5 minutes (300 seconds) and "works" for about 5 seconds to post data to dweet.io,, the "work" pulls about ~80mA, and you've connected a 2500 mAh battery to the board, the battery will last for about (2500mAh / 80mA) * (300s / 5s) = 1875 hours. Or about 78 days.My math is pretty, ummm...optimistic. :) But for a ballpark estimate, it works. My calc assumes *no* draw during deepsleep which is NOT true, but I wanted to keep the calc simple, and the deepsleep draw is very, very small compared to the "work" draw in most cases. Nor does my math account for the normal discharge of the battery even when it's not doing work or deepsleeping. So maybe subtract 10-20% from my calc to account for both.
AvatarJones 2 years ago
Way helpful article. I wonder if you could answer two questions? When you disconnected the PWR LED and the current dropped to 0.077 mA, was that during the deepsleep cycle or the "running" cycle? I feel like it has to be during the deepsleep cycle but then wondered why the LED would be lit during the deepsleep cycle. Also, any chance you could break down the math for your 3.7 years and/or 300 hours calculation? I'd like to make a similar estimate for an ESP8266 board from a different manufacturer based on measurements from my multimeter, and I'm having a hard time working out the maths! Thanks. AJ
Reply
santa2015 2 years ago
I guess the battery life would be considerably reduced if the esp8266 thing is used as a motion detector, as it should be sleeping pretty little, not to lose some motion activity
Reply
Rene Arts santa2015 2 years ago
For a motion detector (probably using a PIR sensor) it is possible to only wake up the ESP when motion is detected by the sensor and let the ESP wake up only once per hour/day to send an "I am still alive" signal with i.e. battery status. Have a look over here: http://www.esp8266.com/view...Another thing: this is also quite interesting for making a solar panel powered ESP based sensor with a small battery to bridge the nights.
Marco Schwartz santa2015 2 years ago
That's for sure, it's really for systems that are only active for short & regular time intervals.
Shares
How to Run Your ESP8266 for Years on a Battery How to Run Your ESP8266 for Years on a Battery How to Run Your ESP8266 for Years on a Battery How to Run Your ESP8266 for Years on a Battery How to Run Your ESP8266 for Years on a Battery How to Run Your ESP8266 for Years on a Battery
Someone from the United States
Recently signed up
15 hours ago
Someone from Germany
Recently signed up
2 days ago
Someone from Brazil
Recently signed up
2 days ago
Someone from Australia
Recently signed up
2 days ago
Someone from Netherlands
Recently signed up
3 days ago
Someone from Iran, Islamic Republic Of
Recently signed up
3 days ago
Someone from Netherlands
Recently signed up
4 days ago
Someone from Slovakia
Recently signed up
4 days ago
Someone from Hungary
Recently signed up
4 days ago
Someone from India
Recently signed up
4 days ago
213 people recently viewed this page