I'm trying to create an extension cord capable of measuring the power draw of devices connected to it. My approach is using a microcontroller with a non-invasive HWTC current sensor. I am using an ADS1015 12-bit ADC which is capable of converting up to 3300 samples per second. The microcontroller is programmed so that it finds the highest voltage peak flowing through the sensor (as I am measuring AC) and then I am calculating the RMS current.
This is a simplified code running on my MCU:
/// Gets the peak voltage over the next 500 ms
/// \returns Peak voltage in mV
float getPeakVoltage(ADS1015& adc) {
Int16 maximum = 0;
const Ulong start = millis();
// Measure for 500 ms
while ((millis() - start) < 500) {
const Int16 value = adc.readDifferential();
if (value > maximum) {
maximum = value;
}
}
// 1 bit from ADC = 3mV
return static_cast<float>(maximum) * 3.0f;
}
const float peakVoltage = getPeakVoltage(adc);
// Using Ohm's law
static constexpr float resistorValue = 220.0;
const float peakCurrent = peakVoltage / resistorValue; // Sensor current ratio is 1000:1
const float powerDrawRms = 230.0 * peakCurrent * 0.707f; // in Watts
This approach works flawlessly for simple loads such as a Wolfram light bulb, however, when I connect, for example, a phone charger, it yields garbage. And by garbage, I mean way too high current draw.
Now I, unfortunately, don't have an oscilloscope to see what the waveform looks like, nonetheless, why my approach fails with different loads attached to the sensor?