1s Lipo and Arduino

Hy

I got now a 1s Lipo working with a step up voltage regulator and all this powers an Arduino. Now I would like to measure the voltage of the battery. How does this work? I can't just connect the wire from the Lipo + to an Analog. Could someone help me?

Thx Geko

You could do something like

int val = 0;
void setup(){
analogReference(DEFAULT);
}
void loop(){
val = analogRead(0);
val = map(val, 0, 1023, 0, 500);
Serial.println(val);
}

Which would print to serial the voltage on analog pin 0 in millivolts. Be careful not to exceed 5V though!

I can't just connect the wire from the Lipo + to an Analog

Well actually you probably can. If the Lipo's negative is common to the step-up regulator's common, which is then the Arduino common, you are free to just run a wire from the Lipo's positive terminal to one of the Arduino's analog input pins. A single cell Lipo maxes out at around 4.2 volts so that is within the 0-5vdc. How you scale (map) the analog counts to a voltage value depends on what the output voltage is for the step-up regulators, as that voltage is the default voltage reference. If it's 5vdc then mapping the 0-1023 counts to 0-5000, will give you the Lipo's terminal voltage directly in millivolts.

Caution about Lipo batteries. If you over discharge them they go bad and won't take a recharge. If you overcharge them they tend to catch fire or explode. :-?

Lefty

Thx, but I tried this and the readout was allways 5V. If i attach an extern battery it works great but with the one connected to Step up Voltage regulator doesn't work...

EDIT: Hm now I get a value 3.91v but the right one would be (measured with a DVM and another Arduino) 3.78v. whats wrong?

Geko

Hm this doesn't work. I recorded the data for about 1.1 Day and it looks like this:

My Arduino doesn't use any battery :)

Can someone help me?

Keep in mind the resolution of a 10bit A/D reading is around 5 millivolts. What you probably need to do is to take around 8 readings at a time, add them together and then divide by 8, thus getting a good average reading value for each sample. Try that and see if it doesn't help with the noise/resolution you are seeing.

Lefty

thx for the hint now it looks much better:

Thx

Sorry, made a mistake in the first code, map to 5000 not 500 >.<!

Good to see you got it working, though :slight_smile:

no Problem. But could someone explain me why the result when I measure a Lipo which isn't conected to the Arduino are better (more precisely) then measuring the Lipo which does power the Arduino?

Thx

Well what load is the Li-po powering when measuring but not powering the Arduino? The Li-po powering the Arduino is under a load, lots of digital switching going on. Perhaps a little filtering (cap) would help, but that's what averaging the analogreads is doing also.

Lefty

You are most likely picking up switching noise from the Arduino or the step-up regulator. As the Arduino clock switches from low to high and back it draws a higher current. These switching currents produce a voltage drop across the battery that will appear to be random to the ADC.

Your trend line is lower and you have a random deviation around above and below the line. Since there is no switching load on the second Lipo you do not see the variation due to switching currents.

(* jcl *)

www: http://www.wiblocks.com twitter: http://twitter.com/wiblocks blog: http://luciani.org

ok that sounds logic thx a lot for all those explanations.