3.7V lithium batteries are commonly used in many projects. However, The remaining power and voltage of the lithium battery are highly nonlinear. We can only roughly judge whether the battery is full or almost empty according to its voltage. The Gravity 3.7V Lithium Battery Fuel Gauge employs Gravity I2C interface, ultra-low operating current, and real-time tracking of the relative state of charge (SOC) of the battery through Maxim's patented algorithm, eliminating the need for full-to-empty relearning and offset accumulation errors. Plug and play to accurately measure the voltage and remaining power of the battery. The module also features as a low battery power alert interrupt function. When the battery power falls below specified threshold, the ALR pin generates a falling pulse to trigger the external interrupt of the controller. You will find it a great help to estimate the battery life by learning the power consumption of the system with this module. In the solar powered projects, it helps to record the status of the battery power change in a day or even months, which benefits to understand the power balance of charge and discharge of the solar system.




Board Overview

Label Name Description
+ VCC Power VCC(3.3~6.0V)
- GND Power GND
C SCL I2C Clock Signal
D SDA I2C Data Signal
ALR ALRT* Low battery power alert interrupt (active low)
BAT IN Battery input 3.7V lithium battery connection port
REV BAT Battery reverse Indicator When the battery connection is reversed, REV BAT lights up.



Connection Diagram

Read Battery Voltage, Remaining Power and Set Low Power Interrupt Alert

Sample Code

 * file DFRobot_MAX17043.ino
 * connect gauge I2C interface with your board (please reference board compatibility)
 * Voltage, percentage will be printed via serial.
 * Use API to config alaram and sleep (please reference to the readme in lib)
 * Copyright   [DFRobot](, 2016
 * Copyright   GNU Lesser General Public License
 * version  V1.0
 * date  2018-3-26

#include "DFRobot_MAX17043.h"
#include "Wire.h"

#ifdef __AVR__
  #define ALR_PIN       2
  #define ALR_PIN       D2

#define PRINT_INTERVAL        2000
#define BAT_PERCENTAGE        32

DFRobot_MAX17043        gauge;
uint8_t       intFlag = 0;

void interruptCallBack()
  intFlag = 1;

void setup()
  attachInterrupt(digitalPinToInterrupt(ALR_PIN), interruptCallBack, FALLING);  //default alert is 32%

  while(gauge.begin() != 0) {
    Serial.println("gauge begin faild!");
  Serial.println("gauge begin successful!");
  //gauge.setInterrupt(BAT_PERCENTAGE);  //use this to modify alert threshold as 1% - 32% (integer)

void loop()
  static unsigned long lastMillis = 0;
  if((millis() - lastMillis) > PRINT_INTERVAL) {
    lastMillis = millis();

    Serial.print("voltage: ");
    Serial.println(" mV");

    Serial.print("precentage: ");
    Serial.println(" %");

  if(intFlag == 1) {
    intFlag = 0;
    Serial.println("Low power alert interrupt!");
    //put your battery low power alert interrupt service routine here


Raspberry Pi Tutorial


Connection Diagram


1.Start the I2C interface of the Raspberry Pi. If it is already open, skip this step. Open Terminal, type the following command, and press Enter:

 pi@raspberrypi:~ $ sudo raspi-config

Then use the up and down keys to select “5 Interfacing Options” -> “P5 I2C” and press Enter to confirm “YES”. Reboot the Raspberry Pi.

2.Installing Python libraries and git (networking required). If it is already installed, skip this step. In the Terminal, type the following commands, and press Enter:

pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git

3.Download the driver library and run it. In Terminal, type the following commands, and press Enter:

pi@raspberrypi:~ $ git clone
pi@raspberrypi:~ $ cd ~/DFRobot_MAX17043/RaspberryPi/python
pi@raspberrypi:~/DFRobot_MAX17043/RaspberryPi/python $ python

Read Battery Voltage, Remaining Power and Set Low Power Interrupt Alert

pi@raspberrypi:~/DFRobot_MAX17043/RaspberryPi/python $ cd readAndInt
pi@raspberrypi:~/DFRobot_MAX17043/RaspbeeryPi/python/readAndInt $ python


Application Examples

Build a Solar Power Management System

Gravity: 3.7V Li Battery Fuel Gauge can be used with the Solar Power Manager 5V to build a solar power management system. The battery fuel gauge can be used to monitor the charging of the battery with a solar panel in real time during the day, and the power consumption of the system during the night. Users can write their own code to record or print battery voltage and remaining power data, which can be employed to evaluate the "power balance" of the solar system in a day or even several months. These datum helps users to determine whether the nominal power of the panel or lithium battery power is large enough to fully support the entire system during the day and night.

The low power interrupt alert of the fuel gauge and controllable 5V power supply of the solar power management module can be used to save power when the battery power is lower than a specified threshold. The ALR pin will send an interrupt signal to trigger the controller to turn off the 5V power supply. This shuts off the power supply of external modules connected to the solar power module, and thus saves power.


For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents


For any questions, advice or cool ideas to share, please visit the DFRobot Forum.