# power factor measurement using PIC16F877A microcontroller

In this article, I have discussed a method to measure a power factor using pic microcontroller. Power factor measurement using pic microcontroller project is design to measure power factor with the help of pic microcontroller and displays it to LCD.Improvements can be done in this project by adding functionality of automatic power factor correction using capacitors. After reading this article, you will be able to answer following questions?

• What is power factor?
• Why we need of power factor correction?
• How to improve power factor?
• Advantages of power factor improvement?
• Power factor measurement using pic microcontroller.
• Automatic power factor correction using pic microcontroller.

### What is power factor?

Let’s start with basic introduction of power factor.  Power factor is basically a ration of real power absorbed by electrical circuit to total appearent power consumed by electrical circuit. In other words, power factor is a ratio of real power and appearent power. Many inductive loads are used in power system. Inductive loads need reactive power for their proper operation. So main cause of power factor in electrical power system is reactance. Capacitors provide reactive power. In other words, capacitors generate reactive power and inductors consume reactive power.

### Why we need to improve power factor?

Reactive power is basically a burn on power system and transmission lines. Reactive power travel back and forth from power generation point to load and hence a lost of electrical energy. Now a days inductive loads are used in domestic as well as industrial applications. Low power factor cause losses in transmission line and voltage drops in transmission lines. Need of electrical power is increasing day by day, so can’t afford to waste power in transmission line. Therefore we need to improve power factor of electrical power system and loads. By providing  reactive power locally at the load side, we can increase power factor of system and power factor of machines. Hence Power factor improvement is local issue.  As I have already mentioned, capacitors are source of reactive power. So capacitors can be used to improve power factor or to provide reactive power to load locally instead of from power generations ends.

### How to improve power factor:

Before understanding what is power factor? Let me tell you what is good power factor? Unity is ideal power factor. Resistive loads have unity power factor. But all electrical loads are not fully resistive. Therefore we need to improve power factor of these load. Power factor can be increased by adding power factor correction capacitor to loads. Capacitors provide reactive power to load locally . There are many methods have been developed for power factor improvement. But in this article, you will learn about power factor measurement and correction using microcontroller.

### Advantages of power factor improvement?

Major advantages of power  factor improvement are given below:

• It reduces the losses in transmission lines and cables
• It reduces the voltage drop in transmission lines and cables
• It reduces the burden on power generation utility companies

### Power factor measurement using pic microcontroller:

Power factor is basically due to lag and lead concept of current and voltage. When current waveform lags behinds the voltage by some angle, power factor will be lagging and when current wave form leads the voltage by some angle, power factor will be leading. Inductor causes a lagging power factor and capacitors produces leading power factor. Hence capacitors improve power factor by providing leading VARS or reactive power to system which cancels the lagging power factor effect of inductors.

Now the question is how to measure power factor using microcontroller? To measure power factor we need to measure phase angle difference between voltage and current wave form. The cosine of this phase angle is power factor. Power factor is also represented by following formula:

Power factor = Cos (θ)

Where θ is basically phase angle difference between voltage and current wave form. So we need to develop a method to measure phase angle difference between voltage and current wave form. I have used zero crossing detection concept to measure time difference between current and voltage wave form. Time difference between two signal or waves can also be used to measure power factor. I will discuss more about it in later part of this article.  Now let’s proceed further with zero crossing detection?

#### What is zero crossing detection?

Zero crossing detection is used to detect sine wave zero crossing from positive half cycle to negative half cycle  or negative half cycle. To measure time difference between two waves we need to detect zero crossing of two waves. There are many methods available to measure zero crossing detection. But I have already posted an article on zero crossing detection using pic microcontroller. I have explained zero crossing detection concept in following article. So I recommend you to read following article first before reading further.

How to detect zero crossing using pic microcontroller

I  assume that After reading an article on zero crossing detection, you got the idea about how to detect zero crossing of sine waves using pic microcontroller. In zero power factor measurement circuit, two zero crossing detection circuits are used. One for voltage wave form and other for current wave form. After detecting zero crossing for voltage wave and sine wave we need to measure time difference between zero crossing of voltage and current wave forms.

### How to measure time difference two wave for power factor measurement:

Now I will discuss how to measure time difference between two waves. It is very easy to measure time difference between two waves with the help of hardware external interrupt pin of microcontroller. hardware interrupt is used to detect zero crossing signal. Microcontroller internal timer is used to measure time. When external interrupt occur on microcontroller pin time will start and after another external interrupt time will stop counting. One interrupt will be generated with the help of current signal and other interrupt with the help voltage signal zero crossing. Timer value will be stored in one variable. This variable value is basically a time difference between two waves. For better results take 20-30 values and take their average.

#### How to find angel using time difference:

So using time difference we can easily calculate phase angle using below given formula’s :

Time difference = average values of timer /1000 ;

In above equation 1000 is used to convert time into seconds because half of the sine wave is about 10us and there will 1000 counts per second.

θ = time difference *  2π;

Power factor = Cos ( θ ) ;

After that time difference is multiplied with  2π to convert it into radians and phase angle in radians. After that by using power factor formula we can easily calculate power factor.  All these calculations are done in programming by writing a code in microcontroller.

### Power factor measurement circuit using pic microcontroller:

Circuit diagram of power factor measurement circuit using pic microcontroller is given below.  Voltage transformer and current transformer is used in power factor measurement circuit.

In above circuit diagram. voltage transformer is used to step down voltage. Because microcontroller can not read high voltage 220v AC directly. Current transformer is used to get wave form of current wave. magnitude of current depend on the load and voltage almost remains constant. After that these signals are fed to zero crossing detector circuit using LM358 operational amplifier. I have already posted an article on zero crossing detection using operational amplifier. For more information about zero crossing detector circuit check following article:

Zero crossing detection using op amp

Microcontroller PIC16F877A read zero crossings of voltage and current waveform and start timer according to zero crossing detection of current and voltage wave form. PC16F877A microcontroller is main part of this project. In reads zero crossing detection. measures time difference and calulate power factor according to above given formula’s.After calculating power factor, PIC16F877A microcontroller displays it on 16 X2 LCD. ### Power factor meter with pic18F452 microcontroller

#### List of components for power measurement circuit:

List of components for power measurement circuit using pic microcontroller is given below:

```Category,Reference,Value,Order Code
Resistors,"R1",2k,
Resistors,"R2",4k,
Resistors,"R3",4k,
Resistors,"R4",4k,
Resistors,"R5",4k,
Integrated Circuits,"U1",PIC16F877A,
Integrated Circuits,"U2",LM358,
Miscellaneous,"AC SOURCE",,
Miscellaneous,"CURRENT TRANSFORMER" It can be wind according to requirement,
Miscellaneous,"POTENTIAL TRANSFORMER" 220V AC to 12V AC step down transformer,
Liquid crystal display: ,"LCD1",LM016L,
Variable resistor: ,"RV1",10k,
```

This guide has provided you all the information you need to measure power factor. I have tried to cover a question on ” How to measure power factor using microcontroller. I recommend you to write your own code for this project. But If you want to purchase code of this project,  contact me on my email address.

[email protected]

In the next article, I will discuss automatic power factor correction using a microcontroller. Suscribe to our blog.

### 34 thoughts on “power factor measurement using PIC16F877A microcontroller”

1. hello Bilal,
Can you posting how dimmer and controlled used avr.

• I will try to post a article on it. kindly post your complete requirement here

2. Very useful , I will try to do some of these projects!
Thank you,
S.Y.raja

3. i need your help about power factor meter to complete my project.

• i would like to show me the best circuit diagram of power factor correction mechanism using micro controller

4. hello bilal,
Harshid here, in your power factor mesurment project CT is working properly means CT output is oki.?

• CT output must be in voltages

5. Bilal I want to measure power factor using 8051 MC. plz suggest me the microcontroller code for that plz.

6. I find it hard to do the coding please I will be glade if I get help from you

7. program code is need or not in this project

8. hello malik…
for my final year project…

• Did you finish it ?

9. Pls help me on digital power factor meter. No one seems to hv done the project

10. hy im anele im doing a power factor measurement and display project at school using microcontroler and im failing to program it would you help me guys im now out of time i need to submit and present it on 27 may for my final mark im failing to programm the microcontroler.

11. could u pls post the video of this project…

12. Its really very useful thanks a lot sir

13. sir how can i do it by using 8051 microcontroller??

14. hello mike are you voluntary to help me to send 16F77A pic code

• please send me pic16f77A CODE

15. Hii bilal! Could you just explain if i can obtain different waveforms for voltage and current? And why are we using CT and PT here?

16. sir please tell how to add current transformer and voltage transformer in proteus?