Battery Level on Artemis Nano

Can the battery level be read on the Artemis Nano?

If so, how?

I used a known 12v voltage with a voltage divider (resistor pair) to get battery output < 3.3 volts. I read the analog pin to get a known reading at 12 volts. Here’s the code I used…works fairly well:

/get_Battery_Perc*****************/

/*!

\fn get_Battery_Perc

\brief Measures volts on A0 and converts to % battery left

\param None

\called timer_isr so updates about every 2 sec’s

\msg Sends calculated battery % to Android

\Notes Using 12v 2000 mAh 10 pack nimh battery.

\return None.

*/

/*****************************************************************************/

void get_Batt_Perc() {

int myValue1 = analogRead(A0); //Automatically sets pin to analog input

Serial.printf(“\n\n\n\n\n”);

Serial.print("A0: ");

Serial.print(myValue1);

Serial.print(" Volts = ");

Serial.print(myValue1 / 3583.4);

//3583.4 came from ADC counts / Known Voltage = 3583.4

Serial.print( " Percent = ");

/****************************************************************************

  • Works through voltage divider 300k-47k to pin A0 except that with no

  • battery, A0 floats so random.

  • calculated 66% at 9.6 volts (measured) which I need to be 0 % left in

  • battery

    • Google says 10 cell ni-mh pack lowest charge b4 damage is .9v / cell,
  • 10 cells = 9 volts - so 9.6 for safety

    • Plus I had 9 volt battery which measured 9.6 volts actual.
  • use: 100-((100 - x) * y)

  • y is correction for scale 9 - 14.4 vs 0 100

  • x = calculated percentage

  • ie for 9.6v got 67% so 100 - ((100-67)*y

  • (100 - (33 * y) = 0

  • so 100/33= 3.03 results in 0 at 9.6v and 100 at 14.4v.

*/

//uint8_t i_perc = (((myValue1 / 3583.4) / 14.4) * 100 );

// == Calculated Percentage. 14.4 is my v at 100% charge

int i_perc = (((myValue1 / 3583.4) / 14.4) * 100 );

// == Calculated Percentage. 14.4 is my v at 100% charge

// so calc v / 14.4 * 100 = calc percent of 14.4 =

// ie 9.6/14.4 = .667 = 67%

i_perc = 100 - ((100-i_perc)*3.03);

//Adjust 0-100 percent to 67-100. 67 = calculated percent at 9.6 volts.

// ie: 100 - ((100-67)*3.03

// 100 - 33 *3.03

// 100 - 99.99 = 0.01 = 0 at 9.6 volts.

Serial.print(i_perc);

uint8_t valBatt = {(byte) 0x42, (byte) 0x00, (byte) i_perc};

//sends 42 00 46 (HEX) for 70 Percent calculated

valBatt[1] = i_perc>>8;

//Compiler warning if above is done during initialization as in next

// commented line, so set after initialization

//uint8_t valBatt = {(byte) 0x42, (byte) i_perc>>8, (byte) i_perc};

//sends 42 00 46 (HEX) for 70 Percent calculated

// 0x42 (HEX) is 66 (DEC) = uint8 = B for Battery

//amdtpsSendData(valBatt, 3);

TX_CHAR_UUID.writeValue(String(i_perc));

//Sending phone Hex for b 00 %% = uint8_t valBatt

// = {(byte)0x42,(byte)0x00,(byte)0x71};

Serial.println();

} //end get_Batt_Perc

There’s no hardware on the Artemis Nano for monitoring battery voltage but you could connect a voltage divider across the battery leads and then feed the output of that into an analog in pin to read the batteries output voltage and calculate the percentage charge.

The Artemis analog pins max out at 2 volts so you’d need a fully charged battery to output no more than 2 volts after going through the voltage divider. A voltage divider made with a 1.2 mega ohm resistor and a 1 mega ohm resistor would output about 1.91 volts on a fully charged LiPo, that would be just about perfect for checking battery charge status on the cheap. KHE’s code could be used for that and modified to work with a LiPo battery.

Another thing you could do would be to use a dedicated IC that monitors the battery and read data off that. [TOL-10617 would work for that.](SparkFun LiPo Fuel Gauge - TOL-20680 - SparkFun Electronics)

Thank you KHE and TS-Chris!