I'm doing a little project using a Lipoly charger and a 2500mAh 3.7V battery, both from Adafruit. I'm trying to display the percentage left on the battery. For that I'm using this little sketch :

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;

I saw on that page that the minimum voltage is 3.0V so I use that to get my values :

  float volt = (float)readVcc()/1000;
  float percent = ((volt-3)/0.7)*100;

When I display my values, it shows me that the percentage left is -4%. Should I worry or am I doing something wrong while calculating?

  • \$\begingroup\$ If your calculation ((volt-3)/0.7)*100 gives you negative number - that means your "volt" variable is less than 3V. \$\endgroup\$
    – Kamil
    Commented May 12, 2014 at 11:41
  • \$\begingroup\$ Wait wait... You measuring constant 1.1V reference connected to ADC input and calculating Avcc? ADC backwards, interesting! \$\endgroup\$
    – Kamil
    Commented May 12, 2014 at 11:53
  • \$\begingroup\$ Kamil, could you explain what you just said ? Because the function readVCC isn't from me, I got it on this page : code.google.com/p/tinkerit/wiki/SecretVoltmeter \$\endgroup\$ Commented May 12, 2014 at 12:07
  • \$\begingroup\$ I explained in answer. \$\endgroup\$
    – Kamil
    Commented May 12, 2014 at 12:10

1 Answer 1


I think your calculation is OK.


If your ADC conversion results is 1024 (full scale 10 bit) - when AVcc = reference

result = 1126400L / 1024 = 1100;

If your ADC conversion results is 512 (half scale 10 bit) - when AVcc = reference / 2

result = 1126400L / 512 = 2200;

Your percent result is -4% because voltage is below 3V.

percent = ((volt-3)/0.7)*100
-4 = ((volt-3)/0.7)*100
-4/100 = (volt-3)/0.7
-0.04*0.7 = volt - 3
-0.28 + 3 = volt
 2.972 = volt
  • \$\begingroup\$ And is it safe to have a voltage below 3V with a 3.7V battery ? \$\endgroup\$ Commented May 12, 2014 at 12:15
  • \$\begingroup\$ No. It's not good for Li-Ion battery. It will loose capacity pretty fast. You should disconnect battery when it happends or reduce current to microamperes (microcontroller in sleep mode, leds off, everything off) until battery will be recharged. \$\endgroup\$
    – Kamil
    Commented May 12, 2014 at 12:19
  • \$\begingroup\$ Ok thanks :). Do you have any idea how to shut off the Arduino when battery is below 3V ? I saw that there is a sleeping mode in the arduino, should that be enough ? \$\endgroup\$ Commented May 12, 2014 at 12:22
  • \$\begingroup\$ It depends on what you have connected to that battery. And how long this circuit will stay without charging. If you leave it in sleep mode at 3V for few weeks - it will kill battery anyway. It's really hard to tell. Im not arduino guy, I don't know how sleeping mode does. If it turns on Power-down Mode: (0.1µA in Atmega328P) - it should be enough, but it's hard to tell without schematic. If you have I2C with pullups - they can kill battery no matter if you have power-down mode on. \$\endgroup\$
    – Kamil
    Commented May 12, 2014 at 12:26
  • \$\begingroup\$ All right, thanks for all the answers ! I'll check that out ! \$\endgroup\$ Commented May 12, 2014 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.