Experiments with ESP Easy (ESP8266) and low consumption - v1.0

Last modified April 6, 2021

You want reduce the consumption of your project with ESPEasy and an ESP8266 easily to be able to use it with batteries for months? Keep reading.

In this series of articles, of which this is the first, I will tell you about the progress that I am making and how you can also make and apply them in your project.

In this first article, in addition to explaining the experiment itself, I will give you all the basis you need and that will serve you for the experiments that I will explain in future articles and even for your own.

To be clear, I am going to explain everything to you with the project that I am dealing with, which is a low consumption CO₂ meter, but practically everything that I explain here is valid for any other low consumption project that you want to do.

What you will find they are not techniques to win autonomy contests (which can be very complex, both from a hardware and software point of view) but simple techniques that work and with which you can obtain more than acceptable results without complicating your life.

I've been wanting to prepare a version of the battery or battery operated CO₂ meter, that allows a interesting autonomy (a few weeks, at least).

In the case of the CO2 meter, where one of my goals is that anyone, without prior knowledge, can build a quality CO2 meter with ease and certain guarantees of operation, this poses several challenges that require making some compromise decisions (that are good enough, without needing to be the best, but that are very easy to implement and that in the balance of ease / result it is clearly the winner).

I recently posted a tutorial on the blog, with its step-by-step video tutorial, for add battery operation to the CO2 meter (or any other project), or more exactly with battery and power supply, indistinctly.

Contrary to this article, the goal of that tutorial was to add battery to the existing project, without breaking autonomy records. What was intended was to provide the meter with battery for occasional use with sufficient autonomy for a day of measurements (between eight and 24 hours, depending on the battery used).

In this case the project is a lot more ambitious. It's about creating a battery-powered or battery-only CO₂ meter and with a much longer autonomy. Twelve days of autonomy, in this first experiment, using a single Li-Ion 18650 battery, which is not bad at all, to be the first attempt.

When I defined the project in my head, there were a series of objectives as a premise:

  1. That was very easy to build, from a hardware point of view
  2. That was very easy to program and configure, from a software point of view
  3. That had continuity with the work already done previously on this blog
  4. That was very easy to solve doubts and problems for users who decide to do so

These are the results of the first experiment, So don't expect miracles, it's just a first test. I will be publishing other experiments, increasingly complete and optimized, as you make them.

I will be happy to hear the results of your own experiments., if you decide to do them, through the blog comments or in the Telegram group by eMariete, as you prefer.

How do you get a circuit to consume as little as possible?

Basically optimizing everything that can be optimized. The maximum is: Every µA counts.

This is like becoming a millionaire by saving pennies.

To optimize in this way, we have to choose wisely the components that consume less. Optimize the time that those components are on and the efficiency when it comes to getting things done.

All of this is important.

There are components that consume much more than others, that do the same, and there may even be components that we can completely do without.Think, for example, of an LED that is always on, consuming energy only to indicate that our circuit is on. What a waste! If my grandmother lived and understood these things, she would be very angry!

And what about the weather? If we want to measure CO₂ every minute, for example, and that takes 1 second, why have our circuit turned on for the remaining 59 seconds?

An ESP8266 on draws about 80mA while an ESP8266 "asleep" (waiting to wake up and "Do something useful") consumes only between 8 and 20µA (4000 times less). We can multiply our battery life by 4000 times just letting the ESP8266 go to sleep when we don't need it to do anything!

The hardware of the experiment

For a low-power project like this, unfortunately, it is not recommended to use a NodeMCU or Wemos D1 Mini board, as we have used in other projects. Those plates consume too much.

I love both boards for projects that are plugged into the current, but for what we are going to do here they are not useful.

An ESP8266 in deep sleep mode (asleep, and waiting for something happen, to wake up and do it) can consume as little as 8 to 20µA (1 mA = 1000 µA) while a NodeMCU board with its ESP8266 in deep sleep mode consumes around 8-20mA. This is between 500 and 1000 times more!

In other words, if we power an ESP8266 in deep sleep mode with a 2000mAh battery it will have an autonomy of X hours or days, while a NodeMCU board with the same battery would only have an autonomy of X / 1000 hours or days (it gives me laziness to calculate autonomy, I'll do it).

And why is this?

Simple, because the NodeMCU has, in addition to the ESP8266 various things that consume a lot and that, to make matters worse, we do not need.

The voltage regulator (which reduces the voltage of the 5V with which we usually feed it through a USB port, and which is usually a chip AMS1117 consumes 5mA by itself (consumes 500 times what the ESP8266 in deep sleep mode!).

Maybe you are also interested in:  How does a Geiger counter work? Discover its 6 characteristics

Here we have two options:

  1. Power the ESP8266 directly from the battery
  2. Use a regulator that consumes less

In this test, I have used an MCP1700 regulator that has a consumption "without doing anything" 1.5µA (3333 times less than AMS1117!)It is almost negligible, because it means less than an additional 1% to the 20µA that the ESP8266 consumes (remember the maximum, each µA counts), but it is a very good drop.

We could avoid those 1.5µA by feeding the ESP8266 directly from a battery, but that presents other problems, which they would complicate this project, for very little profit. For that reason I dismiss it (perhaps one day I will do an experiment with it).

Another detail is that I have not chosen a 3.3V regulator, which is the "official" supply voltage for the ESP8266, but one of 3.0V.

This allows me to squeeze the battery more since I can download it 0.3V more and it works perfectly because it is within the operating margins of the ESP8266 (if you look at the graph that I have left below, you will see that it has been working up to 2.91V approximately, I haven't wasted much time calibrating the voltage divider).

If you want to know more, here is the MCP17000 datasheet with all your data.

Another item that consumes a lot is the USB-to-serial converter chip.

The ESP8266 does not have USB, it only has one pair of pins for serial port communications, so that, to make your connection and programming easier for us, the NodeMCU board includes a usb to serial adapter external.

The problem is that the chip of that adapter (the CP2102, although there are others with other consumptions) it consumes approximately 330µA, even when it is doing nothing. What? 330µA? Has anyone gone crazy? What a waste!

And why do I want a USB to serial converter on the CO2 meter? So I am going to tell you: absolutely not at all. So, I'm going to do without it and I'm going to be so comfortable.

Of course, we no longer have a USB port, so we will have to see how we are going to do it connect to computer to record it (More on this later).

And then?

Well, what I'm going to use is an ESP8266 "Almost peeled", directly. I'm going to use an ESP-12F module which is just the ESP8266 chip with the bare minimum to work.

Click on the image to buy it

The ESP-12F includes the chip, placed on a small board with terminals to connect it, the antenna (Remember that being Wi-Fi it needs an antenna, although we don't think about it often because it's built into the board and we hardly see it) and a few minimal components for the ESP8266 to work (some capacitors and resistors). Nothing more.

The ESP-12F is a module with which it is a bit "uncomfortable" work directly (it is small and the connections are not very accessible) so that I'm going to solder it on a little prototype board for convenience.

In this link you can find the prototype board for ESP-12 that I use. Ten plates cost less than € 1 and make my life a lot easier.

Also, the prototype board has room to put the few additional components you are going to need our circuit to work (a pair of resistors and my low power MCP1700 voltage regulator).

And to record the ESP8266?

Yes, recording a loose ESP8266 is much more complicated You have to record it on a NodeMCU board (that is precisely why those boards were invented, to simplify that work).

There are several ways to do it, here I am going to show you the one that works for me more comfortable and simple

Things have changed a lot in recent years. Long ago to record an ESP8266 there was no choice but to solder a few cables, make jumpers, put buttons, and use an FTDI (serial to USB converter). And when you already had the ESP8266 recorded, you had to disconnect everything to put the ESP8266 in its final place.

In my case, since I used to use the ESP8266 mounted on the white prototype boards that I have shown you before, I had prepared a small assembly with everything necessary in which pricked the prototype board for engraving.

Now to record the ESP8266 I use a plate like this and it simplifies my life a lot (purchase link: ESP8266 programmer on AliExpress):

Click on the image to buy it

This board is basically like a NodeMCU where the ESP8266 is snapped on, without need for soldering, by means of metal strips that make contact and hold it in place mechanically. Once recorded, you simply pull it up and take it out.

Fortunately, with ESP Easy, you only have to flash the ESP8266 once and from there you can update directly via Wi-Fi through the corresponding menu. Without a doubt, something very comfortable. This is called an "OTA update" ("Over The Air").

The Senseair Sunrise energy-saving CO2 sensor

As I was saying, I have written this article thinking about useful for any project with ESP8266 and ESP Easy, whatever it is, what you want to do, and it contains all the necessary information for it. But in this specific example, and which corresponds to the experiment I have done, it is about building a low consumption CO₂ meter and for this a low consumption CO₂ sensor is required.

Senseair Sunrise CO2 Sensor

For this experiment I used the Senseair Sunrise CO2 sensor (also known as Senseair S11).

It is a sensor that consumes on average only 38μA in the configuration in which I have done the experiment. Then I will tell you about some optimization options that I have not used in this experiment, and that I will develop in the following ones.

In addition, the low consumption of this sensor is not at odds with its precision, it's even more accurate than the regular Senseair S8.

The problem with this sensor is that, at the moment, it is not easy to find and buy. We are working on solutions so you can buy it easily and at an acceptable price. I hope to have news soon.

Maybe you are also interested in:  PeluCO₂: A CO₂ meter on your wrist (wearable)

If you want more information here is the Senseair Sunrise datasheet.

Can I use a CO2 sensor that is not energy efficient? Obviously, if you want to achieve results like these, no. You need a low consumption CO2 sensor.

However, I have some ideas to optimize the consumption of normal sensors and I will write an article with experiments about it.

The project outline

Well, now that I've told you about the hardware basics, the because S and all the other important things, I show you the «scheme physical»(Come on, I have not created a formal diagram, this is not a circuit assembly tutorial, it is an experiment), which is really simple (how many fewer components lower consumption, you already know).

In exchange I leave you a lot of montage photos with great detail of each part (click on each of them to see them in large size), as it has been working for the twelve days that the battery has lasted.

You should have no problem replicating it and I suggest as an exercise that you try to draw the scheme from these photographs, even if it is on a piece of paper. As you do this exercise you will learn a lot by finding out why I have done each thing.

You have doubts? Come by the Telegram group and ask…

If you have been an observer, in the diagram and in the photographs you will have seen two resistors, connected to the battery positive, of which I have not told you so far:

These two resistors form a resistive voltage divider and they serve so that ESP Easy can measure battery voltage and in this way know your load approximate.

If you pay attention, the graphs not only show the CO₂ measurement every minute but also the battery voltage.

You will see that there is a 10uF to GND capacitor at the power input to help the voltage regulator with the ESP consumption peaks and also a 100nF capacitor at the VCC pin to avoid high frequency noise.

By the way, the MCP1700 regulator is at the bottom of the board, so you won't see it.

Another thing you have to pay attention to is the jumper between the RESET pin and the GPIO-16 (a little black wire at the bottom of the plate). That bridge is necessary for the ESP8266 to get out of deep sleep, when it's time to wake up.

As additional information, note that the Senseair Sunrise sensor is connected directly to the battery, since its admissible supply voltage ranges from 3.05V to 5.5V. In this way we do not need to use a regulator, with its corresponding additional consumption.

In this experiment the sensor has been on and active all the time. In the next experiment the on and off of the sensor will be controlled by means of the ENABLE pin of the same so the ESP8266 will be able to turn the sensor on and off to keep it on for the shortest possible time and thus save battery.

The software for low consumption

This point is as important or more important than the hardware because, and it is where the magic resides, The best thing about this experiment is having done it with the standard ESP Easy, without complications or additional programming.

Of course Further optimization could have been achieved with custom built firmware, specifically for the low consumption CO₂ meter, but What has been achieved with ESP Easy, and only with ESP Easy, is already a giant step, and opens the doors to a universe of low-consumption projects within the reach of non-programmers..

The concept is very simple, once you know what to do:

Through some very simple rules by ESP Easy, the meter is normally asleep (in deep sleep state), each 60 seconds wake up and, for a few seconds in which you stay awake, reads the measurements of the Senseair Sunrise, connects to the Wi-Fi network, sends the measurements and goes back to sleep, waiting another sixty seconds.

I have also implemented another rule that allows you to check if there is a jumper connected between GPIO-4 pin (D2) and GND Y, if the bridge is connected, it does not go into deep sleep, staying awake.

This is very convenient when we want to access the configuration, for example, since we simply put the bridge, wait for the ESP8266 to come out of deep sleep (60 seconds maximum) and we already connect to it in the normal way, using a browser, since will not return to deep sleep state.

The operation of the rules is surprisingly simple:

ESPEasy starts in the normal way, as in any project.

When connecting to the MQTT broker the following rule is triggered:

On MQTT#Connected Do // when the broker is connected If [SleepEnable#State] = 1 publish, %sysname% / Sunrise / PPM, [Sunrise#PPM] // publish CO2 publish, %sysname% / Battery, [Battery#Volts] publish, %sys statusd "Publish%sysname / statusd%sysleep1" // publish information timerSet, 1,1 Else publish, %sysname% / status, "Deepsleep Disabled" // publish information EndIf EndOn

[SleepEnable#State] depends on the bridge that we have between the GPIO-4 pin (D2) and GND.

If the bridge is open (there is no connection between GPIO-4 (D2) and GND) [SleepEnable#State] is equal to 0 ([SleepEnable#State] = 0 is true), indicating that low power mode is activated Y:

  1. The three lines that send the data via MQTT to the broker are executed
  2. A timer is activated that will run within 1 second

After one second, timer number 1 is activated, executing the following lines:

On Rules#Timer = 1 Do deepsleep, 60 // go to deepsleep for 60 seconds (even if deepsleep value is not configured in the config menu) EndOn

All you do is put the ESP8266 on deep sleep mode for 60 seconds.

After 60 seconds ESPEasy starts again, connects to Wi-Fi and the MQTT broker and starts again (as at the beginning) with:

On MQTT#Connected Do // when the broker is connected If [SleepEnable#State] = 1 publish, %sysname% / Sunrise / PPM, [Sunrise#PPM] // publish CO2 publish, %sysname% / Battery, [Battery#Volts] publish, %sys statusd "Publish%sysname / statusd%sysleep1" // publish information timerSet, 1,1 Else publish, %sysname% / status, "Deepsleep Disabled" // publish information EndIf EndOn

Do not stop reading this article, when you finish with this one, to learn more about ESP8266 and deep sleep:

Experiment results

This first experiment has turned out to be a complete success.

In this graph (click on the image to see it larger) you can see how the meter has been collecting CO2 data every minute and sending it over Wi-Fi. You will also see the evolution of the battery voltage minute by minute:

The ESP-12F has worked well powered at 3.0V with a small detail, and it is that sometimes for very long transmissions (update firmware) I had to power the ESP-12E to 3.3V directly on its pins from the laboratory power supply.

Maybe you are also interested in:  How to control Milight from Rflink

I do not know if it is a problem with the specific unit of ESP-12F that I have used, since theoretically it should not have given me this problem. According to the ESP8266 datasheet, this chip is capable of powering itself between 2.5 V and 3.6 V.

A second explanation would be that the MCP1700 regulator (which according to the datasheet should be capable of delivering 250mA) is at the limit of its capacity. Probably the problem was solved with a major capacitor than the 10uF I have used. More tests will have to be done.

Optimizations and future experiments

As you can see, this experiment has been very simple and, even so, we have achieved 12 days of autonomy.

We could have gotten close to a month just by having it report CO2 measurements every three minutes instead of one (more than enough, in my opinion).

But, in addition, there are other things we can do and ideas that we can explore:

Sensor consumption optimization

In this experiment, we have kept the sensor working for the 12 days permanently.

One of the first optimizations I have to do is change this and have the sensor only work when necessary. It is something very simple since all we have to do is connect a pin of the sensor (the EN pin) to a pin of the ESP8266 and let ESP Easy control the on and off of the sensor to turn it on only when necessary.

Battery voltage measurement optimization

Due to the way in which the resistive divider is made to measure the battery voltage, that divider is consuming current, even if it is little, permanently. It is very little, since it supposes a resistance of 5.7MΩ between the positive of the battery and GND, but it could be avoided.

With the resistors used, and if I have not made a mistake in the calculations, the divider consumes a maximum of 7.37µA. This means that in the twelve days that the meter has been working, the consumption has been 7 days x 24 hours x 7.37µAh = 2.12mA (less than 0.1% of the battery capacity).

The first step would be increase the value of the resistors used, up to the limit that the impedance of the ADC pin allows, with this, these 7.37µAh that cross them permanently would decrease.

The next step would be to disconnect these resistors completely and only when the ESP8266 goes to measure the battery (once every hour, for example) connect them for an instant with a Mosfet transistor, disconnecting them again once the voltage measurement has been made. It is difficult to say if it is worth the effort, to save just over 2 mA.

Time optimization

In this experiment, time management was really basic. Sixty seconds in deep sleep and a few seconds on. We can optimize this much more.

For example, it is very possible that we can reduce the seconds that the ESP8266 is awake to do what it does and we can save a few seconds.

Optimization of operating modes

In this experiment we have used two modes of the ESP8266, the "active" mode and the "deep sleep" mode, but these are not the only ones. There are other modes of operation in which we can, for example, turn off the Wi-Fi (which is what consumes the most) and keep the rest working normally.

Interesting things to investigate, of course.

Strategy optimization

What if, even though we want to save data every 5 minutes, we only want it for historical purposes?

We would wake up the ESP8266 every five minutes, but only a few moments to take the measurement and save it temporarily, without turning on the Wi-Fi or connecting. Once every twelve on (which would be once an hour) we would turn on the Wi-Fi and send all the data together.

Wi-Fi optimization

Most of the consumption in this experiment is dedicated to Wi-Fi. Currently, when ESP Easy wakes up, after deep sleep, it has to connect to the Wi-Fi network and send its data via MQTT. This is time consuming, but can be optimized to reduce it.

It will be one of the next things I work on and the improvement in autonomy I hope is very appreciable.

Use of more energy efficient communications than Wi-Fi

Wi-Fi communications have many advantages, but they are great energy guzzlers. Long ago, Expressive, the maker of the ESP8266 and ESP32 chips, released a new protocol, called ESP-NOW, which promises much lower power consumption, by considerably reducing the time it takes for the microcontroller to perform a transmission.

Support for ESP-NOW on ESP Easy is on the way and this will allow a great improvement in autonomy. I wait impatiently to be able to carry out the first tests.

Meanwhile, a new way of work, without ESP Easy, which I will explore shortly.

What if we don't need to send data, just visualize it?

We could use an e-Ink or e-Paper (electronic ink) screen, which only consumes energy when what is displayed on the screen is updated, the rest of the time it has practically no consumption. In this way our battery could last for months (or years, who knows!).
Even with little consumption, if we wanted historical data, we could save it locally and send it only once a day, turning on the Wi-Fi for just a few seconds.

Here you can see a prototype that I have built, using a very low consumption sensor Cubic CM1106SL-NS and a 2.9 ″ e-Ink screen to test this technology. When I have it a little more "cooked" I will publish a full article about it. First I have to fix some problems and loose ends:


Leave a Comment