Introduction: Enable DeepSleep on an ESP8266-01
We all know how versatile the ESP8266-01 is. By "we", of course I mean the 6 people that are still reading this after seeing the title! Sure, it does have its limitations:
- only 2 GPIOs
- no analog GPIO
- inability to use the ESP.deepSleep() function
We've looked at getting more GPIOs before here.
We'll look at analog options another time. But in this Instructable, we'll deal with the Deep Sleep issue.
Step 1: Things You'll Need, or Maybe Want
Step 2: About ESP.deepSleep()
When your IoT project is powered by a plug in the wall, you tend not to care too much about power consumption. But if you are going to power your project by batteries, every mA counts.
The video at the beginning of this Instructable shows the actual power consumption of a data logging module I developed. In the video, you can see that while in deep sleep, the unit is only drawing about 3mA. In actuality, the ESP and the other components of the circuit are only drawing micro amps, but the project makes use of a voltage converter and regulator because it's fed off of 12 volt batteries. Those 3 mA are lost power consumed by the ghosts of necessary evil..
The point is, if your circuit is spending most of its time doing nothing, you can really cut back its power use by leveraging the deepSleep() function. In my example, I went from using an almost constant 40 mA, and cut it down to 3 mA.
Code-wise, you do have to think a little differently. When programming with the Arduino IDE, a lot of your heavy lifting code will be in the loop() function. The deepSleep() function will essentially reset your ESP. So, any variables, loop counts, etc, they all get lost.
Your setup() function in effect becomes your loop. When your program has done all that it needs to, before the closing bracket, you just throw in:
//1,000,000 = 1 second ESP.deepSleep(10000000);
And of course this assumes we have the following include at the beginning of the sketch:
#include <ESP8266WiFi.h>
At the end of the time specified in the deepSleep() function, the ESP will reset, and start everything at the beginning again.
Here is some code, and ways to handle variable storage. But in this Instructable, we'll focus on the hardware mods.
Step 3: Cut Some Fine Wire
Our ESP-01 can NOT use deepSleep out of the box. We have to solder a wire across two pins. This looks difficult, but trust me, it is not as hard as it seems. Start with some fine wire and strip both ends. An eighth of an inch should work.
I used some 28 ga wire that I use for jumper wires on my breadboards. You could use single-strand wire, but I think it works a little better with multi-strand wires - the wires hold a bit of extra solder amongst themselves. Plus if the gauge is too big, you could remove a few strands to get to the size we need.
Step 4: Examine the End That Connects to the Chip
The chip on the esp is tiny. It would be next to impossible to solder a wire directly to the pin we need to access. Luckily, the pin we need to hit is on the corner of the board. So what we will do, is make sure our tinned jumper wire is well tinned (but not over-soldered), and still skinny and pointy like a needle.
Practice holding the wire end to the pin we need to connect to. If you can't easily poke it straight at the corner pin and make good contact, try a thinner wire, or use some snippers to cut the wire to a point.
Step 5: Solder the Wire to the Rst (reset) Pin
Once the wire is cut and tinned, I like to bend it into the rough shape that you see in the pictures.
Now, we'll solder one end to the Rst pin on the ESP. We do this end first because it helps hold the wire stable when we solder the other end.
Step 6: Solder the Other Wire End to the ESP Chip
This is the hardest part - but don't fret, it's not that bad!
Take the other end of the wire, and poke it at that corner pin of the ESP chip (see picture).
Using your finger (or I like to use a pin, needle, or toothpick - something small yet strong), and hold the wire with the end jabbing at that pin. You want to use something to hold it while you solder, so it doesn't spring back once you remove your iron.
Now, touch your iron to the wire - not at the pin - but close to the plastic wire jacket. Because the wire is so thin, the pre-tinned solder should instantly melt. As soon as you see it liquefy, remove the iron.
Step 7: Hot Glue It to Add Strength
Finally, hit the edge of the board and the wire with some hot glue.
This will help to make sure that you don't break that wire off as you swap the ESP in and out of other project boards.
Step 8: Concluding Thoughts
Using the deepSleep() function will probably get you the most bang for your buck on conserving power, but don't forget to look at other power drains:
- Do you have any other components that are constantly using power? Try using a transistor or a relay to only turn them on when you need them.
- LEDs - if you don't need a light on, kill it! That annoying red power LED on the ESP? hit one side of it with your soldering iron while gently prying it with a small screwdriver (pin, needle, toothpick, etc). If you compare the two pictures here, the main difference is I killed the red power LED on the voltage regulator. Another mA saved! (yes, I know the ESP is also out in the second picture - but trust me, the savings is from that LED!)
Now you know how to make your batteries run the distance - go get creative with your upgraded ESP8266-01!
8 People Made This Project!
- Kraks made it!
- 11je made it!
- raagamparmar made it!
- gbnutte made it!
See 4 More
19 Comments
6 months ago
Hello, I did this modification on module ESP01S, but after wakeup signal (LED blinks) module does not wake up. Is possible to wake up ESP01S or it is possible only on ESP01? Thanks.
Reply 5 months ago
Does someone have same issue?
Question 1 year ago
Hello. Thanks for a great tutorial!
I followed it and was able to add sleep feature to my ESP01/DHT22 sensor.
However after a while the unit stopped going to sleep. It otherwise works OK.
I've re-flashed it but no luck
My worry is that my soldering job wasn't perfect so the wire might have disconnected. It all covered in hot glue so I don't wanna try and peel this off until I'm absolutely sure it's necessary.
But I wonder, in case of wire disconnecting, would the unit not be able to sleep, or, on the contrary, to wake up?
Thanks in advance
Answer 5 months ago
I guess I'm a bit late, but the answer is that it will go to sleep without any problem, but it will not wake up.
You have soldered a wire between the output of the RTC clock and the RST pin, when the clock times out, a signal(High or Low, can't remember) is sent to the RST pin to wake up.
2 years ago
Thanks for your article, really helpful.
I played sometime with the WemOS D1 mini, quite easier. I always connected RESET to GPIO16 through a 1K resistor following the recommendation from here https://www.esp8266.com/viewtopic.php?p=64543#p64...
In an ESP-01 I soldered a 1K resistor instead of a wire and it works very well, and also the manual reset alternative, a button from RESET to GND works as expected.
3 years ago
I too would like to create a battery power button. The mod is showing an ESP-01, how do you do it on a ESP-01S? @tytower mention a small-cap, has anyone done detail instructions for ESP-12?
4 years ago
One note to keeping your variables alive after a reset:
If all you need is to store some numerical values over a reset (e.g. deep sleep), you might want to use my lib RTCVars https://github.com/highno/rtcvars (advertisement end) which has exactly this use case and offers a (hopefully) simple way to store and access variables in RTC memory which is soft reset "resistant".
4 years ago
Hey guys there is a way to make it button working? i mean press a button to reset the esp while in sleepmode(0); ? I have made a little wifi button door opener (it just send a command to my nodemcu) but i like to transofrm it with a battery in a portable button.
Reply 4 years ago
Just realized now: reset pin and gnd = exit from deepsleep :P
5 years ago
Thanks for sharing. I have been struggling with DeepSleep on my ESP8266-01's.
Now I know why.
Regards
Eric
6 years ago
Interested to see how you alter the code
Reply 5 years ago
I need to strip some stuff out of one of my project sketches so it's more "Instructable", but there are two routes I use for variables: EEPROM and local filesystem (SPIFFS). I tend to have bad luck with EEPROM for some reason, so putting data in a local file on the ESP has been my go-to route. In the end, a local file is just data across some addressed space on the chip, like EEPROM, so it's all about the same and will take some added libraries and coding to make work either way.
Reply 5 years ago
I'd really like you to explain this a bit more. I have had quite a bit of trouble altering my programs to enable deep sleep and yours is the first instructable I have seen on it.
6 years ago
All your instructables are based on an outdated module .ESP-12's and later are just as cheap and fix all the problems you write about . Thanks for the instructable though . have you put it on the ESP8266 forum?
Reply 5 years ago
I find that "cheap" is relative to where you are willing to get them from - though I do agree, all ESPs are relatively cheap, and there are much more robust versions that will give you more bang for your buck. I just think we all get a little bit of enjoyment out of pushing components outside the limits they were designed for! Thanks for reading...
Reply 5 years ago
I bought 6 esp-12s at the start of my journey . Done everything I could and a lot they tell me I should not have, but they are still working, the ones I have opened and soldered, (4) .$3 on ebay from china which is the place that invented and manufactured them
6 years ago
Wow I'm one of the six :)
Nice instructable, thanks for sharing. Good to see that people are able to find solutions like this, the way of coding is new for me :)
Reply 5 years ago
Wow, you might be number 7! Thanks for reading!
6 years ago
The modules I have bought lately have all been ESP-12.
Placing a small cap across RESET-> GPIO16_XPD pin does the job and the soldering is easy