**Warning:** if you know how to handle electricity then implement this project with precaution. if you are confused with any component to use contact us.

To learn about the power factor measurement first you should have a basic knowledge of power factor. There are three types of loads.

- Resistive
- Inductive
- Capacitive

When we apply AC voltage to resistive loads it will not change the current wave form. But inductive loads will force to lag the current waveform and in the case of capacitive loading it will force to lead the current waveform than voltage waveform.

You can see the waveforms of inductive load. The phase shift of 30 degree is present in the current waveform.

The power factor is basically the “angle cosine of that lagging current". In simple words, current is lagging by voltage with some angle and if we take the cosine of that angle we will get power factor.

Now how to get that lagging angle? This is only problem left here. If somehow we can measure the time difference of both waveforms then we can find our required angle by using the formula below:

Where frequency (f) is the frequency of the system which may be 50 or 60 Hz.

**Zero Cross Detection:**

Zero cross detection is a method which can enable us to measure the time between voltage and current. In this technique we get a high value (i.e. 1) whenever a zero will cross the system. There are many ways to implement it. But remember, this technique is the heart of this project so implementation must be accurate. In this project we implemented zero crossing using LM358 an 8 pin IC having dual amplifiers in it. In zero crossing, we have to get a “high” value during crossing of zero in waveforms. So to get that value we use amplifier as a comparator which will compare the non inverting reference value and then act accordingly.

We will use a 16x2 LCD to show our results and ATmega 8 or ATmega16 can be used for the project. In the simulation, take upper sine generator as output of Potential Transformer (PT) and lower sine generator as output of Current Transformer (CT). The reason behind using CT and PT is, we cannot give high voltage to the IC LM358. It will burn the IC badly. So first step down the voltage and step down the current at such extent that the highest peak of current and voltage is not more than 5V. If you have no idea of using CT and PT in the real systems then see the links below.

1.AC Voltage Measurement Using Atmel AVR Microcontroller

2. AC Current Measurement Using Atmel AVR Microcontroller

Now comeback to the zero crossing method, you can see that we set the reference value of zero volts at non - inverting pin (+) of both amplifiers. So, according to comparator action it will give us high value (1) at the output whenever a zero will cross in the waveform. The output of comparators is shown below in the figure in which yellow is the output of voltage and blue is the output of current having some lag.

**Implementation:**

I implemented a voltage divider with PT because the output of PT will be 6 volt. 6 volt PT have peak of 1.4*6 = 8.4 volts which is harmful for the IC. So I placed a voltage divider to cut the peak to the 4.2 volts. The resistor present in front of the CT is burden resistor which is essential for CT. We never leave secondary of CT as open circuit.

**Coding part:**

The code is written on codevision. You can download whole code from the link present below. If you want code for Atmel Studio email us. Here we will discuss two main functions of code.

//_________function to get the time difference_____________ void pf_func(){ while(1){ if ( PINC.4==1 ){ TCNT1=0; TCCR1B = 0x01; // Start timer at Fcpu/1 break; } else { continue; } } while(1){ if ( PINC.3 == 1 ){ TCCR1B = 0x00; //Stop timer g=TCNT1; break; } else { continue; }}}

In this function, I started the Timer1 of microcontroller when zero crossing of voltage occurs at PINC.4 and turned off the Timer2 at PINC.5 when zero crossing of current occurs. “g variable” has the final time count of the difference.

//________function to calculate the power factor______ int powerfactor(){ k=0; // To complete number of counts g=g+1; //Value from the timer //To convert into seconds pf=(float)g/1000000; //To convert into radians pf=pf*50*360*(3.14/180); //power facor pf = cos(pf); //power factor into percentage k=abs(ceil(pf*100)); return k; }

In this function, I just converted the delay into seconds and then converted that seconds into angle using the formula I mentioned above.

*If you need more help feel free to comment below and don't forget to like our facebook page.
*

*To download the proteus file and complete code click the buttons below. *

Sir can you give a suggestion for the CT ? like a brand link or Amazon link ? Because i didnt find the "1:1500" ct at the stores..I mean i didt get actually,which CT is i have to use for this project?

Use this link to get the CT. This CT is rather cheap and gives really accurate results as well.

https://www.aliexpress.com/item/YHDC-20A-20mA-PCB-mout-current-transformer/32295621675.html

Does it required external crystal for practical implementation..?

No it doesn't.

can i have power factor code for atmel studio plz?

For Atmega 8

You can change this code for atmel studio. A little bit hard work will be required which will help you further in understanding the things as well.

I tried. but time difference mesurement is not correct. it can not come out from the loop. so I need help.

Can you assist me with the code in Atmel studio please IDE please, I'm having trouble with the transformation.

At which part you are having trouble?

Sorry I meant the code in arduino IDE, I am getting stuck with the function to get time difference please

Put different serial commands in loops and try to figure out at which loop and at which state of comparators you are having issue.

I have done it correctly. yes, I am successful.

Happy to hear that 🙂