Microcontroller Based Automatic Power Factor Correction for Single-Phase Lagging and Leading Loads

The Power Factor (PF) correction is a major power quality function in electrical distribution systems. This paper proposes a low cost Automatic Power Factor Correction (APFC) system to increase the PF of both lagging and leading singlephase loads. The Arduino Mega 2560 microcontroller was used to calculate the PF and activate the relays that connect the capacitor/inductor banks to the load in parallel. Thus, the required capacitive or inductive reactive power was produced by the APFC system by automatically connecting the capacitor/inductor banks to the load in parallel. The APFC system can also measure and display many electrical parameters of the load such as the rms voltage, the rms current, PF, and the real, reactive, and apparent power on an LCD display. Two zero crossing detector circuits are used to find the phase angle difference between voltage and current waveforms of the load. The measurement ability of the APFC system was tested for resistive, inductive, and capacitive loads with two different sizes. The measurements results were compared with the measurements of a commercial digital power meter and a measurement error less than 8.0% was observed. The PF correction ability of the APFC system was verified for inductive and capacitive loads with two different sizes. The experiments show that the PF increased to close to unity for both lagging and leading loads. Keywords-power factor correction; reactive power compensation; Arduino Mega 2560 microcontroller

INTRODUCTION Power Factor (PF) is a critical performance indicator of the power quality in AC power systems [1,2]. The PF of an electrical load is defined as the ratio between the real and apparent power of the load [1][2][3]. The PF can have any value between 0 and 1. Ideally, the PF is equal to unity or 1, which means that a given load matches that of a pure resistance having voltage and current waveforms which are in phase [4]. This means that the real and apparent power of the load are equal to each other. In this situation, the load neither consumes nor delivers reactive power. On the other hand, if the PF is not unity, then the PF type can be either "lagging" or "leading". Lagging PF means that the current waveform lags the voltage waveform by some angle. Instead, if the current waveform leads the voltage waveform, then the PF is said to be leading. For lagging PF loads, such as induction motors, power transformers, and lighting ballasts, the minimization of reactive power is very essential [3,5]. The reactive power is the energy stored in inductive elements which continuously oscillates between the load and the source. This continuous oscillation causes an increase in the amount of current drawn by the load [2,6]. If the reactive power is not minimized, a relatively higher amount of current will be drawn by the load, which makes imperative to use a relatively high cross-section of the conductors that increase the cost and losses of the distribution system [7].
Reactive power minimization is called "PF Correction" or "Reactive Power Compensation". It is a process that makes the PF of a load close to 1. With the PF correction, the load current is minimized without changing the real power consumed by the load [1,8]. So, the load continues to make the same work by the drawn electrical energy with a relatively smaller amount of current when compared with the uncompensated case. Moreover, minimum and maximum allowable limits of reactive power drawn from the system are defined in regulations and the electric distribution companies give penalties to the industrial consumers for any violation of these limits. As a summary, the advantages of PF correction are reduced system losses, increased load carrying capability of the conductors and the transformers, and improved voltage profile and system stability [9][10][11][12][13]. Although there are some expensive solutions to handle the reactive power compensation function, the capacitors are still used globally due to their simplicity and low cost. When compared, the capacitors are much cheaper and easier to implement than static var compensators, static synchronous compensators, and active power filters [1][2][3]. On the other hand, many studies proposed the use of a microcontroller to improve the PF of only lagging loads by adding parallel connected capacitor banks to the load [1][2][3][4][5][6][7][8][9]. Arduino Uno has been used to improve only the lagging load by using capacitor connection in parallel with only the inductive load [1,6,7] and to improve the PF of different loads by using filter and capacitor bank [8]. PIC18F452 type microcontroller for the correction of the PF in constant level of load was proposed in [2]. The contribution of this paper is the use of an Arduino microcontroller for APFC to improve the PF of different types of loads with different sizes. Not only the capacitor banks are used to improve the PF of lagging loads, but also the inductor banks are used to improve the PF of leading type loads with different sizes. Two different sizes for resistive, inductive, and capacitive loads are used to show the reliability of the APFC.
In this paper, the PF improvement of both lagging and leading loads is proposed. An Arduino Mega 2560 microcontroller is programmed to decide the number of the capacitors or inductor banks that are automatically connected to a single-phase load by relays to approach load PF close to unity (0.98 lagging). Three different loads are considered in this work: resistive, inductive, and capacitive loads with two different sizes. The purpose of using resistive load is to verify the operation of the ZCD circuits. The designed APFC system can also measure and display many electrical parameters on an LCD display, such as rms voltage, rms current, PF and its type, and real, reactive, and apparent power of the single-phase load. All the measurements were verified with Reed R5000 digital power meter. The comparison results show that the measurement errors are relatively small with an error of less than 8.0%. On the other hand, it is experimentally verified that the designed APFC system can improve the PF by 39% for small inductive load, 52% for high inductive load, 12% for low capacitive load, and 29% for high capacitive load.
II. SYSTEM DESIGN This section explains the block diagram of the proposed APFC system. Figure 1 shows the complete diagram of the designed hardware to calculate the necessary amount of capacitor or inductor banks to improve the PF of a single-phase load. At first, the voltage and current of the load connected to single-phase voltage source are sensed by an ASL 150212 voltage transformer (PT) and a ZMCT 103C current transformer (CT), respectively. Then the voltage and current waveforms are sent to the ZCD circuits, which are used to change the sinusoidal voltage and current waveforms to square waveforms. Then, the two square waves, synchronized to voltage and current waveforms, are summed by a summer circuit made by an XOR logic gate. The output of the XOR gate is connected to one I/O pin of the Arduino Mega 2560 microcontroller to send the phase angle difference. The PF is calculated and its type is defined with a program written in C.
Based on these calculations, the Arduino Mega 2560 microcontroller decides the value and number of capacitors or inductor banks to be connected in parallel with the load. The design also includes a 2004A LCD display to show the measurements. Fig. 1.
The block diagram of the APFC system.
III. MATHEMATICAL MODEL One of the inputs of the Arduino Mega 2560 microcontroller is related with the phase angle difference (ߠ) between the voltage (ܸ) and the current ‫)ܫ(‬ of the load. These values are read in the microcontroller by using the function pulseIn (pin, value, timeout) [1,2]. The PF is then calculated by: Based on voltage and current measurements and the PF calculation, real (ܲ), reactive (Q), and apparent power (ܵ) of the load are calculated by: The PF could be unity, lagging, or leading based on the load type. If the load is resistive, then the PF becomes unity and no action is needed from the microcontroller. Only the electrical parameters are calculated and shown on the LCD display. If the load is inductive, the PF becomes lagging. In this case, the microcontroller calculates the size of the capacitor banks to be connected in parallel with the load. This is achieved by controlling the relays between the load and the capacitors. If the load is capacitive, the PF becomes leading. In that case, the microcontroller calculates the size of the inductor banks to be connected in parallel with the load. Again, this task is achieved by controlling the relays between the load and the inductors. The following steps are used to calculate the required capacitance or inductance for the APFC system: • Calculation of the PF angle (∅ ) of the load: ∅ = cos ିଵ (PF) (5) • Calculation of the the reactive power (ܳ ଵ ) of the load: • Calculation of the amount of reactive power (ܳ ௧ ) for the desired PF: • Calculation of the amount of reactive power (ܳ ) needed to improve the PF: • Calculation of the capacitance (C) or inductance (L) required to be connected in parallel with the load:

IV. FLOWCHART OF THE ALGORITHM
The flowchart of the algorithm used in the APFC system is shown in Figure 2. After starting the system, at first, the voltage and the current of the load are measured. These are stepped down by a PT and CT. ZCD circuits are used to convert the sine waveform to square waveform. This circuit is used to measure the phase angle between the voltage and the current of the load. The XOR circuit represents the time difference between the voltage and the current. In this sense, the Arduino Mega 2560 microcontroller has three inputs: voltage, current, and the time delay between the voltage and current. The Arduino Mega 2560 microcontroller is programed in the following steps: • Step1: Read voltage, current, and time delay   V. EXPERIMENTAL CIRCUIT AND RESULTS This section explains the hardware circuit of the proposed APFC system and its components. The experimental results are presented and evaluated for different sizes and types of load.

A. Experimental Circuit
The complete experimental circuit of the APFC system is shown in Figure 3. In this circuit, a PT and a CT are used to step down and measure the voltage and the current of the load. The voltage and current waveforms obtained from PT and CT1 are sent to the ZCD circuits which contain LM324 operational amplifiers to change the waveform of the voltage and current from sinusoidal to square. The outputs of the ZCD circuits are fed to the XOR3040 gate. The output of the XOR 3040 gate is a series of pulses. The amplitude and the width of these pulses depend upon the output of the two signals from the ZCD circuits. The CT2 is used as a sensor that measures the load current and sends this information to the microcontroller. All these outputs are connected to the inputs of the Arduino Mega 2560 microcontroller. The microcontroller measures and evaluates the difference in the pulse width of the two square waves to calculate the PF. There are four different values of inductors in the inductance bank and five different values of capacitors in the capacitor bank. The connections of these components are handled by the microcontroller by the relays. According to the type and value of the PF, the microcontroller decides how many capacitors or inductors would be connected in parallel with the load in order to approach the PF to 0.98 lagging. Finally, the rms voltage, rms current, real, reactive, and apparent power of the load, and the information about the connected capacitors or inductors are shown in the LCD display. Figure 4 shows the experimental setup of the proposed APFC system. Experimental setup of the APFC system.

B. Experimental Results
Three different load types and two different load sizes were used to test the performance of the proposed APFC system. To show the accuracy of the measurements taken by the microcontroller, (12) is used to calculate the percentage of error between the measurements of the APFC system and the digital power meter measurement:

1) Resistive Load
In this case, a small and a big resistive load were used. The purpose of this case study was to verify the measurement performance of the proposed APFC system. The small resistive load is a 100W incandescent light bulb. A big resistive load is the combination of these two light bulbs with a total power of 200W. Table I shows the measurements taken by the Arduino microcontroller and the commercial digital power meter. The measured data of the resistive load are the rms voltage, the rms current, the PF, and the active, reactive, and apparent power. The percentage of error for each measured data is also represented in Table I by comparing the measurements taken from the microcontroller with the digital power meter. The error for the voltage measurements for both loads remains less than 1.0%. The error of current and power measurements for both cases is between 2% and 7%. It can be concluded that the proposed APFC system measures many electrical parameters of the resistive load with an error of maximum 7.2%. 2) Inductive Load In this case, two different inductive loads were used. The small load is a single-phase AC motor with ratings of 220V, 50Hz, 43W. The big load is a single-phase AC motor with ratings of 220V, 50Hz, 110W. In this experimental case, both measurements and the compensation performance of the proposed APFC system were verified for lagging PF loads. Table II shows the measurements taken by the microcontroller and the digital power meter before and after compensation for the small load. The error for the voltage measurements before and after compensation was less than 1.0%. The obtained error for current measurements before and after compensation has a maximum of 7.69%. On the other hand, the errors for the power measurements before and after compensation stay between 1% and 8%. When the compensation function is activated, the APFC system connects one 2.5uF capacitor to the load in parallel to improve the PF from 0. 6  deduced that the proposed APFC works well in increasing the PF of the 43W rated single-phase AC motor. Table III shows the measurements taken by the microcontroller and the digital power meter before and after compensation for the big load. The voltage errors stay again less than 1.0% before and after compensation. The errors for the current measurements before and after compensation remain around 3-4%. On the other hand, the errors for the power measurements before and after compensation are between 2% and 7%. When the compensation function is activated, the APFC system connects three capacitors with capacitances of 0.5uF, 1.5uF, and 5uF to improve the PF from 0.45 to 0.97 lagging. In this case study, it is verified that the measurements taken from the APFC system have a maximum error rate of 7.93% and the PFs of the inductive loads with different sizes are effectively increased to be close to unity.

3) Capacitive Load
In this case, two different capacitive loads were used. The small load consists of a 470Ω resistor connected in series with a 10uF capacitor. The big load consists of a 235Ω resistor connected in series with a 12uF capacitor. In this experimental case, the measurements and the compensation performance of the proposed APFC system are verified for leading the PF loads. Table IV shows the measurements taken by the microcontroller and the digital power meter before and after compensation for the small load. The maximum error for the voltage measurements before and after compensation is 1.17%. The maximum error for the current measurements before/after compensation is 2.70%. On the other hand, the errors for the power measurements before and after compensation stay between 0.75% and 7.35%. When the compensation function is activated, the APFC system connects one 2.91H inductor to the load in parallel to improve the PF from 0.85 leading to 0.97 leading. It is deduced that the proposed APFC works well in increasing the PF of the small capacitive load. Table V shows the measurements taken by the microcontroller and the commercial digital power meter before/after compensation for the big load. The maximum voltage measurement error before/after compensation is 1.08%. The errors for the current measurements before and after compensation remain around 3.17% and 3.92%. The error of the power measurements before and after compensation is between 3.49% and 7.74%. When the compensation function is activated, the APFC system connects one 1.01H inductance to the load to improve the PF from 0.68 leading to 0.97 leading. In this case study, it is verified that the measurements taken from the APFC system have a maximum error rate of 7.74% and the PFs of the capacitive loads with different sizes are effectively increased to be close to unity.
VI. CONCLUSION In this study, a single-phase automatic power factor correction system based on the Arduino 2560 microcontroller has been proposed and experimentally implemented. This system is capable of correcting the power factor of lagging and leading loads. Moreover, the system can also measure many electrical parameters of single-phase loads such as the rms voltage, the rms current, the PF and its type, active, the reactive, and the apparent power. The performance of the proposed system has been tested and verified by comparing the measurement results with a commercial digital power meter. It is seen that the measurements are accurate with less than 8.0% error for different load sizes having different PFs. It is also verified that the designed hardware can make the PF of different load sizes become closer to unity by connecting capacitors or inductors in parallel to the load.