Is there anyone to help me? about ARduino

Hi good evenings
i have some question about Arduino cod
i am trying to make some measure AC currents and volts
but here i cant get pretty quilty of curretns value of Sine graphs…
is there anything to get signwave…???

#include “EmonLib.h”

EnergyMonitor emon1;

const int analongln = A15;

float sensor_vol_1 = 0;
float sensor_cur_1 = 0;
float v_Out_1;
float I_out_1;

float delta_I;

void setup()
{
Serial.begin(9600);
Serial.println(“CLEARDATA”);
Serial.println(“LABLE,Time,V1,I1,V2,I2,V3,I3”);
// emon1.current(1, 111.1);

}

void loop()
{
// double Irms = emon1.calcIrms(1480);
Serial.print(“DATA,TIME,”);
// Serial.print(Irms*220);
// Serial.print(",");
// Serial.print(Irms);
// Serial.print(",");

sensor_vol_1 = analogRead (A15);
v_Out_1 = 18*((220*(sensor_vol_1/1024))-73.3) ;

sensor_cur_1 = analogRead (A1);
I_out_1 = sensor_cur_1-341;

delta_I = (I_out_1) - (I_out_3);

// Serial.print (“vOut_1 = “);
Serial.print (v_Out_1);
//Serial.print(“V”);
//Serial.print(” “);
Serial.print(”,”);

//Serial.print (“Iout_1 = “);
Serial.print(I_out_1);
//Serial.println(“A”);
Serial.print(”,”);

//Serial.print (“vOut_2 = “);
Serial.print (v_Out_2);
//Serial.print(“V”);
//Serial.print(” “);
Serial.print(”,”);

//Serial.print (“Iout_2 = “);
Serial.print(I_out_2);
//Serial.println(“A”);
Serial.print(”,”);

//Serial.print (“vOut_3 = “);
Serial.print (v_Out_3);
//Serial.print(“V”);
//Serial.print(” “);
Serial.print(”,”);

//Serial.print (“Iout_3 = “);
Serial.print(I_out_3);
//Serial.println(“A”);
Serial.println(”,”);

//Serial.print("delta_I = ");
//Serial.println(delta_I);

delay(800);
}

You will not be able to get a good quality sine wave doing it that way. The “Serial.print(…)” statements take far too much time and so the readings are too far apart.

The only way you will do it will be to read the analog values and store them, then print after you have collected as many as you need.
Robin Emley, who designed the MK2PVRouter, has a sketch on his website to do this:
Look at Mk2PVRouter - Downloads, and find “Test sketch for the voltage & current sensors”
And a little lower on the page is a text file showing what to expect: “Typical results file from V & I sensors”

You will need to change the input pin numbers, when you do that, it should work for you.

1 Like

Hi,
If you don’t want to miss any inputs, then it’s getting somehow more complicated.
You’ll have to perform the analogRead in a Interrupt Service Routine, collect the data, and print them asynchronously. There’re some sample too on Robin’s site, or you can take a look on my re-worked sketch for 3-phase current/voltage reading.https://github.com/FredM67/PVRouter-3-phase

oh thanks! robert!!
may i can get https://www.mk2pvrouter.co.uk/downloads/
this link again?
i cant access it …
they say there is 403 errors…

Sorry - I forgot the .html :dizzy_face:
https://www.mk2pvrouter.co.uk/downloads.html

You could have gone to the home page: https://www.mk2pvrouter.co.uk

hi robert another question
i try use code that you told me

i got this code but i cant understand what is this mean
i want sine wave of currents and voltage but
in that code i dont know what this means

-------------------------------------
Sketch ID:      RawSamplesTool_2chan.ino

>>free RAM = 7077
millis() now = 5040
recordingMayStartAt 10040
4
4
4
4
3
3
3
3
3
3
3
2
2
2
2
2
2
1
1
1
1
1
1
1
0
0
0
0
0
0
No of cycles recorded = 1
cycleCount 1502,  samplesRecorded 13
|                                     1v.                                       |
|                                     1v.                                       |
|                                     1v.                                       |
|                                     1v.                                       |
|                                    1 v.                                       |
|                                    1 v.                                       |
|                                    1 v.                                       |
min_V1 505,  max_V1 506
min_I1 482,  max_I1 497

Raw data from stored cycle: <Vsample>, <I1sample>, <I2sample>[cr]
13, <<< No of sample sets
506, 497, 505, 496, 505, 494, 505, 493, 505, 492, 505, 491, 505, 489, 505, 486, 505, 484, 505, 483, 505, 483, 505, 482, 505, 482

i used this code

#define POSITIVE 1
#define NEGATIVE 0
#define CYCLES_PER_SECOND 50

byte sensorPin_V1 = 15;
//byte sensorPin_V2 = 14;
//byte sensorPin_V3 = 13;
byte sensorPin_I1 = 1;
//byte sensorPin_I2 = 2;
//byte sensorPin_I3 = 3;

long cycleCount = 0;
int samplesRecorded = 0;

byte polarityNow; 
boolean beyondStartUpPhase = false;

int lastSample_V1;     // stored value from the previous loop (HP filter is for voltage samples only)         
float lastFiltered_V1;  //  voltage values after HP-filtering to remove the DC offset
byte polarityOfLastSample_V1; // for zero-crossing detection
  
boolean recordingNow;
boolean recordingComplete;
byte cycleNumberBeingRecorded;
byte noOfCyclesToBeRecorded;

unsigned long recordingMayStartAt;
boolean firstLoop = true;
int settlingDelay = 5; // <<---  settling time (seconds) for HPF 

char blankLine[82];
char newLine[82];
int storedSample_V1[100]; 
int storedSample_I1[100];
//int storedSample_I2[100];

void setup()
{  
  delay(5000); // allow time for the Serial Window to be opened
  Serial.begin(9600);
  Serial.println();
  Serial.println("-------------------------------------");
  Serial.println("Sketch ID:      RawSamplesTool_2chan.ino");
  Serial.println();
 
  // initialise each character of the display line
  blankLine[0] = '|';
  blankLine[80] = '|';
  
  for (int i = 1; i < 80; i++) {
    blankLine[i] = ' '; }  
  blankLine[40] = '.';
  
  Serial.print(">>free RAM = ");
  Serial.println(freeRam());  // a useful value to keep an eye on
}



void loop() // each iteration of loop is for one set of measurements only
{
  if(firstLoop)
  {
    unsigned long timeNow = millis();
    Serial.print ("millis() now = ");
    Serial.println (timeNow);
    
    recordingMayStartAt = timeNow + (settlingDelay * 1000);
    Serial.print ("recordingMayStartAt ");
    Serial.println (recordingMayStartAt);
    
    recordingNow = false;
    firstLoop = false;
    recordingComplete = false;
    noOfCyclesToBeRecorded = 1; // more array space may be needed if this value is >1 !!!
    cycleNumberBeingRecorded = 0;
    samplesRecorded = 0;    
  }
  
  int sample_V1 = analogRead(sensorPin_V1); 
  //int sample_V2 = analogRead(sensorPin_V2);
 // int sample_V3 = analogRead(sensorPin_V3);
  int sample_I1 = analogRead(sensorPin_I1);   
 // int sample_I2 = analogRead(sensorPin_I2); 
 // int sample_I3 = analogRead(sensorPin_I3);
  
  float filtered_V1 = 0.996*(lastFiltered_V1 + sample_V1 - lastSample_V1); 

  byte polarityOfThisSample_V1;
  if(filtered_V1 > 0)
  {
    polarityOfThisSample_V1 = POSITIVE;
    
    if (polarityOfLastSample_V1 != POSITIVE) 
    {
      // This is the start of a new mains cycle
      cycleCount++; 
         
      if (recordingNow == true) {
        if (cycleNumberBeingRecorded >= noOfCyclesToBeRecorded) {
          Serial.print ("No of cycles recorded = ");
          Serial.println (cycleNumberBeingRecorded);      
          dispatch_recorded_data(); } 
        else {
          cycleNumberBeingRecorded++; } }    

      else
      if((cycleCount % CYCLES_PER_SECOND) == 1) {  
        unsigned long timeNow = millis();   
        if (timeNow > recordingMayStartAt) {
           recordingNow = true;
           cycleNumberBeingRecorded++; } 
        else  {
          Serial.println((int)(recordingMayStartAt - timeNow) / 1000); } }    
    } // end of specific processing for first +ve reading in each mains cycle
    
  } // end of specific processing of +ve cycles
  else
  {
    polarityOfThisSample_V1 = NEGATIVE; 
  }
  
  if (recordingNow == true)
  {
    storedSample_V1[samplesRecorded] = sample_V1;
    storedSample_I1[samplesRecorded] = sample_I1;
//    storedSample_I2[samplesRecorded] = sample_I2;
  //  storedSample_I3[samplesRecorded] = sample_I3;
    samplesRecorded++;
  }
    
  polarityOfLastSample_V1 = polarityOfThisSample_V1;  
  lastSample_V1 = sample_V1;                       
  lastFiltered_V1 = filtered_V1;                  
} // end of loop()


void dispatch_recorded_data()
{      
  // display raw samples via the Serial Monitor
  // ------------------------------------------ 

  Serial.print("cycleCount ");
  Serial.print(cycleCount);
  Serial.print(",  samplesRecorded ");
  Serial.println(samplesRecorded);

  int V1, I1, I2, I3 ;
  int min_V1 = 1023, min_I1 = 1023, min_I2 = 1023, min_I3 = 1023;
  int max_V1 = 0, max_I1 = 0, max_I2 = 0, max_I3 = 0;

  for (int index = 0; index < samplesRecorded; index++) 
  {
    strcpy(newLine, blankLine);
    V1 = storedSample_V1[index]; 
    I1 = storedSample_I1[index]; 
   // I2 = storedSample_I2[index]; 
   // I3 = storedSample_I2[index]; 

    if (V1 < min_V1){min_V1 = V1;}
    if (V1 > max_V1){max_V1 = V1;}
    if (I1 < min_I1){min_I1 = I1;}    
    if (I1 > max_I1){max_I1 = I1;}
   // if (I2 < min_I2){min_I2 = I2;}
   // if (I2 > max_I2){max_I2 = I2;}
  //  if (I3 < min_I3){min_I3 = I3;}
  //  if (I3 > max_I3){max_I3 = I3;}

    newLine[map(V1, 0, 1023, 0, 80)] = 'v'; 
    newLine[map(I1, 0, 1023, 0, 80)] = '1'; 
   // newLine[map(I2, 0, 1023, 0, 80)] = '2'; 
   // newLine[map(I3, 0, 1023, 0, 80)] = '3'; 

    if ((index % 2) == 0) // change this to "% 1" for full resolution
    {
      Serial.println(newLine);
    }
  }
    
  Serial.print("min_V1 ");  Serial.print(min_V1);
  Serial.print(",  max_V1 ");  Serial.println(max_V1);
  Serial.print("min_I1 ");  Serial.print(min_I1);
  Serial.print(",  max_I1 ");  Serial.println(max_I1);
 // Serial.print("min_I2 ");  Serial.print(min_I2);
//  Serial.print(",  max_I2 ");  Serial.println(max_I2);
//  Serial.print("min_I3 ");  Serial.print(min_I3);
 // Serial.print(",  max_I3 ");  Serial.println(max_I3);

  Serial.println();
      
  // despatch raw samples via the Serial Monitor 
  // ------------------------------------------- 
      
  Serial.println("Raw data from stored cycle: <Vsample>, <I1sample>, <I2sample>[cr]");
  Serial.print(samplesRecorded);
  Serial.println(", <<< No of sample sets");

  for (int index = 0; index < samplesRecorded; index++) 
  {
    Serial.print (storedSample_V1[index]); 
    Serial.print(", "); 
    Serial.print (storedSample_I1[index]);  
    Serial.print(", "); 
//    Serial.println (storedSample_I2[index]);  
  }

  recordingNow = false;
  firstLoop = true;
  pause();
}      

void pause()
{
  byte done = false;
  byte dummyByte;
   
  while (done != true)
  {
    if (Serial.available() > 0)
    {
      dummyByte = Serial.read(); // to 'consume' the incoming byte
      if (dummyByte == 'g') done++;
    }
  }    
}

int freeRam () {
  extern int __heap_start, *__brkval; 
  int v1; 
  return (int) &v1 - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

When you post code, put 3 backticks ( ``` ) on a line before the code, and the same after.
I have edited your post.

4… 3… 2… 1… 0… is telling you when the recording will start.

It is telling you that you do not have a measurable voltage on the voltage input - the analogue value read at the input varied between 505 and 506, and you have a very small current on the current input - he analogue value read at the input varied between 482 and 497.

This will affect how your program works - your electricity supply is 60 Hz. You should change that.

I think it does not have enough voltage to know when to start and stop recording.

When you have the correct inputs, you should see a graph like this one “Typical results file from V & I sensors” you can download from www.mk2pvrouter.co.uk/downloads.htm

oh and if i connect enough Voltage…
is that correct that ican get sine wave
of V,I and using Serial flotter

i really appreciate your help Robert :slight_smile:

I thought you had a voltage input, because in your original sketch:

If you only want to draw the current wave, then you can try to use the “voltage” pin for current!

BUT The sketch is designed to monitor and draw the graphs for one voltage and two currents - that is what Robin’s Mk2PVRouter uses. There is always a nearly-constant alternating voltage, normally it is only the two currents that change greatly.

If you use the voltage pin for current, there must still be enough current for it to detect the start and end of the wave.

It will be better if you have a voltage input.

Thanks for your help!
i can finally extract sine wave!!
Really thanks for your help

and is it okay ask some question??
now then we are trying to measure Phase and Active power and Realtice Power and so on
is there any good code that i can studay about it?
i already study emon.library!!

in my opinion…

countDelta = abs(total_I - total_V)

Phase = countDelta * 360 / 75 // idont know why 75…
PowerFactor =abs(cos( phase / 180* 3.1459));

ActivePower = total_I * total_V * PowerFactor

this is my code >>>

-----------------------------------------------------------------------------------
const unsigned int numReadings = 200; 
 
int readingsIClamp[numReadings];   
int readingsGND[numReadings];                         
int readingsVClamp[numReadings];     
int readingsIClamp_1[numReadings];
int readingsGND_1[numReadings];

int readingsIClamp_2[numReadings];
int readingsGND_2[numReadings];

float SumSqGND = 0;            
float SumSqIClamp = 0;
float SumSqVClamp = 0;   

float total_I = 0; 
float total_V = 0;

float SumSqIClamp_1 = 0;
float total_I_1 = 0;


float SumSqIClamp_2 = 0;
float total_I_2 = 0;
 
 
int PinIClamp = A0;   
int PinVirtGND = A1;  

int PinVClamp = A3;  //Sensor ZMPT101B

int PinVirtGND_1 = A9;
int PinIClamp_1 = A8;

int PinVirtGND_2 = A12;
int PinIClamp_2 = A13;

float V_out = 0;

 
void setup() {
  Serial.begin(9600);
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {    
    readingsIClamp[thisReading] = 0;
    readingsGND[thisReading] = 0;
    readingsVClamp[thisReading] = 0;

    readingsIClamp_1[thisReading] = 0;
    readingsGND_1[thisReading]=0;

    readingsIClamp_2[thisReading] = 0;
    readingsGND_2[thisReading]=0;
  }
}
 
void loop() {
  unsigned int i=0;
  SumSqGND = 0;
  SumSqIClamp = 0;
  SumSqVClamp = 0;
  total_I = 0;                //다시한번 쭉 다 0으로 초기화 해주는 과정
  total_V = 0;
  V_out = 0;
  
  SumSqIClamp_1 = 0;
  total_I_1 = 0;
    
  SumSqIClamp_2 = 0;
  total_I_2 = 0;

  float  V_test = analogRead(A3);

  float  V_out_test = (V_test)-502.65; // Test for ZMBT Sensor 
  
  for (unsigned int i=0; i<numReadings; i++)   
  {
    readingsIClamp[i] = analogRead(PinIClamp)- analogRead(PinVirtGND);      
    readingsVClamp[i] = analogRead(PinVClamp)- 502.65;

    readingsIClamp_1[i] = analogRead(PinIClamp_1)- analogRead(PinVirtGND_1);

    readingsIClamp_2[i] = analogRead(PinIClamp_2)- analogRead(PinVirtGND_2);
    delay(1);
 
  //Calculate RMS
  for (unsigned int i=0; i<numReadings; i++)  
  {
    SumSqIClamp = SumSqIClamp + sq((float)readingsIClamp[i]);   
    SumSqVClamp = SumSqVClamp + sq((float)readingsVClamp[i]);  

    SumSqIClamp_1 = SumSqIClamp_1 + sq((float)readingsIClamp_1[i]); 

    SumSqIClamp_2 = SumSqIClamp_2 + sq((float)readingsIClamp_2[i]); 
 
  }
   
  total_I = sqrt(SumSqIClamp/numReadings);  
  total_I= total_I*(float)0.2959; // Rburden=3300 ohms, LBS= 0,004882 V (5/1024)   ;   
                             // Transformer of 2000 laps (SCT-013-000)    
                           


  total_I_1 = sqrt(SumSqIClamp_1 / numReadings);
  total_I_1 = total_I_1 * (float)0.2959;           

  total_I_2 = sqrt(SumSqIClamp_2 / numReadings);
  total_I_2 = total_I_2 * (float)0.2959;                  

 total_V = sqrt(SumSqVClamp/numReadings);
  //V_out = (total_V)*(float)6.193;  //my V sensor
  V_out = (total_V)*(float)2.9 ; //new sensor from 29May


float  I_raw = analogRead(PinIClamp)- analogRead(PinVirtGND);
I_raw = I_raw*(float)0.6;
   
  //Serial.print("Line 1 :");
  //Serial.print(total_I);  //출력

 // Serial.print("Line 2 :");
 // Serial.println(total_I_1);
 Serial.print(I_raw);
  Serial.print(" ");
  //Serial.print("Line 3 :");
  //Serial.println(total_I_2);
  //Serial.print("Line V: ");
// Serial.println(V_out);

  Serial.println(V_out_test);

  //delay(100);
}
-----------------------------------------------------------------------------------------------------------

That is OK in the theory book. Unfortunately, it does not work in the real world because the real world does not have the benefit of pure sine waves. Those exist only in the book. :smiley:

What that means is, as soon as one of the waves - and it is usually the current - ceases to be a nice sine wave, there is no such thing as ‘phase’ for the complete wave - you can only talk about phase for the 60 Hz component, or the 180 Hz component, or the 300 Hz component, etc.

What is the DEFINITION of power factor? It is the ratio of real power to apparent power. So what you are doing there is trying to measure a time difference between two waves, then using that to give you active (real) power.

The easy way, and the most reliable way, is to do as we do in emonLib. That calculates three average values like this:
Take a pair of readings of voltage and current. Calculate V×V, I×I & V×I.
Repeat that for as many cycles of the mains wave as you want, adding up the answers as you go. At the end you have Σ(V×V), Σ(I×I) & Σ(V×I).
Divide each of those by the number of samples to give you the averages, then get the square root of the first two. These are Irms & Vrms. The third average is the real (active) power.
Calculate power factor from those: Power Factor = real power ÷ (Irms × Vrms).

If you need to know whether power factor is leading or lagging, that is harder - much harder. You need to store each voltage sample for exactly a quarter of a mains cycle, and then multiply the current sample by the stored voltage from ¼cycle earlier. Add all those and get the average, that gives you reactive power, which will have a sign for leading or lagging, and you can then use that to give the sign for your power factor.

oh and i knew
that dimming… and zero crossing about Arduino
is it also helpful with my code for getting phase or Power…???
like this page

https://playground.arduino.cc/Main/ACPhaseControl/

using TriArc

If you have a load that is run from a phase-controlled triac, then what is the phase angle between the current wave and the voltage wave? You cannot tell me - and I do not know either - because the two waves are a very different shape. But you can measure real and apparent power and compute power factor from that.

Instead of calculating those values you may use already manufactured chip that does all hard work of measuring electricity power attributes for you. On top you would get also auto-calibrating function.
For example you can evaluate the chip: ADE9153A
https://www.analog.com/en/products/ade9153a.html#product-evaluationkit

The EV-ADE9153ASHIELDZ is an Arduino shield compatible with Arduino Uno, Arduino Zero, or ESP8266.
Avilable at Digikey: https://www.digikey.com/short/zm5jdn

Enjoy prototyping.

They’re proud of that puppy. 123 bucks proud.
For not much more than that, a class 0.5S revenue grade, 3-phase capable meter is available.

Mod - Please use 3 backticks to format code

Thanks Robert!!
so i will follow your advise 1 calculateing powerfactor and realpower using Irms Vrms V*I
could you one more check for my code?
i already compile it but its okay

in my code
i got Irms and Vrms

and

SumP = SumSqIClamp * SumSqVClamp;
SumP_1 = SumSqIClamp_1 * SumSqVClamp;
SumP_2 = SumSqIClamp_2 * SumSqVClamp;

like this I calculate V * I

and like this

total_P = sqrt(SumP / numReadings);
total_P_1 = sqrt(SumP_1 / numReadings);
total_P_2 = sqrt(SumP_2 / numReadings);

i calculate the RealPower
is it correct???


const unsigned int numReadings = 200; //samples to calculate Vrms. 
 
int readingsIClamp[numReadings];    // samples of the sensor SCT-013-000
int readingsGND[numReadings];      // samples of the GND                     
int readingsVClamp[numReadings];      //
int readingsIClamp_1[numReadings];
int readingsGND_1[numReadings];

int readingsIClamp_2[numReadings];
int readingsGND_2[numReadings];

float SumSqGND = 0;            
float SumSqIClamp = 0;
float SumSqVClamp = 0;   
float total_I = 0; 
float total_V = 0;

float SumSqIClamp_1 = 0;
float total_I_1 = 0;


float SumSqIClamp_2 = 0;
float total_I_2 = 0;


float SumP;
float SumP_1;
float SumP_2;

float total_P;
float total_P_1;
float total_P_2;

float realpower = 0;
float realpower_1 = 0;
float realpower_2 = 0;

float apparentpower = 0;
float apparentpower_1 = 0;
float apparentpower_2 = 0;

float powerFactor = 0;
float powerFactor_1 = 0;
float powerFactor_2 = 0;

int PinIClamp = A0;    
int PinVirtGND = A1;   

int PinVClamp = A3;  //Sensor ZMPT101B

int PinVirtGND_1 = A9;
int PinIClamp_1 = A8;

int PinVirtGND_2 = A12;
int PinIClamp_2 = A13;

float V_out = 0;

 
void setup() {
  Serial.begin(9600);
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {    
    readingsIClamp[thisReading] = 0;
    readingsGND[thisReading] = 0;
    readingsVClamp[thisReading] = 0;

    readingsIClamp_1[thisReading] = 0;
    readingsGND_1[thisReading]=0;

    readingsIClamp_2[thisReading] = 0;
    readingsGND_2[thisReading]=0;
  }
}
 
void loop() {
  unsigned int i=0;
  SumSqGND = 0;
  SumSqIClamp = 0;
  SumSqVClamp = 0;
  total_I = 0;                
  total_V = 0;
  V_out = 0;
  
  SumSqIClamp_1 = 0;
  total_I_1 = 0;
    
  SumSqIClamp_2 = 0;
  total_I_2 = 0;

  float  V_test = analogRead(A3);

  float  V_out_test = (V_test)-502.65; // Test for ZMBT Sensor 
  
  for (unsigned int i=0; i<numReadings; i++)    //0~200 까지 루프
  {
    readingsIClamp[i] = analogRead(PinIClamp)- analogRead(PinVirtGND);     
    readingsVClamp[i] = analogRead(PinVClamp)- 502.65;

    readingsIClamp_1[i] = analogRead(PinIClamp_1)- analogRead(PinVirtGND_1);

    readingsIClamp_2[i] = analogRead(PinIClamp_2)- analogRead(PinVirtGND_2);
    delay(1); 
  }
 
  //Calculate RMS
  for (unsigned int i=0; i<numReadings; i++)   /
  {
    SumSqIClamp = SumSqIClamp + sq((float)readingsIClamp[i]);   
    SumSqVClamp = SumSqVClamp + sq((float)readingsVClamp[i]);  

    
    
    SumSqIClamp_1 = SumSqIClamp_1 + sq((float)readingsIClamp_1[i]); 

    SumSqIClamp_2 = SumSqIClamp_2 + sq((float)readingsIClamp_2[i]); 

 SumP = SumSqIClamp * SumSqVClamp;
     SumP_1 = SumSqIClamp_1 * SumSqVClamp;
      SumP_2 = SumSqIClamp_2 * SumSqVClamp;
      
  }
 
   
  total_I = sqrt(SumSqIClamp/numReadings);  
  total_I= total_I*(float)0.2959; // Rburden=3300 ohms, LBS= 0,004882 V (5/1024)      /
                             // Transformer of 2000 laps (SCT-013-000)     
                             // 5*220*2000/(3300*1024)= 2/3 (aprox)  

  total_I_1 = sqrt(SumSqIClamp_1 / numReadings);
  total_I_1 = total_I_1 * (float)0.2959;           

  total_I_2 = sqrt(SumSqIClamp_2 / numReadings);
  total_I_2 = total_I_2 * (float)0.2959;                  


 total_V = sqrt(SumSqVClamp/numReadings);
  //V_out = (total_V)*(float)6.193;  //my V sensor
  V_out = (total_V)*(float)2.9 ; //new sensor from 29May

total_P = sqrt(SumP / numReadings);
total_P_1 = sqrt(SumP_1 / numReadings);
total_P_2 = sqrt(SumP_2 / numReadings);


//여기부터 내가쓴거//

realpower = total_I * V_out * (SumSqIClamp / numReadings);
realpower_1 = total_I_1 * V_out * (SumSqIClamp_1 / numReadings);
realpower_2 = total_I_2 * V_out * (SumSqIClamp_2 / numReadings);

apparentpower = V_out * total_I ;
apparentpower_1 = V_out * total_I_1 ;
apparentpower_2 = V_out * total_I_2 ;

powerFactor = realpower / apparentpower ; 
powerFactor_1 = realpower_1 / apparentpower_1 ; 
powerFactor_2 = realpower_2 / apparentpower_2 ; 



float  I_raw = analogRead(PinIClamp)- analogRead(PinVirtGND);
I_raw = I_raw*(float)0.6;
   
  //Serial.print("Line 1 :");
  //Serial.print(total_I);  //출력

 // Serial.print("Line 2 :");
 // Serial.println(total_I_1);
 Serial.print(I_raw);
  Serial.print(" ");
  //Serial.print("Line 3 :");
  //Serial.println(total_I_2);
  //Serial.print("Line V: ");
// Serial.println(V_out);

  Serial.println(V_out_test);

 Serial.print(" ");
   Serial.print(realpower);
     Serial.print(" ");
   Serial.print(realpower_1);
     Serial.print(" ");
   Serial.print(realpower_2);

    Serial.print(" ");
   Serial.print(apparentpower);
     Serial.print(" ");
   Serial.print(apparentpower_1);
     Serial.print(" ");
   Serial.print(apparentpower_2);
   

   Serial.print(" ");
   Serial.print(powerFactor);
     Serial.print(" ");
   Serial.print(powerFactor_1);
     Serial.print(" ");
   Serial.print(powerFactor_2);

   

  //delay(100);
}

No, those lines are wrong. To calculate the instantaneous power, and to sum it, you need:

SumP = SumP + (readingsIClamp[i] * readingsVClamp[i]);
so that you multiply each individual sample of current and the corresponding sample of voltage. Then you average - no square root:
total_P = SumP / numReadings;

total_P then gives you the average - real or active - power.

Thanks for you Advice!!

i can compile real power
using

SumP = SumP + (readingIclamp[i] * readingVClamp[i]);

but i still cant solve apparent power…

apparentpower = V_out * total_I ;

do you think i need to change for getting apparentpower
like realpower Robert???

Again Really thanks for last advice

No - you need the rms values of voltage and current for apparent power.
That is what apparent means: it is the power you think you have if you measure voltage and current separately with your multimeter, then multiply the numbers you read on the front of the meter.

Your rms values are total_V and total_I, therefore your apparent power should be
apparentpower = total_V * total_I ;

BUT you must still apply the same calibration factors to rms voltage & rms current as you do to the instantaneous values that multiply make the real power. Where in the calculation you apply them is your choice - I would apply them at the end.

Look at emonLib.cpp. V_RATIO & I_RATIO are the final calibration factors. You need to do the same with your sketch:

  double V_RATIO = VCAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
  Vrms = V_RATIO * sqrt(sumV / numberOfSamples); 
  
  double I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
  Irms = I_RATIO * sqrt(sumI / numberOfSamples); 

  //Calculation power values
  realPower = V_RATIO * I_RATIO * sumP / numberOfSamples;
  apparentPower = Vrms * Irms;
  powerFactor=realPower / apparentPower;