Arduino + Current Sensor -> Not always working

I am trying to measure power consumption of devices by using an TA12-200 power sensor with a Arduino Uno board.

This sensor is using a 800 ohms resistor and a 1:2000 ratio.

My measure to get mAh seem to be working when using it on ultra basic device like a 40W light bulb. But as soon as I try it on device that internally use DC like a LCD screen or a soup mixer, I get too high result comparing to my multimeter.

Here is my Arduino code to calculate the power consumption :

float KNPwrSwitch::GetPowerConsumption()
{
int sensorMax = 0;
uint32_t start_time = millis();

// Sample the max value for 1000 ms
while ((millis() - start_time) < 1000)
{

if (sensorValue > sensorMax)
sensorMax = sensorValue;
}

// Compute input voltage
float vIn = (sensorMax * 5.0) / 1024.0;
// Use Ohms law to compute intensity (A) (800ohms for TA12-200)
float intensity = (vIn / 800) * 1000.0;
// Use formula for SINE wave to convert to RMS
float rms = intensity * 0.707;

/*
Current Transformer Ratio is 2000:1...

Therefore current through 800 ohm resistor
is multiplied by 2000 to get input current
*/
float curThroughWire = rms * 2000;

if (DEBUG_MODE) { Serial.println("Power Consumption"); }
if (DEBUG_MODE) { Serial.println("-----------------"); }
if (DEBUG_MODE) { Serial.print("Volts Peak : "); }
if (DEBUG_MODE) { Serial.println(vIn, 3); }
if (DEBUG_MODE) { Serial.print("Current Through Resistor (Peak in A) : "); }
if (DEBUG_MODE) { Serial.println(intensity, 3); }
if (DEBUG_MODE) { Serial.print("Current Through Resistor (RMS in A) : "); }
if (DEBUG_MODE) { Serial.println(rms, 3); }
if (DEBUG_MODE) { Serial.print("Current Through Wire (mA) : "); }
if (DEBUG_MODE) { Serial.println(curThroughWire, 3); }

return (curThroughWire / 1000) * 230; // This is supposed to be my Watts / hour consumption
}

• Please show your schematic. What have you done to ensure the sensor is centered in your A/D range? – Jack Creasey May 30 '19 at 15:49
• You CANNOT connect the sensor directly to an A/D input port. It simply will not work. The sensor will produce a +/- signal if you ground one side of the sensor. It must be offset into the A/D range to work properly. – Jack Creasey May 30 '19 at 16:26
• – Jack Creasey May 30 '19 at 16:29
• In addition, Current Transformers DON'T WORK with DC currents. They are AC transformers and only work for AC currents. – Jack Creasey May 30 '19 at 16:36
• You just lucked out that you can measure (only one half) the AC current. Your configuration is not viable. You are using the intrinsic diodes in the Arduino MCU which YOU SHOULD NOT DO. The CT you have will ONLY do AC current. It will NOT do DC current. – Jack Creasey May 30 '19 at 17:15

Arduino + Current Transformer sensor

The CT is a conventional transformer in all ways, it only works for AC currents.

simulate this circuit – Schematic created using CircuitLab

If the input current is sinusoidal, then the output voltage will be sinusoidal. The CT will work for non-sinusoidal wave shapes, but then to maintain accuracy you must calibrate the unit.

The A/D input to an Arduino (or almost any other MCU) is uni-polar. In the case of a 5V Arduino, the signal range is 0-5V.

If you feed the CT output directly into the Arduino you have a circuit like this:

simulate this circuit

As you can see from above you only get to measure the positive half cycle of the CT output.
Providing the positive and negative peak currents are the same (in the load you are measuring) you will measure the correct peak current for half of the output. This is probably what confuses you since you measured a lightbulb and got somewhat correct results.

1. You are using the intrinsic diode in the Arduino MCU as a rectifier diode. YOU SHOULD NEVER EVER DO THIS!!!
2. You are only measuring current during one half of the AC cycle. This may be ok under some instances but is not a good design.

Read the document I pointed to on the OpenEnergyMonitor site and try to understand the reasoning behind this schematic:

In the schematic above, they provide a bias offset to the mid range of the A/D range, then connect the CT to allow you to measure BOTH positve and negative half cycle currents. This is the correct way (though there are many variations) to measure AC current.

There is no way to measure DC current with a CT (there actually is but it's very complicated) such as you have.
If you are measuring the AC current being used by an LCD power supply, then for most switching power supplies like this the peak current may be high and you are measuring all the losses included in the unit.
In the cases for devices that have non-sinusoidal AC currents you have to provide much higher resolution (number of conversions/second) of the AC current and calculate the power used based on a true RMS and Power Factor calculation. You cannot just measure the peak voltage out of the CT and expect to get accurate results.
This paper on calculating Power Factor with non-sinusoidal currents may help.

• First of all, thank you very much for your time. So if I understand, the grove component I am using only allow me to sense positive wave of my AC current. For the case of my light bulb it luckily work because the sinusoidal is perfectly regular (+/-). So retrieving the positive peak is enough to get accurate result. In the case of my LCD screen I effectively get much higher result that the reality. Probably because of the all the looses you are talking about. And what is a example of a non-sinusoidal AC device ? my LCD screen ? – Karnalta May 30 '19 at 19:22
• You should NOT continue to operate your Arduino in the manner you are. You may well damage it. The sensor you have WILL work for both positive and negative half cycles, but you need to alter the circuit. – Jack Creasey May 30 '19 at 21:34
• I have added a answer to my own question and tried to summarize what I needed to do. – Karnalta May 31 '19 at 8:26

Based on what Jack explained to me and the links he provided me. I ended up with these modifications to solve my problem.

I am going to unweld a TA12-200 from theses Grove circuits and use it on my own with the following schematic :

And in my code I will try to compute the power factor to be able to make a correct estimation of switching power devices consumption.

My project is aimed at Computer / Server consumption monitoring.