Calculating RMS Voltage and Current to get Reactive Power and Real Power

Good Day,

I am trying to make my own Watt and VAR meter using Arduinos and transformers. I have very little knowledge on programming.

My Arduino is to use the ADC pins to measure the voltage and current signals. The line voltages are directly connected to a breadboard. See attached drawing if needed, regarding on the bread board layout. If I subtract 512 from ADC value, the value will be zero when the voltage/current is 0, and positive when the voltage/current are positive, and negative when current and voltages are negative.

The CT and PT are used to step down the line ratings to a safer level for the inputs of the Arduino. There is a reference shifter that is directly connected to the secondary turns of the transformers. Originally, the reference is zero volts, and by injecting a DC voltage of 5 volts, the waveform that is input to the Arduino is shifted up by 2.5 V.

I want 100 samples, and my frequency is 60 Hz. Voltage RMS and Current RMS are used to determine Real Power and Reactive Power.

Vrms = squareroot((sample1^2 + Sample 2^2 +… +Sample100^2)/100)
It is also the same for Irms.

The two values are used to Calculate real power:
P= 1/100 (V1 x I1 + V2x I2 + V3 xI3…+ V100 x I100)

Reactive is calculated using the power triangle:
Q=squareroot ((apparentpower^2) - (realpower^2))

Apparent Power = Vrms x Irms

The output will be sent to a meter ( Duty Cycle )
0-512 Bits will move the meters to a +ve value and 512-1023 will move the meters to a -ve value

arduino.ino (2.54 KB)

Please note that the '^' operator in C and C++ is bitwise exclusive-or, not exponentiation. To square a number X, use X*X, not X^2.

OpenEnergyMonitor.org is a good resource for monitoring AC devices.