Batteries: watch polarity, use protected cells and a charger with protection, never charge damaged cells unattended.
A bench tool that pays for itself in an evening
This is the simplest of the power ideas, and the one you will actually use again and again: put it in series with a power bank, a solar panel, a car charger or a strip of LEDs and read volts, amps and watts on the screen. After that the web page adds a watt-hour counter that you reset with a button.
Limits to remember
With the default 0.1 Ω shunt the INA219 measures up to about 3.2 A and up to 26 V. Above that the chip is out of range, and a spike of a 12 V inductive load can damage it. The meter measures on the high side, so the load ground and the ESP32 ground are common.
A cheap USB cable adds its own resistance; measure at the load connector, not at the source.
Dim or blank the OLED after a minute. Static text burns the pixels in a few months of continuous use.
For currents in the tens of amps, build the battery monitor idea with an external shunt instead.
Components
ESP32 DevKit V1 (30 pin, WROOM-32)
INA219 current/voltage sensor module
OLED 0.96" 128x64 I2C SSD1306
Dupont jumper wires (M-F, M-M)
Wiring
Module
Module pin
ESP32 pin
Note
INA219 + OLED SDA / SCL
I2C
GPIO21 / GPIO22
different addresses, shared bus
INA219 Vin+ / Vin-
shunt
supply + → load +
up to 26 V / 3.2 A
Libraries
Adafruit INA219
Adafruit SSD1306
Adafruit GFX
Code
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <Adafruit_SSD1306.h>
Adafruit_INA219 ina;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
double wh = 0; uint32_t last = 0;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
ina.begin();
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
last = millis();
}
void loop() {
float v = ina.getBusVoltage_V(), a = ina.getCurrent_mA() / 1000.0, w = v * a;
uint32_t now = millis(); wh += w * (now - last) / 3600000.0; last = now;
oled.clearDisplay(); oled.setTextColor(WHITE); oled.setTextSize(2);
oled.setCursor(0, 0); oled.printf("%.2f V", v);
oled.setCursor(0, 20); oled.printf("%.3f A", a);
oled.setCursor(0, 40); oled.printf("%.1fW %.2fWh", w, wh);
oled.display();
delay(500);
}
Build tips
The module handles up to 26 V and 3.2 A; use an external shunt for more current.
Place the INA219 on the positive (high) side of the load.
Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.
Comments
No comments yet. Share your experience or ask a question.