battery level sensing in battery powered low current project - Page 1
Forum section: electronics / beginners

author: gardner
author_rank: Regular Contributor
timestamp: January 31, 2025, 01:48:17 am
content: Lily the cat has an electronic cat door. It runs off 4xAA batteries and reads her RFID chip to recognise her and unlock her door. I want to extend her cat door functionality a bit, so that it reports the battery level and actual unlock events via 433Mhz radios back to my home computer. I have cooked up a planned circuit and am looking for thoughts on my approach to sensing the battery level and potential pitfalls for unplanned current drains.Please excuse the crudity of my drawing -- I did not have time to draw it to scale or paint it.The battery sensing part, I want to explain what I have in mind. TheATTINY185ATTiny85 can use VCC as a Vref to measure the actual battery level via the voltage divider R5 and R6. The ground level of the divider is connected to PB2 on the CPU. I would let that be high impedance -- and input -- except when a battery reading is needed, when PB2 would be driven low, drawing ~500uA through R4, ensuring the voltage regulator was operating in an accurate current range. Normally the circuit would be sleeping and draw almost no current and the voltage regulator might be more sensitive to noise with almost no load.Questions are:Is placing a (low) load on the regulator and battery actually normal practice for making a voltage/state-of-charge reading? I've ballparked 500uA as a good "stablisation load", is that enough/too much current?When the pins ADC0 and PB2 are tri-stated, there is still a ~9uA current through the divider and through the protection diodes of the MCU and ultimately onto the 3.3V VCC, bypassing the regulator. Is that going to be a big deal?

author: Smokey
author_rank: Super Contributor
timestamp: January 31, 2025, 03:04:55 am
content: The "best" battery soc method of coulomb counting.If you have to use voltage, expect a wide error margin. You need to also characterize the battery at the same discharge rates as you will be operating when you take the voltage measurement.

author: Peabody
author_rank: Super Contributor
timestamp: January 31, 2025, 03:12:08 am
content: I don't know about the 185, but the ATtiny85 can read the battery voltage directly, with no divider, and no current draw. If the 85 is powered directly from the battery, with no regulator, it can use the constant 1.1V bandgap as the source being measured, with respect to Vcc (the battery). The logic is a bit backward, so the higher the analog reading, the lower the battery voltage. And you would have to calibrate it because the 1.1V varies chip to chip.But if you want to use a divider, as long as you have the capacitor, I think you can go pretty high on the resistors - 1Meg or so - and still get valid results.Or you can go super fancy, and use something like the circuit below.

author: ledtester
author_rank: Super Contributor
timestamp: January 31, 2025, 03:14:34 am
content: Why is the low end of your divider PB2 and not GND?A continuous drain of a few uAs is not a problem for the battery pack.A good indication of the battery health would be its voltage while the motor is running.I'm not sure about the 500uA load... note that the MCU will be running and therefore drawing some current itself anyway.A previous thread on monitoring battery voltage with an MCU:https://www.eevblog.com/forum/projects/battery-monitoring-voltage-divider/Quote from: Peabody on January 31, 2025, 03:12:08 amIn this case the MCU is powered from the door sensor's 4-cell battery pack.

author: gardner
author_rank: Regular Contributor
timestamp: January 31, 2025, 03:29:06 am
content: Quote from: Peabody on January 31, 2025, 03:12:08 amMy mistake -- it is an ATTiny85.The battery voltage is nominal 6V, up to almost 7V with fresh alkalines which is too high for the ATTiny -- absolute maximum 5.5V Vcc. So I need a regulator and if I have that, it is going to be a way better reference than the crappy one in the chip. I have had tons of trouble getting useful readings using the backwards measure-the-bandgap-with-Vcc-as-reference method. I have never gotten a calibration that was satisfactory over time, battery level and temperature.

author: gardner
author_rank: Regular Contributor
timestamp: January 31, 2025, 03:45:44 am
content: Quote from: ledtester on January 31, 2025, 03:14:34 amWell, the idea is that PB2 can be driven to ground when a reading is needed, and left tri-stated otherwise, so that no current need flow through the divider (or the voltage reference either).I agree that measuring the voltage while the motor is operating is probably my best bet, and I think I will have a crack at timing the measurement to those events. Within the cat door itself, I think the largest current draw is actually the RFID reader -- which only runs in response to an IR photo sensor event. Unfortunately I wasn't able to tease out any logic lines associated with that. The cat-door's MCU appears to be implementing the whole RFID system in software with a few driver transistors. What I really want to know is when the latch is triggered, and I can get that info by tapping into the outputs of the H-bridge that drives the motor.While my MCU will be running, an ATTiny is not a significant load, and the load of only the MCU is going to be especially low whilst doing the ADC measurement.I'll have a read of the referenced thread. Thanks.

author: Peabody
author_rank: Super Contributor
timestamp: January 31, 2025, 05:36:28 am
content: Quote from: gardner on January 31, 2025, 03:45:44 amRemember that there is a protection diode going from the GPIO pin to Vcc. So it will not be tristate. It will be sinking current from the 6.8V battery to the 3.3V rail all the time, no matter how the pin is configured. Well I guess the bottom of the divider will be ok, but the analog pin in the middle will sink current.

author: gardner
author_rank: Regular Contributor
timestamp: January 31, 2025, 08:21:48 pm
content: Quote from: Peabody on January 31, 2025, 05:36:28 amYes. My original post pointed this out. My question is -- is that a problem, do we think?If I keep the divider at ~720K, the voltage difference is 7V - 3.3V - 0.4V diode drop ~= 3.4V / 720K -- about 4.7uA onto the 3.3V railThe regulator I'm thinking of has a quiescent current in the 50uA range. Maybe the 4.7uA bypassing the regulator would offset that, or make it just act weird, possibly drawing more.If I just run the divider down to ground, then it will suck up 7V / 720K = ~10uA continuously, bringing the continuous load up to 60uA -- still mostly the regulator. The ATTiny will be powered down nearly all the time, drawing <1uA.

author: ledtester
author_rank: Super Contributor
timestamp: January 31, 2025, 09:21:10 pm
content: Are you taking into account the quiescent current of your LDO and the 433MHz radio?I just tested a 433 MHz transmitter I got on Amazon and it consumes 4mA even when not transmitting.If the MCU only wakes up when the motor is running you might want to look into a latch circuit which turns on power to the entire application. There was a recent discussion of one such circuit here:https://www.eevblog.com/forum/beginners/polarized-capacitor-could-be-charged-either-way/but there are lots of others tuned for different constraints and goals.

author: Peabody
author_rank: Super Contributor
timestamp: January 31, 2025, 10:13:48 pm
content: Quote from: gardner on January 31, 2025, 08:21:48 pmSo your point is that the current flowing into the 3.3V rail isn't wasted at all so long as the normal current there is more than that. The regulator will just supply less current than it normally would. And I guess that sounds right to me. Your circuit has to stay on all the time anyway to do the RFID thing, I assume, or at least part of the circuit.

author: gardner
author_rank: Regular Contributor
timestamp: February 24, 2025, 05:41:27 pm
content: The part I picked out for the voltage regulator wound up being an MCP1700 which I had on hand. These are designed for battery applications and have super low quiescent current in the 10uA range. While nothing terrible happened when I sunk the battery level divider through PB2 of the ATtiny85, it did not improve the overall idle current draw, so I wound up just sinking it to the ground.The MCP1700 has an absolute maximum input of 6.0V which seems odd for battery applications. 6V nominal is almost 7 with fresh alkalines. With LiIons it's going to be 4.2V or 8.4V. 6V is a weird engineering limit, especially for the 5V version. Anyhow, the part seems to work properly with no excess current draw with an input of 6.8V and I inserted a diode drop to bring that down closer to it's happy place.The radio I'm using prefers a higher supply voltage so I have it running from the 6V rail. It's currently plumbed in after the diode drop, for no particular reason. It has no measurable quiescent current draw but has a start-up time of ~100uS which I compensate for in software. I suppose as the supply voltage for the radio rises, likely the logic threshold on its data pin rises, so this might be something to look out for. These radios are so simple and cheap, but the cheap ones are barely documented and are such trouble to try to characterize. Well characterized ones are around (eg Linx ones) but are too expensive for this sort of gizmo. It's either $0.80 for the mystery parts or $20 for a Linx TXM-433 with full datasheet and all the bells and whistles. It's a shame there is no happy medium.I found that R3 was sinking too much current onto the 3.3V rail when the cat door motor was energized so I upped that quite a bit to 100K and I added a small capacitance to help filter noise. In operation this is working alright. The current pulse on the motor is 300ms so I have a software filter to eliminate spurious noise also. It turned out to be easy to time battery sense measurements to these motor current pulses, so I can get an idea of both open circuit and full load battery voltage. This will be useful going forward.I have the whole thing built up on a breadboard now and it's working alright while I iron out the receiving software. In a few days I will build it onto a proto board.

author: mikerj
author_rank: Super Contributor
timestamp: February 24, 2025, 06:47:51 pm
content: Why not measure battery voltage during the unlock event when it's loaded with the motor?

author: Langdon
author_rank: Frequent Contributor
timestamp: February 25, 2025, 02:21:28 pm
content: Would these be useful:https://www.taydaelectronics.com/xh-m604-lithium-battery-charge-control-module-dc-6-60v.htmlhttps://www.taydaelectronics.com/xh-m609-charger-battery-module-dc-12-36v.html

author: Peabody
author_rank: Super Contributor
timestamp: February 25, 2025, 03:03:28 pm
content: How different would all this look if you used three cells instead of four? Would the radio and other stuff not work at the lower voltage?Also, while not relevant to the original question, I'm curious why you are using an 8MHz crystal. Is the 8MHz internal oscillator not accurate enough?The HT7333-A would be an alternative to the LDO. Input up to 12V, with similar specs otherwise.

author: Langdon
author_rank: Frequent Contributor
timestamp: February 25, 2025, 03:34:23 pm
content: For the regulator, use a L7805 with 2 ceramic bypass caps or you can use this to attain slightly higher efficiency:https://www.taydaelectronics.com/dc-dc-adjustable-step-down-xl4005-module.htmlNo heatsink needed at all.Every time the door is moved, check the battery voltage.It might bmake sense to just bury some low-voltage 18AWG wire and use it to power the MCU and motors with a 5Vcharger or something.

author: gardner
author_rank: Regular Contributor
timestamp: February 25, 2025, 05:44:03 pm
content: Quote from: Peabody on February 25, 2025, 03:03:28 pmThe cat door itself is a commercial product (https://www.surepetcare.com/en-gb/pet-doors/microchip-cat-flap) that is designed to operate off 4xAA cells. The docs specify Alkalines, and not NiMH nor Lithium. I don't know if there is any actual sensitivity to the higher or lower voltage range of those other chemistries, but it is what it is. I want my monitor to run off the battery of the cat door as well as to monitor the battery level, and this means running off 6V nominal. I am married to ATtiny MCUs which have absolute max of 5.5V supply, so with 4xAA I need a regulator.If the cat door ran off 3xAAs, I could run the whole thing without a regulator. I have put together numerous battery powered radio sensors and do exactly that.I showed a crystal because my experience with the internal oscillator is that it is too influenced by temperature to provide accurate enough signal timing on the radio transmissions for a sufficiently reliable data link. There's no good reason the Virtual Wire OOK protocol is as sensitive as it is to exact timing, but it seems to be the case. I added timing offsets to my transmitter implementation to adjust for radio turn on and overall timing, but those can only be characterized for the electronics once and subsequent voltage or temperature induced drift is what it is. As it happens, I have the breadboard version running with the internal oscillator and it does work.The HT7333-A looks good. I just happened to have the MCP1700 on hand.EDIT: I can't seem to find the HT7xx parts on Mouser -- looks like they don't handle Holtek -- but I did see the MCP1702 with similar impossibly low quiescent current (5uA) and a much more generous 13.2V input max.

author: Langdon
author_rank: Frequent Contributor
timestamp: February 25, 2025, 08:58:07 pm
content: Hold up.Why not just solder a wire to the tab connecting to the 3rd battery to give you 4.5VDC to work with?

author: ledtester
author_rank: Super Contributor
timestamp: February 25, 2025, 09:43:28 pm
content: Quote from: Langdon on February 25, 2025, 08:58:07 pmCould work in this case but in general it drains the batteries unevenly reducing the life of the battery pack since some will get depleted before the others.

author: gardner
author_rank: Regular Contributor
timestamp: February 26, 2025, 02:38:20 am
content: Quote from: Langdon on February 25, 2025, 08:58:07 pmIn this specific case, there is no 3-cell point to tie into. The cells are arranged as 2x2. But also you seem to be suffering under the misapprehension that using a regulator is a problem -- it isn't really. The ones I have in mind are cheap -- in the $0.50 range and have vanishingly small current overheads, like 2-5uA. The regulator also provides a convenient voltage reference for battery level measuring that is much better than the internal 1.1V reference in the ATtiny.

author: Peabody
author_rank: Super Contributor
timestamp: February 26, 2025, 05:02:54 am
content: If the internal oscillator just isn't close enough to begin with, then you can adjust it using the OSCCAL register. But it will be affected by temperature, so may wander too much. It will also be affected by Vcc voltage, but you'll be using the regulator, so that shouldn't be an issue. Anyway, the crystal is certainly the safest option.The MCP1702 has a higher dropout voltage, but you'll be coming from 4 AAs to 3.3V, so that shouldn't matter. I forget - have you said how much current the door draws when it's active?

author: gardner
author_rank: Regular Contributor
timestamp: February 26, 2025, 04:34:55 pm
content: Quote from: Peabody on February 26, 2025, 05:02:54 amI wish I knew, but I have not attempted to measure it. The cat door is in-service, and I hadn't done that measurement before connecting up the points I needed and installing it.The loads I am aware of are:(1) the actual CPU, which I suspect is idle most of the time(2) an infrared sensor of some sort that senses if something is inside the entry area -- this could likely run 1 or 2 times/sec for just a few ms. Probably ~500uA or so and maybe at 1% duty cycle.(3) the RFID reader which runs in response to a IR sensor hit, for several (10ish) seconds -- I suspect this is the largest load, probably over 20mA X 10s(4) the latch actuator which operates when the RFID reads a matching animal. Probably ~80mA or more, specially since it runs to motor stall, but only for 1,000ms in 6 short bursts.When I got the cat door I took it apart and figured out how it worked and a fairly minimally intrusive set of monitoring points that I brought out in a custom connector, but it's in service now and has been for a few years, so I'm no longer in an easy position to do additional intrusive analysis.

author: Ian.M
author_rank: Super Contributor
timestamp: February 26, 2025, 04:42:47 pm
content: There are two common ways of avoiding the battery sense divider problems of quiescent curret and of I/O pins being dragged above the Vdd rail.add a low voltage drop high side switch (e.g. a P-MOSFET with a gate pullup, driven by a NPN or N-MOSFET to pull the gate down to switch it on) to switch the top end of the divider, leaving the bottom end permanently connected to 0V, and only swotch it on briefly for the ADC to sample the voltage at fairly long intervals.use a micropower very low input bias current RRIO OPAMP, powered from MCU Vdd to buffer the divider tap feeding the ADC so you can use very high value resistors in the divider so its quiescent cxurrent is small compared to the battery's self discharge.

author: Peabody
author_rank: Super Contributor
timestamp: February 26, 2025, 05:18:49 pm
content: Quote from: Ian.M on February 26, 2025, 04:42:47 pmYou can replace the N device with a capacitor, as shown in the circuit I posted in Reply #2.

author: Langdon
author_rank: Frequent Contributor
timestamp: February 26, 2025, 06:14:32 pm
content: Quote from: gardner on February 26, 2025, 02:38:20 amYeah the device uses only a couple uA but also throws out way more than that.