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, 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 = "";

void setup() 

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

  // Logging data to cloud
  Serial.print("Connecting to ");
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
  // 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");
  // Read all the lines of the reply from server and print them to Serial
    String line = client.readStringUntil('\r');
  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 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:

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, 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 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.

Want to learn more? Get my free eBook about the ESP8266!
The ESP8266 is an amazing WiFi chip that you can use to build all sorts of projects. Download today my free eBook "Build a WiFi Weather Station with the ESP8266". Simply click on the button below!

Leave a Comment

Zeni 2 months ago
Hi Thanks for the article. Give ideas to newbies like me. I think solar power may be a solution if unattended long term performance is intended. Can be used indoors also (after all we use solar powered calculators all the time). Just loud thinking.
Fabrizio 3 months ago
Hi Marco, I'm using an ESP8266-12E board with sensors and shields whose overall consumption is about 150mA: this board has a recommended voltage of 5 Volt (and a voltage regulator). Could I safely use 2x18650 batteries in series so to have a nominal voltage of 7.4V?
Marco Schwartz Fabrizio 3 months ago
If it's within the input range of the regulator, that shouldn't be a problem!
Mike 3 months ago
Your math is WAY off. You aren't figuring in the time that the module is awake and the power usage during that. Your code takes about 0.6 seconds to run. You have it running every 10 seconds. Assume it uses 170ma when awake/running (since it's actively using the wireless and serial port pretty much the whole 0.6s. The 81ma is just as it boots but when the radio is active, it uses around 170ma. Try moving your code to loop() and then remove the commands to make it sleep so that it's constantly running the radio and serial port and then check your power usage and you'll find it's much higher.) So when it's awake, it uses 170ma*0.6s or 102mas (milliamp-seconds.) When it's sleeping, it uses 0.077ma*10s or 0.77mas. Each cycle thus uses up 102.77mas and takes 10.6s to run. The 2500mah battery is a 2500*3600=9,000,000mas battery. So it'd last 9,000,000/102.77 or 87,574 cycles. This comes out to a bit over 10 days. Now if you did have it cycle every 10 mins (instead of 10 secs that the code does) then you'd have it use up 102mas when awake and 46.2mas when asleep. Each cycle would take a wee bit over 10 mins so we'll just say 148mas every 10 mins. Now the battery would last 60,810 cycles. So fewer cycles but each cycle is 60 times longer. So it's now 608,100 mins or 10, 135 hours or 422 days. So your 3.7 years is actually more like 1.15 years. But a LiPo battery will lose about 5%/month just due to self-discharge. So if the battery was left with no load, in 1 year, it loses about 60%. So your "1.15 years" is probably more like 6 months or so, tops.
Marco Schwartz Mike 3 months ago

Hi Mike, your calculation is definitely more accurate that mine, but as you probably know, physics & engineering calculations works by taking a given level of approximation. I just used more approximations than yours to make my calculations, to keep it simple for everyone. 

Diana 4 months ago
Hello, I use the code as is, and the module after returning of deep sleep remains suspended, that is to say the alone code executes once, already I have checked the circuit and you pines, the GPIO16 gives the descending flank, someone me prodria to help. Thank you.
John 4 months ago
nice article
Marco Schwartz John 3 months ago
Thank you!
Matej Sychra 10 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.
Swisscore a year 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
Craig Larson Swisscore a year 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 a year ago
Kzzircuit Maker a year 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 (
Ufuk Varlık a year 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 :)
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.
lio Didier Windey 5 months 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.
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
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.
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 2 years ago
Is it possible to "underclock" the CPU and futher reduce power, even while sleeping?
Ulrich Gierschner Hein Du Plessis 2 years 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 2 years 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?
Chris Tyler Ahmad Khalaf 2 years ago
You could have the ESP sleep until the IR signal and appropriate carrier (38/40 kHz) was detected.
Johan 2 years 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?
Chris Fearnley 2 years 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.
Daddy Dave 2 years 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.
Marco Schwartz Daddy Dave 2 years ago
Good question! Apparently it's possible: That would be a nice addition to the project :)
Robert Aidaid 2 years ago
will it always re-connect wifi when wake?
Slartifartfast Robert Aidaid 2 years 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...
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?
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?
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?
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,, 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
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
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: 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.
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 Indonesia
Recently signed up
4 hours ago
Someone from Germany
Recently signed up
10 hours ago
Someone from the United States
Recently signed up
a day ago
Someone from the United States
Recently signed up
3 days ago
Someone from Spain
Recently signed up
5 days ago
Someone from Germany
Recently signed up
5 days ago
Someone from Germany
Recently signed up
6 days ago
Someone from Belgium
Recently signed up
6 days ago
Someone from Spain
Recently signed up
6 days ago
Someone from the United States
Recently signed up
6 days ago
79 people recently viewed this page