Serial at 115200 baudTap a part to see what it does.
Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.
Build it step by step
0 of 4 doneCharge the cell
Through the TP4056 until its LED turns blue or green.
Put the meter in series
Cell output → INA219 VIN+ → VIN− → project.
Connect the Uno
INA219 SDA A4, SCL A5, shared ground.
Measure each mode
Let the ESP32 run its normal program for a few minutes and read the average.
How do you build a battery runtime estimator?
An INA219 measures how much current an ESP32 project really draws in each mode, and the sketch turns that into an expected runtime on an 18650 cell. You need ESP32 DevKit V1, INA219 Current Monitor, 18650 Li-ion cell, TP4056 Charging Module, Arduino Uno R3 and Breadboard 830 Tie Points. It takes 4 steps and about 60 minutes.
- Level
- Intermediate
- Time
- About 60 min
- Parts
- 6
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- PowerBuy
- PowerBuy
- Development BoardsBuyArduino Uno R3 × 1Runs the meter, so the ESP32 can be measured
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Cell + | TP4056 B+ (protected module), OUT+ → INA219 VIN+ | Power in |
| INA219 VIN− | ESP32 3V3 pin through a 3.3 V LDO, or VIN on boards rated for 3.7 V | Power to the project |
| All grounds | Common | Shared ground |
| INA219 SDA / SCL | Uno A4 / A5 | The Uno does the measuring |
Code
Library: Adafruit INA219. This sketch runs on the Uno (Uno has no printf, so it prints piece by piece). Let it run through several wake/sleep cycles of the ESP32 so the average is real. Runtime = usable mAh ÷ average mA.
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Adafruit_INA219.h>
Adafruit_INA219 ina;
const float CAPACITY_MAH = 2500 * 0.8; // use 80 % of the label for a realistic estimate
double mAs = 0; unsigned long t0;
void setup() { Serial.begin(115200); ina.begin(); t0 = millis(); }
void loop() {
float mA = ina.getCurrent_mA();
mAs += mA * 0.1;
static unsigned long last = 0;
if (millis() - last > 5000) {
last = millis();
float secs = (millis() - t0) / 1000.0;
float avg = mAs / secs;
Serial.print("now "); Serial.print(mA, 1); Serial.print(" mA, average "); Serial.print(avg, 1);
Serial.print(" mA, runtime about "); Serial.print(CAPACITY_MAH / avg, 1); Serial.println(" hours");
}
delay(100);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
now 120.4 mA, average 122.3 mA, runtime about 16.3 hours
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| ESP32 idle with Wi-Fi | Roughly 80 to 120 mA, runtime around a day |
| ESP32 in deep sleep between readings | Average falls to a few mA on a bare module; DevKit boards stay higher because of the USB chip and LED |
| Compare with the label | Estimate uses 80 % of the rated mAh |
If it does not work
Negative current
VIN+ and VIN− swapped.
Runtime far too long
Too short a measurement: include the Wi-Fi bursts.
ESP32 resets
Cell low or voltage drop through wires: charge it and shorten leads.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the battery runtime estimator?
ESP32 DevKit V1, INA219 Current Monitor, 18650 Li-ion cell, TP4056 Charging Module, Arduino Uno R3 and Breadboard 830 Tie Points. Arduino Uno R3: Runs the meter, so the ESP32 can be measured.
How long does the battery runtime estimator take to build?
About 60 minutes for a intermediate maker, in 4 steps.
How do I know the battery runtime estimator works?
ESP32 idle with Wi-Fi: Roughly 80 to 120 mA, runtime around a day. ESP32 in deep sleep between readings: Average falls to a few mA on a bare module; DevKit boards stay higher because of the USB chip and LED. Compare with the label: Estimate uses 80 % of the rated mAh.
Negative current: what should I check?
VIN+ and VIN− swapped.
Runtime far too long: what should I check?
Too short a measurement: include the Wi-Fi bursts.
ESP32 resets: what should I check?
Cell low or voltage drop through wires: charge it and shorten leads.
