Voltage Divider Battery Sensing - No Change to Readings?

Hello, it's me again. Back with another question I'm hoping someone can help me with please. :slight_smile:

The project I'm working on at the moment is going to be powered by a 12V 7Ah Sealed Lead Acid battery (Model: NP7-12TFR if that helps).

I want my project to monitor its own battery health so I turned to a library I've found on GitHub called Battery Sense. GitHub - rlogiacco/BatterySense: Arduino library to monitor battery consumption

I am using an DC-DC converter to step down the 12V to 5V for powering my project so I built my sensing circuit based on Sections: Higher than 5V, with external voltage regulator and Higher than 5V, activated on demand.

What I ended up with was the On Demand Circuit placed between the battery and the DC-DC converter as shown in Higer than 5V with external regulator.

I'm almost certain I've followed every instruction to the letter including the recommended VoltageReference calibration and I am getting a reading but it doesn't appear to be changing.
Yesterday the freshly fully charged battery was at 13.314V according to the battery sense sketch and today it reads the same?

I verified the reading yesterday against my multi-meter and it was pretty darn close but today my multi-meter is showing 13.093V but the sketch still says it's 13.314V.

I have checked, checked and triple checked the circuit wiring for mistaks I may have made wiring it up on breadboard but as far as I can tell I have reproduced the circuit exactly and the values for the resistors are correct. I have also verified that my ratio values are correct in the library as well as the true voltage. I have defined correct upper and lower (MIN MAX) battery values and that all the pins used are wired to the correct places.

I just can't understand why the reported voltage isn't showing any drop.

Basically the circuit is just a simple voltage divider rated to handle / read 12V batteries and it's switched in and out of circuit using a 2N7000 Mosfet. It all appears to be working except the readings don't seem to be changing at all.

Obviously I know these battery monitors aren't super reliable or super accurate due to so many influential factors and variables but I just want some rough idea of what the battery is doing.

Sorry if that's not enough or is too much information. If any more information is needed to help diagnose my problem just ask and I'll do my best to provide it. In the mean time I'm going to keep working the problem myself. Naturally if I get to the bottom of it before anyone has an answer, I'll post back with the solution.

Many thanks!

Thanks!

Give it a try with just the voltage divider.

Try and discharge the battery a bit more.

And just do the reading without a library and see what you get.

PS The switching via the mosfet is a dumb design. Because of the clamping diodes in the Arduino the voltage can only float up to 5,5V. So I assume you used the 22k for R1? With a battery of 13,3V you still have (13,3V - 5,5V) / 22k = 0,35mA drain. Doesn't sound like a lot but when turned "on" it just draws 13,3V / (22k + 10k) = 0,42mA. That's just a saving of 70uA...

First try to short D and S (wire it together) of the mosfet. What do you measure at sense input?

What arduino do you use? With 5V or 3.3V VDD?? What are the R1 and R2??

Note: Mind the switching off the divider with low-side n channel mosfet is suboptimal, as the battery will discharge itself via R1 and the clamp diode in the Sense input into the Vdd.
You have to switch off the R1 at the high-side instead.
PS: Septillion describes the issue in detail :slight_smile:

There is an another "active" divider design which does not draw almost any current when off.
For example:
http://www.stm32duino.com/viewtopic.php?f=18&t=1697&hilit=zero+load

Post your code and your circuit - these are rather essential to troubleshooting!

What I ended up with was the On Demand Circuit placed between the battery and the DC-DC converter as shown in Higer than 5V with external regulator.

I haven't completely studied those circuits or the software but it looks "fishy" with the MOSFET in series with the voltage divider. The MOSFET will affect the voltage divider and when the MOSFET is "off" it's going to totally screw-up the voltage divider.

So, I 2nd what septillion said... Just use a normal voltage divider directly across the battery (the Higher-continuous schematic). Or, at least start with that until you can figure-out what's going on.

But the solution of pito is nice :slight_smile: The effect of the mosfet is negligible. It's resistance is orders of magnitude lower than the resistors.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Hi all and many thanks for all the replies!

First of all I'll start off by providing all the information that's been requested.

My breadboard prototype is using an Arduino Nano for convenience but the finished design will be using a stand-alone Atmega328P-PU IC so I can save as much power as possible by not having stuff powered up / consuming power that doesn't need to be and by using sleep etc.

My project runs at 5V which is supplied by a DC-DC Buck Converter (MP1584EN 3A - supposedly quite efficient) which is in turn is fed from my 12V Lead Acid Battery.

I have split my project into 2 parts. So I have a main board with the Atmega328, Crystal and Sensors etc mounted to it and then I have my power board which will have the DC-DC Converter mounted to it as well as the Battery Sensing Circuit - once finalised.

This is the Circuit Diagram for my Power Board with the Battery Sensing (Voltage Divider) that I am having trouble with.

And this is the code I've been using to test the Battery Monitor Circuit Above. It's the example code that goes with the Library I found on Github - mentioned in my original post - if that helps?

#include <Battery.h>

Battery battery(11900, 12800, A1, 7);  //BATT MIN/MAX (Realistic 12V Battery Range), Sense Pin, Mosfet Switch Enable Pin

void setup() {
	Serial.begin(9600);
	while (!Serial);
	battery.begin();
}

void loop() {
	digitalWrite(13, HIGH);
	delay(3500);
	digitalWrite(13, LOW);
	delay(3500);

	Serial.print("Battery voltage is ");
	Serial.print(battery.voltage());
	Serial.print(" (");
	Serial.print(battery.level());
	Serial.println(")");
}

Due my project being battery powered, I'm trying to keep the power consumption of my project as low as I possibly can. I've streamlined my main board as much as I can so that the Atmega spends the majority of the time sleeping and power only goes to those modules, devices and components that have to be on. Everything else is asleep or powered down.

I'm still very much a novice at this game so I relied on Google to guide me to the most efficient DC-DC converter so I wasn't wasting too much power with such a large step down from 12V to 5V and when the Main board is asleep and not drawing very much. I came across a very informative website which did a Regulator comparison and the MP1584 came out as the best for my needs.

Unfortunately I haven't had time to try any of the provided suggestions for debugging the Battery Sensing circuit yet. While waiting for replies, I thought I'd get on with etching out the first prototype PCB for my main board since the breadboard prototype performs as expected or better.

Now that I've etched my main board I can turn my full attention to the problematic Power Board. I just thought I'd post up some more information before I tried any of the suggestions made.

Although, if some of you guys are saying it's a bad design, I might think about looking at something better instead. All I would like to do is monitor the battery voltage by taking a reading once every hour so it doesn't have to be anything fancy just so long as it's efficient and wont put a constant drain on the battery - if that's possible.

@Pito: I looked at that link you posted and it looks very interesting and looks like it might be just the thing I need. I'm going to go back and have a more in depth read of that thread to get my head around it a little better. If I had any questions would you mind dropping me a few hints if I find I need it?

Thanks for all the help!

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Include:
Battery
Converter
Arduino

Everything, not just half a dozen bits of circuit that needs a SearchAWord expert to trace the wiring.
ie: Draw WIRES between components, layout logically your circuit so it shows your current flow, this will make trouble shooting soo much easier.
Your schematic may be good for a PCB manufacturer, but not for circuit function tracing.

Note that most of the labels are of no use to the circuit as a schematic.
ie: Wirepad numbers.

Note, When you turn Q1 off you will be pulling the arduino input pin the battery volts.

Thanks... Tom.. :slight_smile:

If you must turn off the voltage divider, put the MOSFET in between the resistors and tap off below it.

screenshot.194.jpg

The downside is that you need a MOSFET that can turn on at a very low voltage, and those don't usually come in a through hole package. It's not impossible to solder a SOT-23 package (like a DMG6968) by hand, but it takes some practice.

screenshot.194.jpg

http://jeelabs.org/2013/05/16/measuring-the-battery-without-draining-it/index.html

http://jeelabs.org/2013/05/17/zero-powe-battery-measurement/index.html

Hi, looking at your circuit I don't see a problem. The 2N7000 ON resistance is ~ 6 ohms with a gate voltage of 4.5V, so its well below the error caused by the resistors if they are 1%.

I do notice when the FET is off (no gate voltage) you have 12V going to the Arduino through a 22k resistor. This should have minimal effect, however it means if the FET is not on when you take your reading it will read the same voltage all the time, which is what you have.

As others have mentioned, test without the FET (i.e. FET shorted). If you readings are more what you expect, I would:

  1. Turn the FET on all the time with the arduino. Retest voltage
  2. Put a delay between turning the FET on and initiating your reading.

Good luck

JohnRob:
Hi, looking at your circuit I don't see a problem.

The one from post#7 or from post#9.

The one from post#7 is definitely wrong.
Remove the fet and/or R2, and you see that R1(22k) dumps it's current in the pin protection diode of the analogue input.
The diagram of post#9 hasn't got that problem.
It should work, assuming the source resistor is calculated for <1volt and 1.1volt Aref is used in setup().
Leo..

Indeed, start by removing the MOSFET. It's useless in this configuration anyway :slight_smile:

@ Wawa

I don't believe circuit #7 has a problem and with this configuration you don't have to worry about getting enough gate voltage to the FET.

I understand that some folks don't like to "use" the body diode for circuit function. However I've worked with Microchip factory engineers on commercial products. They told me the body diodes were quite capable and some milliamps would not be a problem. Here the OP would have a little over 300 ยตA, should not be an issue.
And yes I know this is not a Microchip processor but I can't imagine the process is that much different.

But in the end design trade off's are a personal decision.

Not worried about clamping diode current.
The whole idea of using a fet there is to stop the voltage divider draining the battery.
The circuit from post#7 doesn't do that.

I would forget the whole fet setup with a lead/acid battery, and just use very high value resistors.
As in the first link from post#10.
Battery self discharge will be higher than the drain of a >=10Megohm resistor.
I also would drop to 1volt, and use 1.1volt Aref.
Leo..

@Wawa

I agree. I wasn't thinking of the battery drain aspect, just the function. My bad.