Projects / USB energy meter

USB energy meter

Beginner45 minGuided buildReviewed
Arduino UnoA4A5GNDINA2195.02V 450mAafter 10 min1602 LCD

Tap 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 done
  1. UNOINA219USB1.64 A

    Join the USB breakouts

    VBUS through the INA219, grounds straight through.

  2. UNOINA2191.64 A1602

    I2C bus

    INA219 and LCD both on A4 and A5.

  3. UNO

    Upload

    Power the Uno from your computer.

  4. UNO

    Measure a gadget

    Charge a phone for 10 minutes and note the mWh.

In short

How do you build an USB energy meter?

An INA219 between two USB-C breakouts measures volts, milliamps and the total milliwatt-hours a USB gadget uses, shown live on a 1602 LCD. You need Arduino Uno R3, INA219 Current Monitor, 1602 Character LCD, USB-C Breakout Board × 2 and Breadboard 830 Tie Points. It takes 4 steps and about 45 minutes.

Level
Beginner
Time
About 45 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
USB-C in VBUSINA219 VIN+5 V from the charger
INA219 VIN−USB-C out VBUSTo the gadget
Both USB GNDUno GNDShared ground
INA219 and LCD SDA / SCLUno A4 / A5Same I2C bus (0x40 and 0x27)

Code

Libraries: Adafruit INA219 and LiquidCrystal I2C. The usual 0.1 Ω shunt reads up to about 3.2 A, enough for most USB gadgets. 1 kWh = 1,000,000 mWh.

Runs on a virtual Arduino Uno 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>
#include <LiquidCrystal_I2C.h>
Adafruit_INA219 ina;
LiquidCrystal_I2C lcd(0x27, 16, 2);
double mWh = 0; unsigned long last;

void setup() { ina.begin(); lcd.init(); lcd.backlight(); last = millis(); }

void loop() {
  float v = ina.getBusVoltage_V(), mA = ina.getCurrent_mA();
  unsigned long now = millis();
  mWh += v * mA * (now - last) / 3600000.0;
  last = now;
  lcd.setCursor(0, 0); lcd.print(v, 2); lcd.print("V "); lcd.print(mA, 0); lcd.print("mA    ");
  lcd.setCursor(0, 1); lcd.print(mWh, 1); lcd.print(" mWh         ");
  delay(250);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Nothing plugged inAbout 0 mA
Small fan or LED lampSteady current, mWh rising
Phone chargingSeveral hundred mA at about 5 V (fast-charge chargers may stay at 5 V without data lines)

If it does not work

Gadget does not charge

The charger needs the CC resistors on the breakout, and fast charging needs D+ and D−.

Negative mA

VIN+ and VIN− swapped.

LCD shows blocks

Turn the contrast trimmer.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the USB energy meter?

Arduino Uno R3, INA219 Current Monitor, 1602 Character LCD, USB-C Breakout Board × 2 and Breadboard 830 Tie Points. 1602 Character LCD: With the I2C backpack. USB-C Breakout Board × 2: One in from the charger, one out to the gadget.

How long does the USB energy meter take to build?

About 45 minutes for a beginner maker, in 4 steps.

How do I know the USB energy meter works?

Nothing plugged in: About 0 mA. Small fan or LED lamp: Steady current, mWh rising. Phone charging: Several hundred mA at about 5 V (fast-charge chargers may stay at 5 V without data lines).

Gadget does not charge: what should I check?

The charger needs the CC resistors on the breakout, and fast charging needs D+ and D−.

Negative mA: what should I check?

VIN+ and VIN− swapped.

LCD shows blocks: what should I check?

Turn the contrast trimmer.