Monitoring battery voltage with an arduino nano

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,345
I am working on a circuit running from a 18650 cell and a boost converter to 5V, using an arduino nano. I would like to monitor the battery voltage so it can warn that the battery needs to be charged. Normally you would connect the battery voltage via perhaps a 10k resistor to a nano analog pin. However, the nano power can be switched off (Q1), disconnecting the input to the boost converter. In this case the battery voltage would be applid to the nano input while it is unpowered.

I came up with circuit below, see R3, C1. I think this works OK when the nano is powered but is it OK when the nano power is off?


1672829612033.png
 

John P

Joined Oct 14, 2008
2,025
As you said, it looks as if you might have a problem while the system is turned off. The Arduino will have its 5V line at zero volts then, and there are protection diodes from the input pins to 5V. I think then you'd then have the battery voltage going to the Nano's A1 via R3, and current along that path would allow the battery to run down. Could A1 receive its voltage from pin 3 of Q1 instead? During operation, the voltage drop across Q1 would be tiny, so you'd get an accurate reading, but when power is off there shouldn't be any current flow.
 

Irving

Joined Jan 30, 2016
3,845
When the power to the MCU is 0v and X volts is applied to a GPIO pin current flows through the internal input protection diode. To avoid damaging the MCU this needs tobe limited to a few mA. A 10k resistor between the GPIO/ADC input and the X volts supply will limit it to <1mA. For a 3.3v MCU the voltage at the pin should be limited to 3.6v typically. Your battery will be 4.1-4.2v for a LiPo, so a 33k to Vbatt and a 75k to ground will give approx 3v at the ADC input for a fully charged cell and will limit the current to 0.1mA when the nano is off.

What are the purpose of D1 and D2 to 'SW'? Are they the right way round?

Do you need on-board pull-ups on SCL/SDA?
 

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,345
R3 is 1MΩ and C1 (100nF) keeps the impedance at A1 low when the sampling capacitor (14pF) is charging.
So the battery drain when it should be off, and the current into the A1 protection diodes, would be around 3.7uA. Will this be any problem for the nano?

SW on the encoder is a switch to 0V.
D1 is there so that when Q1 is off, pressing the SW button on the encoder will turn Q1 on, then the MCU sets PWR high, which turns on Q2 and so keeps Q1 on. When the MCU wants to turn off the system it can take PWR low again.

When the system is on, D2 connects the SW signal to the MCU.
 

Ian0

Joined Aug 7, 2020
9,668
If all you need is a simple high-low voltage detection, then use an external comparator with open-drain outputs, and switch on the internal pull-up in the microcontroller when it is operating.
 

Ian0

Joined Aug 7, 2020
9,668
You're proposing added hardware and less capability!
I'm proposing removing unnecessary capability, and yes, there will be more hardware, but there will be more hardware on any scheme that switches off the sense resistor to prevent the micro being powered up through its protection diodes.
 

UweX

Joined Sep 2, 2020
33
The circuit may work in the proposed way. The question is just the ratio of turn-on time (where we have a high supply current) to turn-off time (here we have now a leakage current through R3 and the input protection diode). So if this additional current drain of the battery is not acceptable the idea of John to move the measurement resistor R3 to the switch output is the best improvement. When the micro controller is off, it can't measure any voltage. When it is on, the voltage is available. The drop over Q1 has to be considered ( I hope it is small and the µC can turn off any big loads during the measurement) and the time constant ( R3 ) can be decreased if the measurement takes place shortly after the power up. The time constant of the input filter can easily calculated and usually any code has some significant start-up time.

What supply voltage is the micro controller running on ? Usually the board has a 3.3V regulator and you can choose the voltage. In case of 3.3 V operation you have to consider a voltage divider like Irving recommended. In case you want to give only an indication for low battery voltage the R3 is sufficient. Down to 3.3V battery voltage the ADC will just measure "full". But the micro controller can precisely determine the power-off point assuming it is below 3.3V. Using a resistive divider gives some additional tolerances or errors in addition to the imperfection of the ADC and its reference.
 

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,345
Assuming a 3.7ua drain while the mcu is off then a 18650 cell would last somewhere around 60 years so I'm not going to worry about that as the cell would easily outlast me!
 

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,345
There are battery supervisor ICs for this purpose. They offer various capabilities but this one is very simple: B+, 0V, and an \( \overline{\mathsf{\text{LBO}}} \) output. It avoids using the MPU completely.
This would still need an mcu pin and would give only an OK/Bad indication. The proposed circuit allows for an approximate battery percentage remaining indication.
 

UweX

Joined Sep 2, 2020
33
Assuming a 3.7ua drain while the mcu is off then a 18650 cell would last somewhere around 60 years so I'm not going to worry about that as the cell would easily outlast me!
Beside this current you may already have a battery management IC and some self-discharge. Also the high application current will be active from time to time. This all adds up and I am sure you live longer than all this together.
 

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,345
Beside this current you may already have a battery management IC and some self-discharge. Also the high application current will be active from time to time. This all adds up and I am sure you live longer than all this together.
Yes, I have also included a charger circuit.
 

MrAl

Joined Jun 17, 2014
11,389
Hello there,

In good measurement circuits it is not unusual to use small reed relays made for signal paths to switch things to be measured on and off. That includes input voltages and auto set range switches. You can usually hear them click when you change range. That's on the better equipment.
If you can manage to use a regular reed relay you can turn it on at the appropriate time and simply turn it off when done.
If you cant do that, then you may have to go to a latching relay. That's the type where you energize one coil to get it to turn on and energize a different coil to get it to turn off. Once you energize it it stays in that state, on or off, so you can remove the signal that energizes it. That means it wont eat up battery power.
The kind of relays used however should be the type that are recommended for signal paths not just your typical relay, although that may work too (testing required).
 

MrAl

Joined Jun 17, 2014
11,389
How would that be an improvement on the circuit proposed here?
Hi,

Maybe i misread something?
It sounded like something was drawing current at the wrong time so it had to be switched off. Of course some kind of comparator circuit would have to go with that.
 

Thread Starter

AlbertHall

Joined Jun 4, 2014
12,345
It is essentially a custom wireless remote control, powered by a single 18650 cell, with a 2x16 LCD display and a rotary encoder as the interface.
It has a boost converter to make 5V for the LCD, the arduino nano, and the HC12 RF transceiver.
As it will be for only occasioanl use I wanted to be able to turn it off, and for it to be able to turn itself off after a period of no activity. This switch has to be between the cell and the boost converter.
 
Top