Measuring battery voltage

Hello,
I am powering my project with a 4 AA batteries which generates 4.8V and via voltage regulator I power with 3.3V a ESP32-S2 mini.
The board goes in deep sleep when not in use, and when it wakes up I would like to have the reading of the battery.
I have one analog pin (3.3V only tolerant) and I'm looking for a energy efficient way to measure (ie. only when the ESP is on). Solutions I have found so far vary from voltage divider/capacitors/mosfets, to complex circuits, or specific solutions for LiPo batteries.

Among all I have found the following diagram:
image

Would this work?

Would anyone suggest what to look for as alternative please?

dk

If it's a secret what sensor it is, its datasheet, no help from here.

You are right, edited the post accordingly.

Why not just two resistors, for the battery voltage attenuation and read that with ADC?

Look at using logic level mosfets.

Thanks.....

What values? How much current would that always draw, compared to the current drawn by the circuit on offer when both transistors are off?

Deep sleep requires ferret-like attention to every source of battery drain.

a7

The drawing isn't pretty, but I would look at this one.

A TP2104 should work for the P-channel.

How are you turning off the voltage regulator? That will discharge your batteries long before your voltage measuring circuit (which looks good to me).

1 Like

What I'm evaluating now is the following:
Use this board (GitHub - tstoegi/MicroWakeupper: All about the MicroWakeupper Library (and BatteryShield for the Wemos D1 Mini)) with the ESP. When an external triggers the MicroWakeupper the ESP turns on, does the necessary readings, and sends the values. Than it turns off (total switch off).
Use 4 normal AA batteries to power the MicroWakeupper and the ESP. The consumption for this should be very limited.
The last question is really how do I know when the batteries need to be replaced.
The ultimate goal is to have a sensor which can run independent for as much as possible, and find a way to be mindful of energy consumption.

I'm curious about roll of the unlabeled capacitor between D4 and the gate.

And I ask for a friend if this works with D4 coming from the 3.3 volt Arduino and a V+ of nominal 4.8 volts.

a7

The capacitor is there to protect D4 from the higher battery voltage. Normally D4 would be high at 3.3V. When you take D4 low to read the battery voltage, the gate voltage drops by 3.3V, not to ground. But that should be enough to turn on a logic level mosfet if its threshold voltage is 2V or less.

But of course the gate will immediately begin to recharge through the pullup resistor, so you can't waste time reading the battery voltage. Then when D4 goes back to 3.3V, the gate will be raised above battery voltage briefly, but that will equalize through the resistor.

The only time D4 will see more than 3.3V is very briefly when power is first applied to the circuit. But that's through the pullup resistor, so D4's protection diode should be able to easily deal with that.

The size of the capacitor depends on how quickly you can sample the battery voltage, but I suspect it could be quite small. I think I would start with 100nF, and test it by taking D4 low, then repeatedly doing ADC conversions, and see how many times you can do that before the result begins to drop. If you can do four or five times, that should give you plenty of leeway.

2 Likes

Hello ShermanP,

Looking at your design: when D4 is high, the mosfet is on, the current will flow, and voltage can be read with A0.
C1 can be 100nF, how do I calculate R1, R2, and R3 considering A0 is 3.3V tollerant?
Would the IRF9530 be ok as well instead of the TP2104?

What is the difference or the advantage compared to the design with the IRF530 and the IRF9530 in the first post please?

Clever. I prefer the first circuit, although the use of non-logic level MOSFETs catches me off guard.

Just because the circuit in #1 is more general purpose - does not need to rely on the robustness of the Arduino output pin and, I'm always being a bit slow, does not need me to be right there right away to do the reading.

And maybe because I unterstood it immediately. :expressionless:

Certainly if one was making a few thousand or a few thousand thousand of these, the simpler circuit would be a win.

THX!

a7

No. When D4 goes LOW, that turns on the mosfet, and you have a short time to do the ADC to read the battery voltage. Then you take D4 back high when you've finished, and the mosfet stays off until you're ready to check battery voltage again.

I would try 100K for R1. But you will have to experiment with values of C1 and R1 to make sure the mosfet stays on long enough to do the ADC after D4 goes low. It will depend on the gate capacitance of the mosfet, and its gate threshold voltage. So I don't know how to calculate it. If you get good readings with 100nF and 100K, that should be fine. If the readings are lower than they should be, a bigger capacitor might be needed.

As for the divider, you said in your original post that you have 4 AA batteries providing 4.8V. But if those are NiMH rechargeable batteries, 1.2V is just their nominal voltage. Fully charged they would be close to 1.5V each, which would give you 6V in total. So I think I would just make R2 and R3 the same, which would divide the battery voltage in half, and still keep you under 3.3V on the analog pin. Something like 47K for each would probably work.

No i don't think so. That mosfet can have a maximum gate threshold voltage of 4V, so a 3.3V drop from R4 might not even turn it on. You need a "logic level" P-channel mosfet. I don't know of one in that same TO220 package unless you can find an NDP6020P, but it has been discontinued. You need a mosfet with a maximum gate threshold voltage of 2V or less.

It just uses fewer parts. But I'm not sure your original circuit will work reliably with those mosfets as battery voltage drops. The gate threshold voltage is borderline on the IRF530 in particular.

I use these with an EZSP32 to shut off my resistors netowrks used in A:D.

FQP30N06L FQP30N06 30N06 30N06L N-Channel MOSFET

Make sure the part number has a N or its not the one you are looking for,

Ok, this means that is the ESP is most of the time off, D4 is LOW and the battery will drain for the time the ESP is off.. or this is wrong assumption?

Also what about this similar solution using a solid state relay, if I understand it correctly, when the D1 is LOW everything is disconnected, while it's HIGH I can measure the battery level with the A0 and the divider?
It might be exaggerated, but will it work or have any disadvantage or risks?

Yes.
Only a high to low transition on the pin turns the mosfet 'on' for a short time.
The time the mosfet is 'on' is set with the RC time constant of C1, R1.
The mosfet is 'off with a constant LOW or a constant HIGH on the pin.

Logic voltage of an ESP is 3.3volt, so the high to low jump is only 3.3volt.
That requires using a mosfet with a low Vgs(th).
The IRF9530 (and IRF530) can't be used with 3.3volt logic.
You likely will only find low Vgs(th) fets in an smd package.
The FDN340P (eBay) is such a fet (used as USB backflow protection on an Uno/Mega).
Leo..

Yes, except that for this purpose, RDSon doesn't matter, and very little current has to flow. So I think a TO92 device like the TP2104 would probably work fine. Threshold voltage isn't very low, but is probably low enough.

And in the two-mosfet circuit, the N-channel 2N7000/BS170 types should also work for the same reasons.