Hello,
i'm trying to build energy cosmuption monitor for my home. here we have 220V@50Hz
i red about CT and bought some from sparkfun.
basically i read the voltage across some load resistor and from that i can calculate the secendory current (I=V/RLoad)
from the turn ratio (2000) i can deduce the primery current.
here is my code:
int SensorValue = 0;
int WireTurns = 2000; // the ratio between I primery and I secondary
int Num_of_Samp = 500;
int DelayMicros = 20000/Num_of_Samp; // 1/50Hz is 20ms period
float Rload = 2000.0/(float)WireTurns;
float volt = 0;
float RMS = 0;
float I=0;
void setup() {
Serial.begin(115200);
}
void loop() {
RMS = 0;
for (int ii=0;ii<Num_of_Samp;ii++){
SensorValue = analogRead(A0);
volt = 0.00489*SensorValue; // 5/1023 = 4.88mV
volt = volt-2.5;
volt = volt*volt;
RMS = RMS + volt;
delayMicroseconds(DelayMicros);
}
RMS = RMS/(float)Num_of_Samp;
RMS = sqrt(RMS);
I = RMS/Rload;
Serial.print("Max Voltage:");
Serial.print((RMS*1.44)+2.5);
Serial.print(" RMS current:");
Serial.print(I);
Serial.print(" Power cons.:");
Serial.println(I*220);
}
i read the voltage 500 times, calculate the square value and finaly after the loop ends i take the mean and then the square.
here is my problem:
i get different RMs current reading when using different resistors.
when using 5K ohm i get 0.16A and when using 2k ohm i get 0.22 A
anybody here tried doing something like this?
thanks,
Etay
If you want to calculate RMS current, you need to sample the voltage of the CT waveform many times over ONE cycle of the AC line, and calculate the RMS value from its definition, sqrt( (1/N) sum (V^2)). Then calculate the current from the RMS voltage value after scaling. You aren't calculating the average over one cycle because of all the floating point operations in the sampling loop, so the delay that you have built in to the code is not correct.
If you have the "Non-Invasive Current Sensor - 30A SEN-11005" from SparkFun, you need to be using a 10 ohm burden resistor. Depending on the primary current you are trying to sense, to get any accuracy at all you will probably also need an amplifier and/or precision rectifier circuit. One example of an amplifying precision rectifier that I've successfully used (which also eliminates the problem of fast sampling and calculating the RMS value) is below. This particular design requires a bipolar power supply, but it can be modified to use unipolar power supplies. The gain is about 40, and the response is quite linear over the range of primary AC currents 500 mA to 40 A with the specified CT, however calibration against known loads should be done in any case.
Hey Jremington,
Thanks for the advice. Actually I though this might the problem...
When using your propose circuit I'll get rectified signal so still I'll need to calculate RMS value so the loop will look the same no?
Thanks,
Eray
That circuit produces a DC voltage proportional to the peak value of the AC current. If the AC current is a sine wave, then the RMS value is the peak value divided by the square root of 2. The circuit has a time constant of about 1.6 seconds, so you could consider that to be the sample period.
O.k
Your circuit looks like integrator and rectifier is that right?
The capacitor and the 1.5k are the time constant of the integrator and the 1.5k and 62k is the amplification
Sorry, typo: the time constant is about 0.16 sec, which I got by simulating the circuit operation.
Here is how to calculate the time constant: Op amp integrator - Wikipedia
But beware, that does not figure in the diode properties.
The time constant is 1.5k*10u=15ms no?
You. Used the same circuit also for current sensing from 50 hz grid?
Shouldn't I aim exactly for 20ms I'm integration time?
Thanks very much for your help,
Etay
This circuit calculates the average peak value of the voltage from the current sensor, so there is no need to worry about integrating over exactly one cycle. For my application (60 Hz) the time constant was not particularly important, but if you want to measure the instantaneous power of the circuit, then you do need to choose the appropriate time constant. Of course you will have to measure the voltage as well.
Hello again,
i measured using scope the voltage on the shunt resistor and i was puzzled because the current is not sine wave!
you can see in the picture the wave form on the scope.
the problem with this wave form is that taking the peak and divide by sqrt of two wont give me the real rms value...
what do you think?
it seems i need to use some kind of rms to dc chip no?
thanks,
Etay
Measuring the peak is not accurate, given all the electronics people have in their
homes now the mains is far from a pure sine wave these days, to get RMS you have
to square-root the mean of the square...
Is this household AC?
What is the load that you are using to set current through the CT, what is the current and what is the value of the shunt resistor across the CT?
For tests of CTs, I like to use an ordinary tungsten light bulb, or a resistive room heater as the load. The rms current in amperes is approximately the rated power of the load in watts divided by the rms voltage.
etayl:
Now I have AD737 from analog digital. Do you some experience with it?
No sorry, have never used it but I did find the schematic shown below using one.
(You could dispense with Ra1 to Ra4 and connect the current transformer in place.
Just don't forget the burden resistor for the transformer and confirm with the datasheet of the AD737 if capacitor C1
is required to AC couple the input to the chip.
EDIT:
Just had a quick look over the AD737 and saw this:
The AD737 output is negative going; the AD736 is a positive output going version of the same basic device.
Hey UnoDueTre,
do you have some experience in rms do dc?
i just simulated the circuit you proposed with multisim software (attached picture of the circuit)
the output is very law and nos as expected.
do you know what seems to be the problem?
regarding your question, yes i know its negative. i think of using inverter to get it positive
thanks,
Etay
As I said before, I have never used that particular chip.
There are a few things you should check for first:
Pin 3 of the AD737 is "power down" (low=enabled, high=powered down) and I see it's floating in your sim.
I don't know how accurate your model of the AD737 is, but have you tried making it low?
Are you overloading the input to that chip?
In your simulation, replace V1 (the 0.5V 50Hz source) with a variable one.
Now do a sweep with say 20 points where at each point the input source generates say 1mV, 2mV, 5mV, .......,200mV, 500mV and look at the output for "flattening" which could be indicative of input saturation.
Hi UnoDueTre,
you are right.
i connected pin 3 to grond and reduced the peak of the sine wave to 100 mV but still same output of around 300mV
maybe something is wrong in the simulaiton. i'll try to connect the chip on breadboard see what happen
Etay