Battery-Powered ESP8266 Sensor? Never Been Simpler

Fritzing diagram of connections between the Wemos D1 board, the TP4056 board, the pushbutton and the LiIon battery

Say, you’re starting your electronics journey with a few projects in mind. You have an ESP8266 board like the Wemos D1, a Li-Ion battery, you want to build a small battery-powered sensor that wakes up every few minutes to do something, and you don’t want to delve into hardware too much for now. Well then, does [Mads Chr. Olesen] have a tutorial for you! Here, you’ll learn the quick and easy way to get your sensor up and running, learn a few tricks for doing sleep Arduino environment, and even calculate how long your specific battery could last.

You’ll need a TP4056 board, providing charging and battery protection features, a jumper, and maybe a pushbutton – the Fritzing diagram shows everything you’d like to know. From there, you have examples on using deep sleep, do pushbutton or sensor-driven wakeup, manage WiFi, and even read the battery voltage – all of these are a single line of code away, and you learn the few important caveats there are. In the end, there’s even an embedded calculator for how long your Wemos D1 board can survive on a single charge – enter your capacity, the amount of time between wakeups, and see just how long your board will last.

This tutorial is truly accessible if you never touched ESP8266 deep sleep before but would like to start – it’s short and sweet, and you’ll have your battery-powered sensor up and running in no time. It doesn’t go into topics like optimizing the onboard hardware, but in all fairness, you don’t have to do that until you’re ready, and sometimes, it’s really software optimizations that will have a hefty payoff . And, if you ever want to learn more about Li-Ion-powered devices, our tutorials are there for you.

23 thoughts on “Battery-Powered ESP8266 Sensor? Never Been Simpler

  1. Wow. I guess that approach would work. Pretty cumbersome. Maybe it’s the WemosD1 causing the extra effort, I’ve never used those. The ESP8266 has a perfectly functional sleep or deepsleep mode. And many of the sensors like BMExxx can also turn the sensor(s) on/off as needed.

          1. The ESP32 is technically superior in all aspects. The only thing that keeps 8266 alive is it’s cost. For me efficiency, simplicity and power trump a few bucks everytime for a few devices

  2. ESP8266 can work years from fully charged 18650. You must use low drop voltage regulator as it was mentioned earlier, USB converter chip should be removed, which leaves you with basic ESP8266; and most important – communication should be via ESP-NOW, not WiFi. On time will be reduced to under 0.1 of a second compared to few seconds with WiFi.

      1. It will, but you can get around this by having another esp_now “Hub” that is plugged in or otherwise provided with more power to act as a handler for all the wireless sensors, and then it can connect to WiFi and send to an app via http or mqtt. It all depends on how often the sensor needs to send data. If it is only say once every 30 minutes or so, then you can get by with WiFi and deep sleep in-between. If it needs to be more often, then the sensor->Hub->WiFi is way more energy efficient, just requirements an extra component built.

    1. That info was helpful when I was trying to do something similar, but I think it’s also a bit out of date. IIRC there have been a number of changes to the ESP8266 Arduino core files, some made his code to manipulate the wifi state not work as he describes, and one that makes sure wifi is off while the Arduino code is loading.
      Also, there is WiFiState.h that contains code and structures to store wifi state data to RTC and restore it on waking from sleep. It works fine as long as you don’t need to store anything else to the RTC RAM, but some sort of standardized layout for the RTC RAM along with some getters and setters would be something I’d like to see (and maybe there is one now since I haven’t revisited this in a while).

      With an ESP01, an LDO, and SHT30, I could eek out just about a month of runtime with 4AAA batteries with my measurements set to 1 minute intervals (just an arbitrary number I was messing with). With a 18650, the run time is much longer and I rarely need to think about batteries.

  3. FWIW I made 3x ESP8266 + DHT22 each using 2x AA alkaline batteries. 3.3V regulators removed from both ESP an DHT22 which came with SHTC3 sensor. Both LED’s removed on ESP and 3mm external LED wired for TX indication. Wire added for deep sleep. WIFI router uses static IP for sensors.

    They transmit UDP WIFI data every ~5 minutes. Data comprises of sensor number, temperature, humidity, battery voltage (as there’s no voltage regulator) , wake time which is timer + 10ms added just before TX and sleep, WIFI signal level and station SSID (as there are multiple choices).

    Normal wake time is 250ms (0.25 seconds) including sensor unless the router isn’t available in which case it tries for up to 10 seconds. So far they have been running 1 year and 4 months, now at 2.6V so maybe not much longer.

    Testing with PSU showed 2.4V as lower limit. One sensor is in the attic with temperatures sometimes reaching over 50C.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.