Calculate capacity of battery used as power supply for NodeMCU board

Hello everyone, I'm sorry if this is posted in the wrong section, so many to choose from and I'm totally new here :frowning: .

I have a question regarding my project involving a NodeMCU 1.0 that I'm programming with Arduino IDE.
So far my project is hooked up in this way (the battery i'm using is a Ni-Mh):

My question is fairly simple and can be summarized as follows: "what's my best option to calculate the battery percentage?"
I skimmed this and other forums/pages before posting and (as a programmer approaching electronics for almost the first time) I understand i can achieve a solution in different ways:

  • A voltage divider was the first and most recommended, although i don't understand how to connect it into my project configured this way.

  • Calculating the remaining battery life based on (capacity of the battery / total consumption) , but this method seems by far the worst solution for my project as i cannot calculate time in a reliable way (I expect the battery to completely drain at some point and slowly recharge over solar panels) and it involves too many variables.

  • I read about an internal voltmeter on the Arduino boards and i found a piece of code to calculate the voltage using it but i don't think it applies to my board (I'm trying to understand the schematics but as a first-timer they look disorienting).

  • Not really posted somewhere but i pieced together that my motor driver uses a 78M05 voltage regulator to step down the 12v input to 5V there's anyway it comes in handy?

I understand that the output voltage of the battery won't be a precise measurement of its capacity. Just an indication of like 3 phases (100%-50%-25%) would be perfect for me.

I'm very sorry for any cringe-misunderstood information i might have posted, thanks for all and any help that might come! :slight_smile:

You are way overcomplicating this. Batteries are rated in Amp-Hours with a derating curve for amperage. First, measure what your circuit draws in Amps. Next, figure out your duty cycle. If your duty cycle is continuous, a battery may not be the right solution. Take a laptop, for example. Say it draws 1 Amp and is expected to last 8 hours between charges. If the battery for the laptop is rated for 8 Amp-Hours at 1 Amp draw, it will last 8 nominal hours from 100% capacity to 0% capacity.

Please do not simplify the Battery discharge characteristic.
With the ni-cad, gell cell, lead acid and probably many of the
newer types, the capacity is based on a 20 Hour
discharge rate at a given temperature. So if you drain
the battery faster than that, it will not power your load
for as long as you calculate that it will.
Herb

Perehama:
You are way overcomplicating this. .... Take a laptop, for example. Say it draws 1 Amp and is expected to last 8 hours between charges. If the battery for the laptop is rated for 8 Amp-Hours at 1 Amp draw, it will last 8 nominal hours from 100% capacity to 0% capacity.

I don't think he is over complicating this - he has a solar panel connected.

Take your example, and connect the laptop to a solar charger. Give it an unknown amount of light over an unknown amount of time. How long does the laptop last now?

ykarus117 sorry I don't know the answer, but a voltage divider and the ESP8266's ADC would probably work. Someone more electronics-y should be able to advise you.

Unfortunately the voltage of an NiMH battery, particularly when it may be under load and/or being charged, is a very poor indication of the charge level. The discharge characteristic is such that most NiMH cells drop rapidly from about 1.4V to roughly 1.2V where it remains for about 85% of the charge and then the voltage drops rapidly again and at roughly 1V it is empty.

Steve

I designed a sun meter for a client once. I found a cheap battery powered clock. I added a light sensor and a level detector and calibrated the threshold for direct sunlight. If a cloud blocked the sun, the output of the solar cell would drop below the threshold and trigger the compartor which would in turn trigger a
transistor which would disconnect power from the clock. Start the clock at 12 and if it reads 4 at 6pm then there was 4 hours of direct sunlight. It worked perfectly. In your case I think it would be simpler to just monitor the battery voltage.

As already stated :

Let battery = 1000mAh
Let load = 500mA

battery life = 1000mAh/500mA = 2 hours.

Let load = 2000mA

battery life = 1000mAh/2000mA = 0.5 hours.

Thus, you can use an analog input to measure the battery voltage (use a voltage divider for batteries >5V) and when the voltage drops below the minimum , turn on a piezo beeper beeping at 2/Hz and
turn on a red flashing light. More sophisticated systems have two batteries and a relay to switch the batteries over to a charger so each battery can be connected to a charger or to a load and the common
contact of the relay is the battery and N.C. is the load and N.O. is the charger. The two relays have
reverse logic. If relay A is ON, relay B is OFF and vice versa. Both relay always switch at the same time
so one battery is always being connected to the load and the other battery is being disconnected (and connected to the charger). The same charger goes to both relays. The arduino monitors both batteries at all times and has a charging flag for each battery. In order to get an accurate reading you also need a N.C. SPST relay to disconnect the battery from the relay so the arduino can measure the voltage with nothing connected. The two SPST relays are only energized for 500mS to measure the voltage and then de-energized (since they are N.C. relays, this reconnects the battery to the main switching relay.

Since you did not post any data for the solar power you can do those calculations yourself.
(how many hours of direct sunlight to charge a battery).

herbschwarz:
Please do not simplify the Battery discharge characteristic.
With the ni-cad, gell cell, lead acid and probably many of the
newer types...

This is the derating curve I was referring to on the datasheet. The different chemistry of the battery will affect the current available. Some battery materials, like Lithium-polymer, are very flexible on current, while others, like lead-acid or gell-cell, are constructed in a way that can favor current over capacity or capacity over current. Some battery materials are rather inflexible and the only way to get more current is to get more batteries in parallel.

rstro:
I don't think he is over complicating this - he has a solar panel connected.

Take your example, and connect the laptop to a solar charger. Give it an unknown amount of light over an unknown amount of time. How long does the laptop last now?

8-hours nominally from 100% to 0%. I don't see a solar panel connected in the diagram, but if there is one, and everything is unkown, all we know is the laptop need 8 amp hours to last 8 hours. But if we know duty cycle for the nodeMCU circuit we could determine if solar power is a thing to consider. A shed light will have such an infrequent duty cycle that the solar is mostly topping off the battery in between the off chance that we go get something from the shed on a given day after dark... A little league baseball scoreboard will get a heavy use on Saturday and charge most of the week. A refrigerator, or freezer unit might have an on period of 10 minutes every 60 minutes, plus 10 after each time the fridge is accessed. Each one of these situations is suitable for solar power, and can have a circuit designed for it, as long as the relevant details are known.

Thanks everyone for their input i really appreciate it! I think i will implement two solutions (a voltage divider and the solution suggest by @Perehama).

raschemmel:
More sophisticated systems have two batteries and a relay to switch the batteries over to a charger so each battery can be connected to a charger or to a load and the common
contact of the relay is the battery and N.C. is the load and N.O. is the charger. The two relays have
reverse logic. If relay A is ON, relay B is OFF and vice versa. Both relay always switch at the same time
so one battery is always being connected to the load and the other battery is being disconnected (and connected to the charger). The same charger goes to both relays. The arduino monitors both batteries at all times and has a charging flag for each battery. In order to get an accurate reading you also need a N.C. SPST relay to disconnect the battery from the relay so the arduino can measure the voltage with nothing connected. The two SPST relays are only energized for 500mS to measure the voltage and then de-energized (since they are N.C. relays, this reconnects the battery to the main switching relay.

I really like the idea, although a little overkill for me now. I'll save it somewhere for some future iteration, thanks mate! :smiley:

I see that what I am telling you is not being understood.
When the battery manufacturer states the AmpHour capacity
of a battery, that means that the battery will supply
that AmpHour capacity when discharged over a 20 hour
test period at the specified temperature. The battery
capacity is called C, so the discharge rate is C/20.
Bringing that down to earth means that a 2000mAH battery
should be discharged at 100mA max. If you draw more than
100mA from it, it is not guaranteed to deliver 2000mAH.
I am not an expert in battery chemistry so all I can say
is that drawing higher current leads to more I squared R
heat and increased chemical activity and those lower the
battery efficiency. So, a battery rated at 8AH being
discharged at 1 Amp will not last 8 hours as you suppose.
After all, you are working it 2.5 times harder than it
is spec'd for.
Herb

That's precisely why Nimh have been replaced by Lipo and lithium-ion.

Nominal battery capacity is for brand new unused batteries in ideal conditions, if you calculate you need a minimum of 5Ah, the last thing to get is a 5Ah battery pack, 10Ah is much more reasonable value to go for,
so that you have plenty of headroom for battery aging, temperature change, different rates of discharge, etc.

Over-discharging any battery will pretty much ruin it, that's the most important thing to guard against, another
reason to be very conservative in rating the capacity.