Fundamentals 4 min read

Real‑Time Battery Monitoring with MAX17048 and ESP8266 via MQTT

This tutorial shows how to use a MAX17048 fuel‑gauge module with an ESP8266 (or ESP32) to read voltage, state‑of‑charge and charge‑rate of a 18650 Li‑ion cell, wire the hardware correctly, calibrate the sensor, and publish the data in real time through MQTT for remote monitoring.

Black & White Path
Black & White Path
Black & White Path
Real‑Time Battery Monitoring with MAX17048 and ESP8266 via MQTT

Module Overview

The MAX17048 is a low‑cost, high‑accuracy fuel‑gauge designed for 3.7‑4.2 V Li‑polymer/ion cells. It provides real‑time voltage, state‑of‑charge (SOC), and charge/discharge rate readings. Two JST 2‑pin connectors allow simultaneous connection of the battery and a load/charger without additional switching circuitry.

Hardware Required

ESP8266 or ESP32 development board

MAX17048 module

18650 lithium‑ion cell (parallel connection only, never series)

Wiring Connections

Connect the ESP8266 pins to the MAX17048 as follows:

3.3 V → 3.3 V

GND → GND

D1 → SCL

D2 → SDA

Observe correct polarity; reversing the battery leads can damage the board.

Wiring diagram
Wiring diagram

Core API (Open‑Source)

Project repository: https://github.com/Priess0503/MQTT_18650_MAX17048

// Basic reads
float cellVoltage();   // battery voltage (V)
float cellPercent();   // SOC (%)
float chargeRate();    // charge/discharge rate (%/hr)

// Initialization
bool begin();
uint8_t getChipID();

// Power‑saving
void hibernate();
void wake();
bool isHibernating();

// Alerts
void setAlertVoltages(float minV, float maxV); // voltage thresholds
uint8_t getAlertStatus();
bool isActiveAlert();

MQTT Payload Example

{
  "voltage": 3.251,
  "soc": 18.5,
  "rate": -5.23,
  "state": "Discharging"
}

The rate field comes from the CRATE register; a negative value (e.g., -5.23%/hr) indicates the battery is discharging at 5.23 % per hour, while a positive value indicates charging.

Calibration and First‑Use

Before the first reading, fully charge the cell to 4.2 V. This triggers the quickStart routine, which calibrates the SOC value.

Calibration diagram
Calibration diagram

Verification

In a test the voltage read via MQTT was 4.13 V and SOC 91.8 %. A multimeter measurement confirmed these values, demonstrating the accuracy of the MAX17048 readings. With MQTT configured, battery status can be observed remotely at any time.

Multimeter verification
Multimeter verification
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

IoTEmbeddedMQTTBattery MonitoringESP8266MAX17048
Black & White Path
Written by

Black & White Path

We are the beacon of the cyber world, a stepping stone on the road to security.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.