Simple power usage monitor with just a split-coil current transformer and a ATtiny45 microcontroller.
To use this USB power usage monitor simply clamp a split-coil current transformer like the SCT013-000 in the picture onto the electric cable to be measured.
The current transformer generates a current in the secondary coil that is proportional to the current going through the primary coil which is proportional to the apparent power usage assuming a resistive load.
The challenge is to measure the current and make it available through USB. The first step is to convert the current to a voltage by connecting a load resistor to the secondary coil. The result is an AC voltage.
The trick is to take many samples and calculate the average of the absolute values.
The bipolar differential ADC of the ATtiny45 microcontroller can handle this without additional hardware. And connecting it to USB is very simple thanks to the V-USB project. Only three resistors and a decoupling capacitor are needed.
The rest is done in firmware. Not even an external crystal or resonator is needed as the internal RC oscillator is used. It is calibrated by the firmware at power up.
The firmware samples during approx. 200 ms, i.e. 10 waves @ 50 Hz. The sum of the samples is divided by the number of samples (approx. 1600) to achieve the average voltage. This is proportional to the RMS voltage which is proportional to the current and therefore to the power usage.
On the host a command line tool called tinysct retrieves the result from the microcontroller through USB.
All documentation (e.g. how to calculate the load resistor), firmware, command line tool and schematics are available in this repository.