Monitoring a LiPo battery while powering the Arduino UNO with it

I want to power an Arduino board from a LiPo battery and monitor its voltage as it winds down.

I have read how to connect the A0 to the + of the LiPo battery and its - to GND on the board (ReadAnalogVoltage example) to monitor the battery itself from a sketch.

Now I want to power the Arduino itself from that same LiPo battery. I was thinking of powering the Arduino through the Vin & GND pins.

I believe the Vin has a power regulator that regulates it down to 5V, correct? The barrel jack too? So what would be the adv/disadv of either? I ask because in my case I will want to also measure the battery pack voltage. For that I would need to tap the +/- from the battery, which leads me to think of a circuit like this:

I believe you are correct, Vin and the jack are the same connection essentially. The pros and cons seem pretty strait forward, the barrel jack is more convenient, but requires the plug, Vin needs no special connector, but isnt quite so convenient.

That being said, I had some issues with my mega clone's jack (inconsistent connection), and I dont see much love for it here on these forums. On top of that, in my case, it wasn't clearly marked, so i had to follow traces to figure out which way was right. Personally, id stick with Vin.

One thing it looks like you havn't considered however, the batteries voltage. Youll need more than 3.7v on the jack or Vin. I'm pretty sure the rated minimum is 7v (I've successfully ran a nano and mega on 6v though). Once you get the voltage up to the right level, you'll have to lower it back down under the max input of A0.

In short, your basic approach is right, but there are some things to consider to set it up.

If you put 3.7volt on the DC jack, you are left with 3volt on Vin (raw).
Because the Uno has a reverse protection diode between DC jack and Vin.

3volt on Vin is about 2volt on the 5volt rail, because of the ~1volt drop of the regulator.
Your Uno won't work anymore on the default clock settings.

You can connect a <=5volt battery (single cell LiPo) directly to the 5volt pin.
Your Uno will run within specs untill the battery dropw below ~3.8volt.
Then it's russian roulette. Nothing breaks, but you MIGHT have errors.
Undervolting is like overclocking. Hard work, not enough food.

You can connect a <=5volt battery to the analogue input (wise to use 4k7 or 10k resistor between +battery and pin).
But you can't measure it with default Aref.
When the battery goes down, so does Aref, and you will have the same A/D value and so the same voltage readout.
There are other ways though.
Leo..

Edit.
Check the specs of the Arduno you have. There are differences especially in the supply section.

True. Ill have to add 2 batteries in series to the schematic then because I cant find a 7.4V battery in Fritzing.

And as for the A0 volt, I guess you mean with a voltage divider?

Btw, I downloaded LTSpice and Circuit Construction Kit. I was wondering if I can model this in LTSpice and somehow tell the schematic that it will consume xyzmA and have it run through the amount of time it would last until it depletes?

That's how I would hook it up. You might want to play with the resistor values though. They form a complete circuit for the battery to drain through. Id use as high of a value as you can.

I dont know much about that software, but you can do that calculation yourself using the batteries "mAh" rating. This is the batteries charge life. Divide that number by your current draw (in mA) to get an estimation of how long it will last.

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

Thanks Wawa...what I meant is that I need the LiPo to drain to determine how it will last. The reason why Im thinking of doing it this way is that for now, all I will power is my board, but eventually I will test this on a setup with a board with a shield and sensors. So I want to determine how much everything will be drawing as a whole, in order to determine how much storage I need as well as production to refill my LiPo.

I know there are power estimations of board power consumption but with the sensors I will be adding and my sampling times, it gets really complex to estimate and even then its still just an estimate.

Oh yeah, wait a minute...it does complete the circuit. I hadn't noticed that. Hmmm...I might have to rethink my whole setup here.

Battery capacity changes with temperature, and drops with age.

You should measure both cells if you connect two in series.
For safety, discharge should be stopped once ONE cell drops below ? ~3volt ?

I suppose you could use a voltage divider for both cells (8.4 to 6volt), and a single resistor for the grounded cell (4.2 to 3volt) connected to a second analogue input. Subtract the voltages to know the voltage of the top cell.

Note that measuring with default Aref does not work anymore once Vin drops below ~6volt.
1.1volt Aref still does.
Leo..

I don't know about an Arduino board but you can easily power an Atmega 328 chip from a 3.7v LiPo and have it report the correct battery voltage.

The trick is to turn the voltage measuring upside down. Pretend that the reference voltage is Vcc (which will vary as the battery discharges) and use that to measure the 1.1v internal reference voltage (which won't change).

This is the code I use in my standalone 328.
This first bit goes in setup()

        // set up for batt voltage measurement
        // REFS1 REFS0          --> 0 1, AVcc internal ref. -Selects AVcc external reference
        // MUX3 MUX2 MUX1 MUX0  --> 1110 1.1V (VBG)         -Selects channel 14, bandgap voltage, to measure
    ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);  
    delay(50);  // Let mux settle a little to get a more stable A/D conversion

and this is the function that does the measuring

int getBattVolts() { // Returns actual value of Vcc (x 100)

     const long InternalReferenceVoltage = 1080L;  // Adjust this value to your boards specific internal BG voltage x1000
        // Start a conversion 
     ADCSRA |= _BV( ADSC );
        // Wait for it to complete
     while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
        // Scale the value
        // 100L is my fudge factor to match my multimeter R2
     int results = (((InternalReferenceVoltage * 1024L) / ADC) + 100L) / 10L; 
     return results;
}

I got this from here

...R

Robin2:
I don't know about an Arduino board but you can easily power an Atmega 328 chip from a 3.7v LiPo and have it report the correct battery voltage.

The trick is to turn the voltage measuring upside down. Pretend that the reference voltage is Vcc (which will vary as the battery discharges) and use that to measure the 1.1v internal reference voltage (which won't change).

This is the code I use in my standalone 328.
This first bit goes in setup()

        // set up for batt voltage measurement

// REFS1 REFS0          --> 0 1, AVcc internal ref. -Selects AVcc external reference
        // MUX3 MUX2 MUX1 MUX0  --> 1110 1.1V (VBG)        -Selects channel 14, bandgap voltage, to measure
    ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0); 
    delay(50);  // Let mux settle a little to get a more stable A/D conversion



and this is the function that does the measuring


int getBattVolts() { // Returns actual value of Vcc (x 100)

const long InternalReferenceVoltage = 1080L;  // Adjust this value to your boards specific internal BG voltage x1000
        // Start a conversion
    ADCSRA |= _BV( ADSC );
        // Wait for it to complete
    while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
        // Scale the value
        // 100L is my fudge factor to match my multimeter R2
    int results = (((InternalReferenceVoltage * 1024L) / ADC) + 100L) / 10L;
    return results;
}




I got this from [here](http://forum.arduino.cc/index.php?topic=38119.0)

...R

Now that is clever.

Ok but just a sec. So if I wire it up the way I proposed in Post #3, the battery will drain because of the board and also because Im shorting the circuit of the circuit between +/- leads of the battery with resistors?

Marciokoko:
Ok but just a sec. So if I wire it up the way I proposed in Post #3, the battery will drain because of the board and also because Im shorting the circuit of the circuit between +/- leads of the battery with resistors?

I have just a sinlge LiPo powering my Atmega 328 so I don't need any voltage divider.

If you do need a voltage divider choose resistor values that cause an acceptable voltage drain. But be aware that the ADC works best with a max resistance of about 10k - read the Atmel datasheet.

...R

OK, I need to ask something basic Here:

  1. Why does using a voltage divider cause this drainage issue?

  2. And how would I choose a resistor that generates an acceptable voltage drain?

  1. A voltage divider is a circuit comprising two resistors between positve and GND. Current flows through resistors - that's what they are for. (The measured voltage is read from the junction between the resistors).

  2. Read up about Ohm's law.

...R

No, I wasn't clear. I know the voltage divider splits the voltage. I know I need one because I have a 7.4v battery and the Arduino can only take 5v.

But when I drew up the schematic on post 3, I was told I would have a problem with the battery draining itself not just because it's powering the board but also because it's basically short circuiting itself through the voltage-divider-resistor circuit.

Can someone explain to me why this would drain my battery and how resistors would prevent that?

Thanks

Marciokoko:
Can someone explain to me why this would drain my battery and how resistors would prevent that?

That is what I was trying to do in Reply #13.

Current flows through the resistors in the voltage divider. That current comes from the battery.

I suggested you study Ohm's law so you can choose appropriate resistor values to minimize the current and deplete the battery as slowly as possible.

...R

Well I have been reading up on Ohms Law and a few others here (http://www.learn-about-electronics.com/).

I understand resistors slow down current flow, and it does so by converting some of that electrical energy into heat. But Im not sure how I can use specific types of resistors to minimize the battery depletion. I understand values of the resistors change the voltage but I dont understand what I would need to change?

Do I want to add large resistors to slow down the current flowing through the voltage-divider circuit or speed it up? It seems logical that the more resistance, the less current will flow through it and thus will short out the battery slower...

If you have a 5000 ohm resistor and a voltage of 5 volts across it, how much current will flow ?

(and PLEASE, other readers leave this exercise for @Marciokoko)

...R
PS ... resitors don't "slow" electricity. Electricity flows at near the speed of light, including through resistors.

5V/5000Ohms = 0.001A

whereas if I use a 50,000Ohm resistor I will only get a 0.0001A current.

So the current is less. This means the battery will discharge slower?

One thing about resistors slowing electricity down. I read this (Speed of electricity flow (speed of current.)) but I need to read it a few more times. I understand electricity (as referred to the movement of charge) never stops. I get that from my organic and inorganic chemistry classes as well as PChem classes. But they do reduce current flow, right? Because they do dissipate part of that electric energy as heat energy.