Experiments with ESPEasy (ESP8266) and low power - v1.0

Do you want to reduce consumption of your project with ESPEasy and an ESP8266 easily so you can run it on batteries for months on end? Read more.

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

In this first article, as well as explaining the experiment itself, I will give you all the background you need, which will be useful for the experiments I will explain in future articles and even for your own experiments.

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

What you will find are not techniques for winning autonomy competitions. (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 CO₂ meter with battery or battery operationwhich allows for a interesting autonomy (at least for a few weeks).

In the case of the CO2 meter, in which one of my objectives is that anyone, without previous knowledge, can build a quality CO2 meter easily and with certain guarantees of operation.this involves a number of challenges that require some compromising decisions (that are good enough, without having to be the best, but that are very easy to implement, and that on the balance of ease/result, the clear winner will be).

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

Unlike this article, the aim of this tutorial was to add battery power to the existing project, without setting new records in terms of autonomy. The aim was to equip the meter with battery for occasional use with sufficient autonomy for a day's worth of measurements (between eight and 24 hours, depending on the battery used).

In this case the project is very much more ambitious. The aim is to create a CO₂ meter with battery or battery only operation and with a significantly longer range. Twelve days of autonomy, in this first experiment, using a single 18650 Li-Ion battery.which is not bad for a first attempt.

When I was defining the project in my head, there were a number of objectives as a premise:

  1. That it was very easy to buildfrom a hardware point of view
  2. That it was very easy to program and configurefrom a software point of view
  3. Who had continuity with the work already done previously on this blog
  4. That it was very easy to solve questions and problems for users who choose 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 posting other experimentsThe new, more and more complete and optimised as you make them.

I would be delighted to hear the results of your own experiments.If you decide to do so, you can post them in the comments on the blog or on the eMariete Telegram groupas you prefer.

How do you make a circuit as energy efficient as possible?

Basically, optimising everything that can be optimised. The maxim is: Every µA counts.

This is like becoming a millionaire by saving pennies.

To optimise in this way, we have to choose the components that consume the least amount of energy. Optimise the time these components are on and the efficiency of getting things done.

All of this is important.

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

What about the weather? If we want to measure CO₂ every minute, for example, and it takes 1 second to do so, why have our circuit switched on for the remaining 59 seconds?

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

The hardware of the experiment

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

I love both boards for projects that are plugged into the mains, but for what we are going to do here they are no good.

An ESP8266 in deep sleep mode (sleeping, and waiting for for something to happenThe ESP8266 (the ESP8266 is used to wake up) 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 8-20mA. That is 500 to 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 (I'm too lazy to calculate the autonomy, I'll do it).

And why is this?

Simple, because the NodeMCU has, in addition to the ESP8266 several things that are very time consuming and that, to make matters worse, we do not need.

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

Here we have two options:

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

In this test, I have used an MCP1700 controller which has a consumption "doing nothing". 1.5µA (3333 times less than AMS1117!)The ESP8266's power consumption is almost negligible, because it's less than an additional 1% on top of the 20µA consumed by the ESP8266 (remember the maximum, every µA counts), but it's a very good drop.

We could avoid those 1.5µA by powering the ESP8266. directly from a batterybut this presents other problems, which would complicate this projectfor very little benefit. For that reason I dismiss it (maybe one day I will experiment with it).

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

This allows me to squeeze more out of the battery, as it I can download it 0.3V more and it works perfectly well because it is within the operating range of the ESP8266 (if you look at the graph below, you will see that it has been working until the 2.91V approximatelyI didn't waste much time calibrating the voltage divider).

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

Another very consuming element is the USB-to-serial converter chip.

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

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

Why do I want a USB to serial converter in my CO2 meter? Let me tell you: absolutely not at all. So, I'm going to do without it and I'm going to stay that way.

Of course, we no longer have a USB port, so we'll have to figure out how we're going to get it to work. connect to the computer to record it (more on this later).

And then?

Well, what I'm going to use is an ESP8266. "almost peeled".directly. I am 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, which is placed on a small board with terminals to connect it, the antenna (remember that as it is wifi it needs an antenna, although we don't think about it often because it is integrated in the board and we hardly see it) and some minimum components for the ESP8266 to work (some capacitors and resistors). Nothing more.

The ESP-12F is a module with which it is somewhat "uncomfortable". work directly (it is small and the connections are not easily accessible) so that I will solder it onto a small prototyping board. for convenience.

In this link you can find the prototype board for ESP-12 I use. Ten plates cost less than €1 and make my life so much simpler.

In addition, the prototyping board has space to put the few additional components that our circuit will need to work (a couple of resistors and my low-power MCP1700 voltage regulator).

What about recording the ESP8266?

Yes, taping a single ESP8266 is much more complicated than writing it to a NodeMCU board (that's precisely why these boards were invented, to simplify this task).

There are several ways to do it, but here I am going to show you the one that works for me. more convenient and simpler

Things have changed a lot in the last few years. Once upon a time, to engrave an ESP8266 you had to solder a few wires, make jumpers, put pushbuttons, and use an FTDI (serial to USB converter). And when you had the ESP8266 engraved you had to disconnect everything to put the ESP8266 in its final place.

In my case, as I used to use the ESP8266 mounted on the white prototyping boards that I showed you before, I had prepared a small assembly with everything I needed in which I would pinned the prototype plate for engraving.

Now to record the ESP8266 I use a board like this one and it makes my life so much simpler (purchase link: ESP8266 programmer on AliExpress):

Click on the image to buy it

This board is basically like a NodeMCU on which the ESP8266 is put under pressure, without the need for weldingThe engraving is done by means of metal strips that make contact and hold it in place mechanically. Once engraved, you simply pull it out.

Fortunately, with ESP Easy, you only have to flash the ESP8266 once and from then on you can update it directly via wifi through the corresponding menu. This is very convenient. This is called "OTA update" ("Over The Air").

The energy-saving CO2 sensor Senseair Sunrise

As I said, I have written this article with you in mind. that you will find it useful for any ESP8266 and ESP Easy project.whatever it is you want to do, and it contains all the information you need to do it. But in this particular example, which corresponds to the experiment I have done, it is about building an energy-efficient CO₂ meter, and for this purpose a low-energy 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 average consumption as low as 38μA in the configuration in which I have done the experiment. Then I will tell you about some optimisation options that I did not use in this experiment, and that I will develop in the following ones.

Moreover, the low power consumption of this sensor is not at odds with its accuracy, is 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 that you can buy it easily and at an acceptable price. I look forward to hearing from you soon.

If you want more information here you have the datasheet of the Senseair Sunrise.

Is it possible to use a CO2 sensor that is not energy efficient? Obviously, if you want to achieve results like these, no. You need an energy-efficient CO2 sensor.

However, I have some ideas for optimising the consumption of normal sensors and I will write an article with experiments on the subject.

The outline of the project

Well, now that I've told you the basics about the hardware, the why and all the other important things, I show you the "outline physical"(I haven't created a formal schematic, this is not a circuit assembly tutorial, it's an experiment), which is really simple (the fewer components lower consumptionyou know).

In exchange I leave you a lot of photographs of the assembly with great detail of each part (click on each of them to see them in a larger size), as it has been working during the twelve days of battery life.

You should have no problem replicating it and as an exercise, I suggest that you try to draw a diagram from these photographs, even on a piece of paper.. While doing this exercise you will learn a lot by finding out why I have done what I have done.

Do you have any doubts? Visit the Telegram group and asks...

If you have been observant, you will have seen in the diagram and in the photographs two resistors, connected to the positive of the batteryI have not told you about so far:

These two resistors form a resistive voltage divider and serve to enable ESP Easy to measuring the battery voltage and thus know their cargo approximate.

If you look, The graphs show not only the CO₂ measurement per minute but also the battery voltage..

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

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

Another thing you have to look out for is the jumper between the RESET pin and GPIO-16 (a little black wire at the bottom of the board). That jumper is required for the ESP8266 to come out of deep sleep statewhen it is time to wake up.

As an added bonus, note that the Senseair Sunrise sensor is connected directly to the battery, as its permissible supply voltage ranges from 3.05V to 5.5V. This means we do not need to use a regulator, with its corresponding additional power consumption.

In this experiment the sensor has been on and active at all times. In the next experiment, the switching on and off of the sensor will be controlled by the pin ENABLE the ESP8266 will be able to turn the sensor on and off in order to maintain the sensor's on for as little time as possible and thus save battery life..

Low power software

This point is as important or more important than the hardware because it is where the magic lies, The best thing about this experiment is that it was carried out with the standard ESP Easy, without any complications or additional programming.

Of course further optimisation could have been achieved with custom-built firmware.specifically for the energy-efficient CO₂ meter, but what has been achieved with ESP Easy, and only with ESP Easy, is already a giant step forward, and opens the door to a universe of low-power projects within the reach of non-programmer users..

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

By means of a very simple rules of ESP Easy, the ESP Easy is normally asleep (in deep sleep), each 60 seconds wakes up and, for a few seconds during which he stays awake, reads the measurements from the Senseair Sunrise, connects to the wifi 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 the GPIO-4 pin (D2) and GND y, if the bridge is connected, does not enter deep sleepstaying awake.

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

The way the rules work is surprisingly simple:

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

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

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 CO2
  publish,%sysname%/status, "Deepsleep Enabled" //publish information
  timerSet,1,1
 Else
  publish,%sysname%/status, "Deepsleep Disabled" //publish information
 EndIf
EndOn

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

If the bridge is open (no connection between GPIO-4 (D2) and GND) [SleepEnable#State] is equal to 0 (SleepEnable#State]=0 is satisfied), 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 and will be executed within 1 second.

After one second, timer number 1 is activated and the following lines are executed:

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 it does is to set the ESP8266 to deep sleep mode for 60 seconds.

After 60 seconds ESPEasy starts again, connects to the wifi and the MQTT broker and starts again (same 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 CO2
  publish,%sysname%/status, "Deepsleep Enabled" //publish information
  timerSet,1,1
 Else
  publish,%sysname%/status, "Deepsleep Disabled" //publish information
 EndIf
EndOn

Be sure to read this article, when you're done with this one, to learn more about ESP8266 and deep sleep:

Results of the experiment

This first experiment has proved to be a success.

In this graph (click on the image to see it bigger) you can see how the meter has been collecting CO2 data every minute and sending it via wifi. You will also see the battery voltage evolution minute by minute:


The ESP-12F has worked well on 3.0V power with one small issue, and that is that at times 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.

I don't know if this is a problem with the particular ESP-12F unit I used, as 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. The problem would probably be solved with a larger capacitor than the 10uF I used. More tests will have to be done.

Optimisations and future experiments

As you can see, this experiment was very simple and we still managed to achieve 12 days of autonomy.

We could have achieved about a month by simply having it report CO2 measurements every three minutes instead of one (more than enough, in my opinion).

But there are also other things we can do and ideas we can explore:

Optimisation of sensor consumption

In this experiment, we have kept the sensor running during the 12 days on a permanent basis.

One of the first optimisations I need to do is to change this so that the sensor only works when it is needed. It is very simple as all we have to do is connect one pin of the sensor (the EN pin) to one pin of the ESP8266 and let ESP Easy control the on/off of the sensor to turn it on only when it is needed.

Optimisation of battery voltage measurement

Because of the way the resistive divider is made to measure the battery voltage, this divider is consuming current, however little, permanently. It is very little, since it means a resistance of 5.7MΩ between the battery positive and GND, but it could be avoided.

With the resistors used, and if I have not made a mistake in my calculations, the splitter consumes a maximum of 7,37µA. This means that in the twelve days the meter has been running 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 to increase the value of the resistors usedThe ADC pin impedance would be as high as the impedance of the ADC pin allows, so that the 7.37µAh that passes through it permanently would be lowered.

The next step would be to disconnect these resistors completely and only when the ESP8266 is going to measure the battery (once every hour, for example). connect them for a short time with a Mosfet transistorThe voltage measurement is made by disconnecting them again after the voltage measurement. It is difficult to say whether it is worth the effort, to save just over 2 mA.

Time optimisation

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

For example, it is quite possible that we can reduce the number of seconds that the ESP8266 is awake to do what it does and we can save some seconds.

Optimisation 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 wifi (which consumes the most power) and keep everything else running normally.

Certainly interesting things to investigate.

Optimising the strategy

What if, even if 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 for a few moments to take the measurement and store it temporarily, without turning on the wifi or connecting. Once every twelve wakes (which would be once every hour) we would turn on the wifi and send all the data together.

Wifi optimisation

Most of the consumption in this experiment is dedicated to wifi. Currently, when ESP Easy wakes up after deep sleep, it has to connect to the wifi network and send its data via MQTT. This takes quite some time, but can be optimised to reduce it.

It will be one of the next things I work on and the improvement in autonomy will hopefully be very noticeable.

Use of more energy-efficient communications than wifi

Wi-Fi communications have many advantages, but they are big energy guzzlers. Some time ago, Expressive, the manufacturer of the ESP8266 and ESP32 chips, came out with a new protocol, called ESP-NOWwhich promises much lower power consumption by significantly reducing the time it takes for the microcontroller to transmit.

Support for ESP-NOW in ESP Easy is on the way and this will allow a great improvement in autonomy. I am looking forward to the first tests.

In the meantime, a new way of working, without ESP Easy, which I will explore shortly.

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

We could use an e-Ink or e-Paper (electronic ink) screen, which only consumes energy when the display 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 low power consumption, if we wanted historical data, we could save it locally and send it only once a day by turning on the wifi for just a few seconds.

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

DID YOU FIND IT INTERESTING?
DON'T MISS OUT ON FUTURE EXPERIMENTS!
SUBSCRIBE TO THE NEWSLETTER AND JOIN THE TELEGRAM GROUP AND DON'T MISS ANY OF THE BEST.

3 thoughts on “Experimentos con ESPEasy (ESP8266) y bajo consumo – v1.0”

  1. Thank you for your article.
    Is it possible to make deepsleep dependent on degree of battery charge? For example:
    On Rules#Timer = 1 Do deepsleep, (60 / (VBattery / 4,2V))
    It could be useful in solar + battery powered devices.

    Reply
  2. Just read through the article and it is well written and very informative.
    Thanks for also introducing ESPEasy to explain why and how you did configure it to get low power usage.

    Reply

Leave a comment