Mbili rev 6b: read the battery voltage level

Hi gabriel,

i write this simple code to measure the voltage of battery of mbili rev 6b.

#define ADC_AREF 3.3
#define BATVOLT_R1 4.7
#define BATVOLT_R2 10

void setup() {

void loop() {
// put your main code here, to run repeatedly:

float getRealBatteryVoltage() {
  uint16_t batteryVoltage = analogRead(BATVOLTPIN);
  return (ADC_AREF / 1023.0) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * batteryVoltage;

I have any question:

  1. pin A6 is correct to measure the level of lipo battery ? I do not have to connect any wire?
  2. i read (with battery and usb connected) always 4.22 Volt. Is correct?
  3. What is the minimum voltage level to declare the exhausted battery or fully charged?
  4. is it possible to know also the level of current coming from the solar panel?
  5. where can I find a lib written by you on battery level management for sodaq mbili rev 6b ?


Here is the schematic for the Mbili Rev 6b: http://support.sodaq.com/wp-content/uploads/2016/08/sodaq_mbili_rev6b_sch.pdf

  1. If you look in the JST section you can see that A6 is connected to the voltage divider using the same resistor values as in that code.
  2. Both the USB and the Solar Panel will charge the LiPo battery. When either is attached you will read either the charge voltage or the battery voltage, whichever is greater.
  3. This will depend on the specifications of that attached battery and the requirements of whatever components you are using. For instance the Mbili MCU runs at 3.3v, but the GPRSbee I believe requires a minimum of 3.5v. You may start running into issues once the voltage drops below 3.7v.
  4. You will need an additional hardware to measure this.
  5. There is no library for this. The only code you really need is the function above which measures the voltage level.


  1. wich hardware?

You could use a breakout board such as this one to measure the current: https://www.sparkfun.com/products/8883

Alternatively, you could approximate the charge current by measuring the voltage coming off of the solar panel. Due to the Mbili operating at 3.3V levels, you will not be able to attach the solar panel directly to an analog input, you will need to use a voltage divider to reduce the voltage to with the acceptable input range.