Knowing exactly how much charge remains in your battery is essential for reliable portable projects. A battery fuel gauge does more than just read voltage – it tracks coulombs in and out, accounting for discharge rate and temperature. This guide covers building an accurate fuel gauge with Arduino using the INA219 module.
Voltage Alone Is Unreliable
A lithium-ion cell’s voltage-to-capacity relationship is non-linear and changes with discharge rate, temperature, and cell age. A cell at 3.7V might be at 50% capacity under light load but only 30% under heavy load. The voltage also rebounds when load is removed, making instantaneous voltage readings misleading. This is why smartphones use dedicated fuel gauge ICs rather than simple voltage measurement.
Coulomb Counting Explained
Coulomb counting integrates current over time to track energy entering and leaving the battery. If the battery starts at 100% and you measure 500mA flowing out for 2 hours, you have used 1000mAh. Subtract that from the cell’s known capacity to get remaining percentage. The INA219 module provides both voltage and current measurements over I2C, making it ideal for this purpose.
Price: ₹86
Precise I2C current/voltage sensor for fuel gauge projects
Buy on Zbotic.in
Price: ₹69
1S LED battery indicator – simple plug-and-play
Buy on Zbotic.in
INA219 Current and Voltage Sensor
The INA219 is a bi-directional current and voltage monitor that communicates via I2C. It measures voltage (0-26V) and current (up to ±3.2A in default configuration) with 12-bit resolution. With a 0.1-ohm shunt resistor on the module, it can detect currents as small as 0.1mA while handling up to 3.2A.
Arduino Fuel Gauge Circuit
Connect the INA219 in the high-side (positive path) of your battery circuit:
- Battery positive → INA219 VIN+ → INA219 VIN- → Load positive
- Battery negative → Load negative
- INA219 SDA → Arduino A4, INA219 SCL → Arduino A5
- INA219 VCC → Arduino 5V (or 3.3V), GND → Arduino GND
Arduino Code for Fuel Gauge
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
float batteryCapacity_mAh = 2200.0; // Your cell's rated capacity
float consumedMah = 0;
unsigned long prevTime;
void setup() {
Serial.begin(9600);
ina219.begin();
prevTime = millis();
}
void loop() {
float voltage = ina219.getBusVoltage_V();
float current = ina219.getCurrent_mA();
unsigned long now = millis();
float hours = (now - prevTime) / 3600000.0;
consumedMah += current * hours;
prevTime = now;
float remaining = batteryCapacity_mAh - consumedMah;
float percent = (remaining / batteryCapacity_mAh) * 100.0;
percent = constrain(percent, 0, 100);
Serial.print(voltage, 2); Serial.print("V ");
Serial.print(current, 1); Serial.print("mA ");
Serial.print(percent, 1); Serial.println("%");
delay(500);
}
Price: ₹71
3S battery indicator for 11.1V-12.6V packs
Buy on Zbotic.in
Price: ₹54
Universal 1S-8S indicator for any pack configuration
Buy on Zbotic.in
Displaying Battery Percentage
For visual feedback, connect an OLED display or LED bar graph. A simple 4-LED indicator can show: Green (75-100%), Yellow-Green (50-75%), Orange (25-50%), Red (0-25%). For OLED, display voltage, current draw, percentage, and estimated remaining runtime (remaining mAh / current draw).
Pre-Built Indicator Modules
If you prefer a ready-made solution, LED battery capacity indicator modules are available that simply connect in parallel with your battery and show charge level using LEDs:
Frequently Asked Questions
How accurate is coulomb counting?
With an INA219 and well-calibrated battery capacity value, accuracy is within 5-10%. Errors accumulate over time due to self-discharge and measurement drift. Reset to 100% when you detect the charging voltage (4.2V with near-zero current) and to 0% at the cutoff voltage.
Can I use a simple voltage divider instead of INA219?
A voltage divider can only measure voltage, not current. You get a rough charge estimate but cannot account for load-dependent voltage sag. The INA219 at ₹86 is well worth the investment for accurate fuel gauging.
What about dedicated fuel gauge ICs like MAX17043?
The MAX17043 uses a model-based approach (ModelGauge) that estimates capacity from voltage patterns rather than coulomb counting. It is more accurate for specific cell types but harder to source in India and requires no shunt resistor.
Ready to Power Your Next Project?
Browse our complete range of batteries, power supply modules, and charging accessories at Zbotic.in
Add comment