USB Power Meter

Casually put together a small but rather fun project. I got curious about how much power my DIY gadgets actually consume—and at the same time, I wanted to check the real capacity of those AliExpress batteries. Sure, you could use a multimeter, but then you’d have to rig up some janky setup to wedge it into a USB cable, plus keep unplugging it whenever you need it elsewhere. And devices with microcontrollers have fluctuating power draw depending on their operating mode. So I built myself a dedicated device.

The idea is pretty straightforward. Two USB Type-C ports—one input, one output. The power flows through a 0.1 Ohm shunt resistor placed between them. Depending on the current flowing through the resistor, you’ll get a corresponding voltage drop across it, just as Ohm’s Law says.

A current sensor chip—INA213—is connected in parallel with the resistor. It amplifies the voltage drop by a factor of 50 and sends it to an analog-to-digital converter. In the first version of the device, I used the microcontroller’s built-in ADC, but just like in my radio project, the readings were all over the place. So I swapped it for a dedicated ADC—ADS1220. In the latest version of the device, I upgraded the microcontroller to a newer model, but kept the old ADC—it still works fine and gives better accuracy at 24-bit resolution. Added a bit of supporting circuitry and a simple OLED screen. That’s pretty much it. Oh, and a couple of buttons just in case, and a small EEPROM chip for future settings.

The measurement range is defined by the shunt resistance and the ADC’s reference voltage. In my case: a 0.1 Ohm resistor, 50x gain, and a 2.048V reference—gives a maximum current range of 409.6 milliamps. That’s less than what USB can handle, but more than enough for my DIY gear. And if it’s ever not enough, I can just swap in a 4.096V reference and double the range. There’s even space for it on the board.

It samples 1000 times per second. The precision takes a slight hit at that speed, but it’s worth it for catching short spikes—like when the display refreshes or data is transmitted over WiFi. Drew up the schematic over the weekend, then spent another couple of weekends assembling it and writing the code.

It’s really convenient to use—just plug in two USB cables and you’re good to go. Super happy with how it turned out.