Your calculation is a little confusing.
Could you add '(' and ')' around the multiplication, so it is clear that the multiplication is done first.
To solve your problem, go back one step.
Show the value of analogRead() on the serial monitor without the average.
I assume the heater is powered by the mains ? 110 or 240V AC ?
If so, you will read AC values, changing at 50Hz or 60Hz.
The average of a AC value will be zero.
You have to know what the numbers ".0264" and "-13.51" do, and explain that in the sketch. You can't write a good sketch if you don't know what those numbers are.
By the way, I have no idea what those numbers are, I would calculate the voltage of the analog input and use the sensitivity of the sensor in the sketch to calculate the current.
But I'm not really sure of what that -13.51 means, because I just got this from internet and just used.
Ok Erdin, just forget that -13.51. Just please tell me the way you follow if you want to measure the AC voltage using this sensor connected to arduino ?
The sensor(ACS712) is for -20 to 20A AC/DC measuring . And it shows 2.5V with no current flowing through the IC.
The output is somewhere in the middle.
So 2.5V with no current is good.
To measure the current with the 50Hz or 60Hz mains requires a lot of programming if you want to do it right.
Take a look at this: Home | OpenEnergyMonitor
You should find explanation about current measurement.
For a rough indication, you could find the minimum (negative current) and the maximum (positive current) during an interval (for example 100ms). They should be almost equeal to each other with an AC current and you could use that to calculate for example the rms value.
If you want to know an AC current, you have to do a number of samples and you need some calculation.
But I'm not really sure of what that -13.51 means, because I just got this from internet and just used.
Its -0.0264 x 512
That line:
average = average + (.0264 * analogRead(A3) -13.51) / 1000;
would be much clearer as
sum += 0.0264 * (analogRead(A3) - 512) ;
and take mean after the loop by dividing by the loop count.
But of course averaging an AC waveform is pointless - you want the rms value, hence something like:
float sum = 0;
for (int i = 0; i < N; i++) {
float current = 0.0264 * (analogRead(A3) - 512) ; // in amps I presume
sum += current * current ; // sum squares
// no delay, make sure N large enough to cover many waveforms.
}
float average = sqrt (sum / N) ; // root-mean of squares
Within the main code, there is a calibration ( we can set anything we want as that constant ) value to be put. Also they ask us to put the phase difference . So i'm confused because I don't really know which value I should put as PHASE DIFFERENCE ?
Further I hope to use this system for resistive loads such as water heaters and also for inductive loads such as motors.
My problem is, now the above published serial monitor output results have been obtained with NO LOAD connected . But still how it gives a value for apparent power ?
And can real power and power factor be NEGATIVE ?
I also tested connecting a purely resistive WATER HEATER as a load. But still the real power remains below 1, but apparent power goes high up to like 900. Im confused ?
Yes I did . Even I have gone through their website many times . But they haven't explained how to select a value for phase shift. But in their default example they have put the phase shift as 1.7 . And the Voltage Calibration as 234.6 . It somehow works, but not accurate. That's why I thought of changing the phase shift value.
May be its not needed to change the phase shift value. But I'm searching for a way to make this reading accurate.