Reading and logging battery voltage

I'm putting together a bunch of sensors to log barometric pressure, temperature, humidity, and daylight brightness. Since it will be logging data independently of a computer, it will also need a separate power source. I have a 18650 lipo battery, the fancy kind that don't lie about their capacity, and i would like to log the battery voltage with the rest of the data to see how the voltage may effect the readings. And also tell it to turn off before it reaches the minimum voltage so i don't damage the battery.

This is a wiring diagram of what i plan to do:

The first thing is the battery charger, which charges via usb. The next thing is the big green battery. Then it goes to the step up converter to give the arduino the voltage it needs to operate properly. For monitoring the battery charge i just have the positive end of the battery leading straight into an analog input. Im not entirely sure if thats right. Should i have a high value resistor between there to make sure im not going to blow up the arduino or does the input pin only take the current it needs?

I also am wondering about where the voltage is on the battery. The negative and the positive end have half the voltage each correct? A 4.2v batter has a +2.1v and a -2.1v on each side. So if it's like that, then i shouldn't be putting the battery out - to ground. Does it matter?

If you think i should change anything else like the output voltage let me know please. Also if i should add some passive components. i think i should add a capacitor in parallel with the battery but i think that's all ready covered by the boost converter.

How long do you think the battey will last.
Half a day?
Boost converters like that consume quite a bit when doing nothing.
And boosting to 8volt wastes even more battery power.

Better to run the Arduino straight off the battery.
Nick Gammon (moderator here) has a website that explains most of what you're trying to do.
Leo..

Since the arduino needs at least 5v, should i use two batteries in series? That would make charging quite a bit more complicated too. Ill look for that website to learn some more.

A "bare bones" Arduino will run on 1.8 V (at lower clock speed) and many sensors will run on less than 3 volts.

This page describing a solar powered Arduino is a great introduction to all kinds of useful stuff. Study it carefully!

Need to change the extended fuse byte from
uno.bootloader.extended_fuses=0x05

to something else.
5 = 101 = BOD level of 2.7V typical
6 = 110 = 1.8V
7 =111 = BOD disabled.

The byte may also read back as 0b11111xxx,
so 0xFD, 0xFE, 0xFF
for the 3 settings above.

griffin175:
I have a 18650 lipo battery, the fancy kind that don't lie about their capacity,

What do you mean about the battery not lying? You've piqued my interest.

The negative and the positive end have half the voltage each correct? A 4.2v batter has a +2.1v and a -2.1v on each side. So if it's like that, then i shouldn't be putting the battery out - to ground. Does it matter?

They don't have two halves, each producing 2.1V. It's just a cell, and has 4.2V across it when charged. And yes, ALWAYS connect the battery's -ve end to gound. If you connect the +ve end to ground, a wire from the other end will have -4.2V potential, and cannot be connected to your Arduino. It's best to look at the battery as being 0V at the negative end, and +4.2V at the positive end.

And for simplicity all around, it's better to use 2 of your cells in series, as you suggest in your second post. Then you need no boost converter or any of the other complicated options suggested. You could charge the two batteries while still connected in series, or charge them individually. Speaking of which, how do you plan to charge the cell(s)?

To monitor the voltage of two cells in series with an analogue pin, you couldn't connect the positive end directly to the Arduino, but a simple 2-resistor voltage divider solves that problem. You just need to ensure that the very highest voltage presented to the analogue pin is below 5V, then scale the ADC result accordingly.

Edit: Oh, by the way, they're actually a 3.6V cell, too, not 4.2V. They're about 4.2V straight off the charger and without a load, but this rapidly drops to ~3.6V.

Thanks oldSteve, what i meant by the fancy kind of battery is not the $2 a cell from eBay china kind which advertise the capacity of a car battery. A lot of people get tricked by that and the batteries generally fail in very little time.
Don't worry, i had no intention of hooking up the positive to ground. I was just wondering if the voltages were divided by the two sides if i would have to do anything first. Im used to using usb or power supplies, this is my first battery project. But i think it doesn't matter because whatever the GND volotage is, as long as it's negative, you just pretend it's 0 and at the leftover to the positive end so you have a 0v reference.
I know it is a 3.6v cell on average, i was just giving a max range. It turns out that the battery will last a lot longer than half a day. I did remove the voltage booster and i was interested in the lower bounds of the non-barebones arduino nano and the sensors. I hooked it all up last night and gave it the bare necessity code to operate, without any sleep function and writing data once a second. in about 11 hours it has dropped the battery from 4.22v fully charged to 4.08v. And that's still the steep drop off part of the curve with no power saving tricks at all. I don't think ill have any issues getting this to run for 48 hours on one charge. But it would probably last a year using every trick on that website. Thanks Wawa and jremington, that was a very helpful guide.
To monitor the battery voltage, i just went straight from the battery anode to the analog input. I learned that it does have high impedance like a multimeter, so i figured it would be fine since the voltage will never be above 5v.
Ill know for sure how everything went running 2v lower than the lower bound, according to the store page info, when i check the data. I put it in the refrigerator so conditions should be pretty constant while voltage drops. I'll be able to see if it had an effect on the data.
I plan on charging the cell with a phone charger and a small circuit ass seen in the diagram i drew, but if i need two i cant use it to charge them while in series. I'm planning to seal it in a case and the batteries would be hard to remove and put back.
CrossRoads, I don't know what an extended fuse byte is. I'm still pretty noob. Could you explain what this does and how do do it with a bit more detail?

UPDATE: I have just reviewed the data, and it seams that the lower voltage did have an effect on the data. The temperature readings were a bit higher than they should have been and the voltage logged on the battery was always 5v on every measurement even though it stated at 4.2 and went down to 4.04v. I think im going to have to try this again but with a variable power supply to get a better relation of input voltage to data logged. Perhaps I should figure out how to change the extended fuse byte like CrossRoads said. But i have no idea how and there's not a lot on info available on google.

Change the fuse value in boards.txt and reburn the bootloader.
Do you have a Programmer?

I am using 4 AA NiMH batteries with a couple of 5V solar panels in series with a Schottky diode in parallel across the panel (rated at 5.3V). A diode with a voltage drop of 0.3V is in series with the pannels +ve rail and the battery pack to stop backflow of current at night.

This gives me a nice pack that provides plenty of juice (2,200mAh worth) and with the 2 panels, a basic log and broadcast every minute system is dead happy...essentially forever.

The panels are rated at 120mA I think it was. My nano uses around 30mA with a few sensors...so on a 10 hour day (as I have 2 panels in series, I get 5V on cloudy days as well) there is plenty of juice.

The panel and pack easily mount on top of the electronics in quite a nice neat package.

Food for thought.
AAA rechargeable make for an ever smaller pack?

griffin175:
The temperature readings were a bit higher than they should have been and the voltage logged on the battery was always 5v on every measurement even though it stated at 4.2 and went down to 4.04v.

What sensor. Analogue, digital.
LM35 can't be used. TMP36 can.

Arduino can't measure it's own supply if you use default Aref.
A lower battery voltage = a lower Aref = the same A/D value = the same voltage printout.

Measure both agains 1.1volt Aref.
Leo..

CrossRoads:
Do you have a Programmer?

I dont unfortunately. I'm using the basic out of the box Nano, so it already has the bootloader and I didn't need a programmer.
I did some more testing on the lower bounds of the components. The pressure and temperature sensor both work fine down to 2.8v, but for some reason the SD card stops working when it only gets 4.3v. For both of those the arduino and the signals were still 5v, just the VCC was adjusted for each individually. A 4.3v minimum is interesting because it worked fine under 4.04v on the battery when everything was getting 4.04v. So it would make sense that the real issue would be whatever the fuse byte is.
Another weird thing that's happening is when it is under battery power is always says the voltage is 5v. I have added a pull down resistor to the analog pin, and it works fine under usb power. Im guessing that the analog read value is actually a ratio of the voltage input of the arduino to the voltage at the analog input. Is that how that works?

Wawa:
Arduino can't measure it's own supply if you use default Aref.

It can with a voltage divider, then scaling the result.

Wawa:
What sensor. Analogue, digital.
LM35 can't be used. TMP36 can.

Arduino can't measure it's own supply if you use default Aref.
A lower battery voltage = a lower Aref = the same A/D value = the same voltage printout.

Measure both agains 1.1volt Aref.
Leo..

Im using a BMP085 digital pressure and temperature sensor.
That explains my voltage reading issues. But how to i get 1.1v to the Aref? If i set up a voltage divider the voltage will drop with the battery voltage, wont that be resulting in the same issue? I don't have any variable voltage regulators except an LM317T, and that's a bit over kill and might be negating any power savings of not using the boost converter.

OldSteve:
It can with a voltage divider, then scaling the result.

How do is use a voltage divider and scale the result? Sounds like it will be some difficult math.

Here is a function which will read the battery voltage, by comparing with the internal voltage reference.
Again, I strongly recommend that you study this post, which does much of what you want. Save yourself some self-flagellation.

// Reads 1.1V reference against AVcc
// returns battery voltage in millivolts
// must be individually calibrated for each CPU

int readVcc(void) {

  int result;

   ADCSRA = (1<<ADEN);  //enable and
   ADCSRA |= (1<<ADPS0) | (1<<ADPS1) | (1<<ADPS2);  // set prescaler to 128

  // set the reference to Vcc and the measurement to the internal 1.1V reference

   ADMUX = (1<<REFS0) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
   delay_ms(1); // Wait for ADC and Vref to settle

   ADCSRA |= (1<<ADSC); // Start conversion
   while (bit_is_set(ADCSRA,ADSC)); // wait until done
   result = ADC;
  
   // second time is a charm

   ADCSRA |= (1<<ADSC); // Start conversion
   while (bit_is_set(ADCSRA,ADSC)); // wait until done
   result = ADC;
  
   // must be individually calibrated for EACH BOARD

  result = 1148566UL / (unsigned long)result; //1126400 = 1.1*1024*1000
  return result; // Vcc in millivolts
}

but for some reason the SD card stops working when it only gets 4.3v.

SD card has its own 3.3V regulator? May not output 3.3V anymore when the input voltage gets too low.

griffin175:
How do is use a voltage divider and scale the result? Sounds like it will be some difficult math.

Sorry, I didn't read Wawa's post properly, I was distracted. You can't use the default AREF in your situation.

I've just been reading back through the thread and have a question. Where are you connecting your battery voltage to the Arduino? Vin?

jremington:
Here is a function which will read the battery voltage, by comparing with the internal voltage reference.
Again, I strongly recommend that you study this post, which does much of what you want. Save yourself some self-flagellation.

Thanks, i've been studying that page and it is very relevant and useful. But It's a too far beyond my abilities and understanding of how this stuff works to apply it to this project now. I've already got it operating fully under USB power, and the battery lasts pretty long without any power saving tricks. All i want to do to finish it is to read the battery supply voltage, and if i can figure out how to calibrate it to get that function working ill be nearly done.

CrossRoads:
SD card has its own 3.3V regulator? May not output 3.3V anymore when the input voltage gets too low.

It has it's own regulator to take 5v down to the normal 3.3 for SD cards. The weird thing is it works fine under a lower voltage if the arduino is also getting the same lower voltage.

OldSteve:
I've just been reading back through the thread and have a question. Where are you connecting your battery voltage to the Arduino? Vin?

Yes, i am using the Vin. I know that has the regulator on it. Should i be going around it by plugging it directly into the 5v pin? Since it never goes above 4.2 i guess there's no point in a regulator.

griffin175:
Thanks, i've been studying that page and it is very relevant and useful. But It's a too far beyond my abilities and understanding of how this stuff works to apply it to this project now. I've already got it operating fully under USB power, and the battery lasts pretty long without any power saving tricks. All i want to do to finish it is to read the battery supply voltage, and if i can figure out how to calibrate it to get that function working ill be nearly done.

It has it's own regulator to take 5v down to the normal 3.3 for SD cards. The weird thing is it works fine under a lower voltage if the arduino is also getting the same lower voltage.

Yes, i am using the Vin. I know that has the regulator on it. Should i be going around it by plugging it directly into the 5v pin? Since it never goes above 4.2 i guess there's no point in a regulator.

Yep. The regulator has a dropout voltage of about 1V. ie 1V of your battery voltage is immediately lost across it. So from your ~4V, only about 3V is 'seen' by the chip. If I were you I'd connect directly to the 5V pin, as you say.
(And I'd personally still go with 2 of those LiPo cells in series for , but that's just me.)

The sensor is digital.
That means you're able to set Aref to 1.1volt for battery measurements.

I would use a single LiPo cell connected to the 5volt pin.
That would give the same (or better) battery life as two LiPo cells in series.

Use a 1:3 voltage divider to measure the battery. High-ish values for less drain.
e.g. 33k to ground and 100k to battery.
Add a 100n cap from analogue pin to ground for stable readings.
Read with 1.1volt Aref.
Leo..