Battery powered CO₂ meter (well done)

In this tutorial I'm going to show you how to add a battery to any of your microcontroller-based projects, correctly, without danger.

The uses are endless and although I will use as an example the Home CO2 Meter, you can use it in any other project, be it based on Arduino, ESP8266, ESP32, or any other microcontroller.

There are few occasions when we would like use our CO2 meter with batteries (at least it happens to me often).

Even to calibrate it outdoors periodically, it suits me that they are autonomous.

So far I have used a powerbank, of those normally used for mobiles, for this purpose, but I thought it was time for a slightly more definitive, meter-integrated solution.

The project that I present here allows you to equip the CO2 meter with a rechargeable battery or to any other similar project, easily and for very little money.

Also, the end of this project it's not just riding it, otherwise to comment on some things along the way, very important for the hobbyist of gadget who wants to equip his drum sets. And is that, Have you noticed the "well done" in the title?

And what is this that is well done?

Putting a battery on a gadget that runs at 5V (or 3.3V for that matter) seems like one of the simplest things in the world, right?

I have a secret: This article is not just about telling you What "Ride" the battery, but teach you why it is important to do it a certain way, which is why it is so extensive (and trust me, it could be a lot more extensive if we went into much more detail).

I ask you a favor: Even if you think that this is very simple and that there is too much verbiage in this article for something so easy, please read the entire article (don't just go "to the montage"), you may already know everything, but , maybe, you will be surprised.

I think that by now everyone knows that Lithium Ion (Li-Ion) and Lithium Polymer (Lithium Polymer) batteries or «Lipo ») are delicate and they can even be dangerous. Surely many of you remember about the scooters that left burning alone on the street, not too long ago.

We live with these batteries and nothing usually happens, but that is because the vast majority of commercial devices that use them know their risks and manage them appropriately.

The danger does not come from the battery itself (well, a little yes) but, above all, from the use made of it.

The problem is usually that most of the «non-specialist people»Does not know (and it is logical, it does not have to know) what that of«the use made of it»And even less when they trust that if they take a battery and take a charger and plug them carefully, nothing bad can happen.


There is a type of use that is especially delicate and I'm sick of seeing projects with a design that puts your battery, your device and your house in danger.

This type of use is, above all, when you want to use the device and charge the battery at the same time.

Think about it, there are not so many devices that do that. We can think of phones and, that they are really extended, little more ...

We want the battery of our meter to be always charged, we want our device to work while the battery is charging. We don't want to have to turn the meter off for a few hours while the battery charges.

The commandments of Li-ion and Li-po batteries

These are the ten most important commandments +1 when working with Li-ion and Li-po batteries (and then others follow):

  1. Don't overcharge the battery
  2. Don't overcharge the battery
  3. Don't overcharge the battery
  4. Don't overcharge the battery
  5. Don't overcharge the battery
  6. Don't overcharge the battery
  7. Don't overcharge the battery
  8. Don't overcharge the battery
  9. Don't overcharge the battery
  10. Don't overcharge the battery
  11. Do not short circuits the battery (this is as important as the previous 10)
  12. Do not overloads battery below one point
  13. Don't let it be hot Battery
  14. Don't put batteries in parallel if they don't have the same load

They are not the only ones, but they are the ones you can do let your house go on fire more easily.

The sin of most projects

Most projects that are seen on the internet commit a serious mistake and I'm going to tell you what it is in a simple way so you can understand it quickly.

If you remember, the first ten commandments said: "Don't overcharge the battery". This means that, in the process of charging the battery, there is a certain point at which you have to stop loading it and do not go from there. Continuing to charge the battery after that point is dangerous.

As you can imagine, it follows from the previous paragraph that the process of charging a battery is very delicate and the chargers for Li-ion and Li-po batteries (contrary to what happens with lead, nickel-cadmium or nickel-metal batteries, which endure more mess) are very precise devices.

I am not going to explain in full detail how is the charging process of a Li-ion and Li-po battery (perhaps in another article) but I am going to give you the main lines of what a charger does:

Battery charging process with TP4056
  1. First the charger does security checks to make sure the battery is not connected backwards. That it is within a certain voltage range, etc.
  2. The charger then performs a "Pre conditioning", in which it checks, in a very controlled way and by supplying low currents, that the battery "absorbs" the current it is expected to absorb, that its voltage rises by giving it current, and so on.
  3. Begins the constant current charging, which takes almost the entire charging process. This means that the charger will change the voltage that it supplies to the battery as necessary, so that it is always absorbing the same intensity.
  4. When the charger detects that the battery is close to 4.2 volts, which marks its maximum voltage, begins to reduce current intensity that supplies the battery.
  5. When the current is less than a certain value, the charger stops charging. Is over.

Well, the problem is that in most projects, the last point is never reached and the battery charges, and charges, and charges ... until… until the battery lasts.

Have you noticed how many devices that run on battery have problems with it? Well, there you have a good reason.

And why doesn't it stop loading? Well, I'll also explain it to you below.

The usual and (very) poorly done feeding system

What they do in many (many) projects is the following:

We start from a project, which is powered normally at 5 volts.

The next thing would be to add a battery with its charger (a small board based on the integrated circuit TP4056, which works great and is capable of charging the battery with an accuracy of 1.5%), and it could be left connected always to maintain the permanently charged battery:

Sure, in the previous example we would have a charged battery but that battery would give us a voltage of between about 3 and 4.2 volts, depending on how charged it is, and we couldn't use it directly to power our circuit (which needs 3.3 or 5 volts to work).

What our clever designer does is connect, in parallel with the battery, a circuit called "step up down" (among other curious names), to which we can apply any voltage to the input (within limits that depend on the exact circuit that we use, say between 2.5 and 30 volts) and that at the output it will always give us a wonderful 3.3 or 5 stabilized volts:

But oh, our amateur designer notices after a short time (when the battery dies or disaster strikes, whatever happens before, but it will not take long), that there are things missing here for your circuit to work correctly and I can sleep peacefully at night.

  1. A protection against over discharge, because if you leave your device connected too long and the battery discharges below a point, the battery will die (some batteries have this built-in protection).
  2. A protection against short circuits, because, let's be serious, at any time (and more in an amateur circuit, which is what we are) a cable can play with another, and… magic smoke… (in the best of cases).
  3. Other protections that may not cause the assembly or the house to burn, but that it is convenient to have them.

So you go back to the layout board and change the simple charger you had used for a more complete charger, which includes the necessary protections (pay attention to the connections to the charger, they are very similar, but not the same: the previous one had only two terminals output and this has four terminals independent, two for the battery and another two for output):

At this point, our hobbyist designer has what he wanted. A power system that works with battery, that can charge the battery and power the device at the same time and that has the necessary protections ...

Try it and it works! and so happy he publishes it ...

But that design (so widely spread, Google it if you want and you'll see hundreds of them) hides a dark secret, a mortal sin that can put us in danger:


And why is this happening?

The key is in the first point of the TP4056 integrated circuit datasheet:

"The TP4056 automatically ends the charge cycle when the charge current drops to 1/10 of the programmed value after reaching the final float voltage."

This means that the TP4056 will stop charging the battery only when the final voltage has reached 4.2V and the charging current drops to one tenth of the programmed charging current.

By default, on most boards with the TP4056 (and others like it) the programmed load current is 1 Ampere (it can be modified by changing a resistance), which means that until there is no consumption less than 100mA the charging process will not be interrupted and as we have an additional circuit connected, «hanging from the charger«, The charger will be«confused»For that additional consumption and will never stop charging the battery.

And how do we do it right?

I guess I have your attention now.

Is it a topic that interests you? If at any time you are going to want to provide drums to any type of project, you should ...

Well, stay tuned for the update of the article with the solution. I will tell you how improve the above diagram to avoid the problems mentioned and I will teach you step by step and in detail (video tutorial included) my solution to add battery to the project, I tell you that it has nothing to do with what we have seen before.

Subscribe now to the newsletter and join the Telegram group and don't miss it.

Today is February 20 and I am mounting the video with the tutorial. I promise you that in a few days it will be ready. Hold!

2 thoughts on “Medidor de CO₂ con batería (bien hecho)”

  1. Well, we are looking forward to finishing the article, I already told you in the Telegram group that I would like to put a model airplane camera broadcasting at 5.8 Ghz and power it with a solar panel. We could use it very well to use it as a beacon and to do antenna tests.
    I admire your ability to communicate complex things in a simple way that all kinds of people can understand.
    Congratulations !

    • Hello Zulu.

      Yes, it's giving me a little more work than expected. I hope to finish it shortly, I don't have much left. Promised!

      Regards, and thank you very much. 😀


Leave a Comment