# PFC using arduino

I'm trying to make a power factor correction system using arduino.

In the first i successes to calculate the PF using arduino and XOR gate

Following picture is my circuit:

simulate this circuit – Schematic created using CircuitLab

But now i want to convert this project to PFC by connecting some relays to the arduino to connecting some capacitors to the inductive load during PFC process.

This is my code:

int pin = 13;

int cap1 = 6; //0.5 micro farad capacitor

int cap2 = 7; //0.5 micro farad capacitor

int cap3 = 8; //0.5 micro farad capacitor

int cap4 = 9; //0.5 micro farad capacitor

int cap5 = 10; //0.5 micro farad capacitor

int cap6 = 11; //0.5 micro farad capacitor

/*Variables will change their value:*/

double duration,duration1,T=20;

double si,phi;

double power_factor;

void setup()

{

pinMode(pin, INPUT);

Serial.begin(9600);

pinMode(cap1, OUTPUT);

pinMode(cap2, OUTPUT);

pinMode(cap3, OUTPUT);

pinMode(cap4, OUTPUT);

pinMode(cap5, OUTPUT);

pinMode(cap6, OUTPUT);

}

void loop()

{

getpf();

if(power_factor < 0.98)

{

digitalWrite(cap1, HIGH);

getpf();

Serial.println(power_factor);

if(power_factor <0.98)

{

digitalWrite(cap2, HIGH);

getpf();

Serial.println(power_factor);

if(power_factor <0.98)

{

digitalWrite(cap3, HIGH);

getpf();

Serial.println(power_factor);

if(power_factor <0.98)

{

digitalWrite(cap4, HIGH);

getpf();

Serial.println(power_factor);

if(power_factor <0.98)

{

digitalWrite(cap5, HIGH);

getpf();

Serial.println(power_factor);

if(power_factor <0.98)

{

digitalWrite(cap5, HIGH);

getpf();

Serial.println(power_factor);

if(power_factor <0.98)

{

digitalWrite(cap6, HIGH);

getpf();

Serial.println(power_factor);

}

}

}

}

}

}

}

else if(power_factor >= 0.98)

{

Serial.println(power_factor);

}

}

void getpf()

{

duration = pulseIn(pin, HIGH);

duration1=(duration/1000);

si=(duration1/20);

phi=(si*360);

power_factor=cos(phi/57.2);

}


Each capacitor with value of 0.5uF connect to relays and the relays connected to pin 6, pin 7, pin 8, pin 9, pin 10, pin 11

I have 3 problems with this project:

1-When the power factor is low and the load need to only two capacitors(0.5 + 0.5 = 1uF), all relays turn ON together (i think there are problem in "if getpf" command.)

2-When i opens the serial monitor in IDE to see the power factor number, the system reset and relays turn ON and OFF

3-Why i can't measure PF of harmonic load by this project? however i know i can't correct the PF of harmonic load by adding capacitors to the load, but why i can't measure the power factor of harmonic load correctly?

• I don't think anyone's going to bother trying to decipher your double-spaced non-indented code. You have used the code tag correctly but pasted in badly formatted code. Edit required. – Transistor Mar 20 '18 at 20:25
• XY problem! Why MCU? What do you plan to gain? – winny Mar 20 '18 at 20:40
• If you use a binary or 1,2,2,5 capacitor system you can get a lot more capacitance then 6x50uF. – Oldfart Mar 20 '18 at 20:49
• If you only slice the current, you ignore the peak pulse currents that may not affect zero crossing , so other methods that compare rms waveform are necessary due to binary "quantization" error – Tony Stewart Sunnyskyguy EE75 Mar 20 '18 at 21:06