Automatic Power Factor Controller Using Microcontroller
Automatic Power Factor Controller Using Microcontroller
The thirst for new sources of energy is unquenchable, but we seldom realize that we are wasting
a part of the electrical energy every day due to the lagging power factor in the inductive loads
we use. Hence there is an urgent need to avoid this wastage of energy.
Before getting into the details of Power factor correction, lets just brush our knowledge about
the term power factor. In simple words power factor basically states how far the energy
provided has been utilized. The maximum value of power factor is unity. So closer the value
of P.F to unity, better is the utility of energy or lesser is the wastage. In electrical terms Power
factor is basically defined as the ratio of the active power to reactive power or it is the phase
difference between voltage and current. Active power performs useful work while Reactive
power does no useful work but is used for developing the magnetic field required by the device.
Most of the devices we use have power factor less than unity. Hence there is a requirement to
bring this power factor close to unity. Here we are presenting a prototype for automatic power
factor correction using PIC Microcontroller.
Comparator Section
The 230 V, 50 Hz is step downed using voltage transformer and current transformer is used to
extract the waveforms of current. The output of the voltage transformer is proportional to the
voltage across the load and output of current transformer is proportional to the
current through the load. These waveforms are fed to Voltage Comparators
constructed using LM358 op-amp. Since it is a zero crossing detector, its output changes during
zero crossing of the current and voltage waveforms. These outputs are fed to the PIC which
does the further power factor calculations.
Microcontroller Section
PIC 16F877A microcontroller is the heart of this Automatic Power Factor Controller, it find,
displays and controls the Power Factor.. To correct power factor, first we need to find the
current power factor. It can be find by taking tangent of ratio of time between zero crossing
of current and voltage waveforms and two successive zero crossing of voltage waveform.
Then it displays the calculated power factor in the 162 LCD Display and switches ON the
capacitors if required.
Correction Section
When load is connected the power factor is calculated by the PIC microcontroller. If the
calculated power factor is less than 0.9 then the relay switches on the capacitor. The relays
are switched using ULN2003 which is basically a driver IC. ULN2003 consists of seven
DARLINGTON PAIRS.
The current lead in capacitor compensates the corresponding current lag which is usually
present in loads. Hence the phase difference between the current and voltage will be reduced.
Power Factor Correcting capacitor connected parallel to load through relay, if the relay is
energized by microcontroller it will connect the capacitor parallel with load, if relay
deenergized it will remove the capacitor from the load. When the resistive load is on the power
factor will be near to unity so the microcontroller doesnt energize the relay coil. When the
inductive load is on the power factor decrease now the microcontroller energize the relay coil
in order to compensate the excessive reactive power. Hence according to the load the power
factor is corrected.
MikroC Program
b = TMR1L | (TMR1H<<8);
tm = (float)b/a;
pf = cos(tm*2*3.14);
x=abs(ceil(pf*100));
return x;
}
void main()
{
char c[]="0.00";
int a,b,d,x,f,e;
float tm,pf;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1)
{
a = powerFactor();
Delay_us(50);
b = powerFactor();
Delay_us(50);
d = powerFactor();
Delay_us(50);
e = powerFactor();
Delay_us(50);
f = powerFactor();
x = (a+b+d+f+e)/5;
c[3]=x%10 + 0x30;
x=x/10;
c[2]=x%10 + 0x30;
x=x/10;
c[0]=x%10 + 0x30;
Lcd_Out(1,1,"Power Factor");
Lcd_Out(2,1,c);
if(x<90)
{
PORTD.F0 = 1;
PORTD.F0 = 1;
Delay_ms(2000);
}
else
{
PORTD.F0 = 0;
PORTD.F0 = 0;
}
Delay_ms(250);
}
}
The function powerFactor() will find the current power factor by using the Timer 1 module of
PIC 16F877a. Power Factor may be fluctuating, so to avoid it we will find power factor more
than one time and its average is taken.
https://electrosome.com/automatic-power-factor-controller-using-microcontroller/
COMMENTS
fatih
i don t know why this program did not compile. can i know what exact version of
mikroC it has written for. thank you?
Ligo George
Stefaev
Ligo George
The code is correct.& we made this project with above code.. ,for the practical
implementation you need to modify the power factor correcting section of the code.
as this is only a prototype
Stefaev
Ligo George
Ligo George
Stefanev
So PORTD is output
do
{
if(PORTD.F0 == 1)
T1CON.F0 = 1;
else if(PORTD.F0 == 0 && T1CON.F0 == 1)
{
T1CON.F0 = 0;
break;
}
}while(1);
how to trigger the timer1 if the inputs are PORTA0 and 1 ???
Ligo George
Kalpesh
What is the value of Current Transformer ? Which Current Transformer should i use ?
Ligo George
jun
Hi sir I understand the source code,can you give me the sample current ratio or
specification detail of current transformer
Ligo George
dark
sir which compiler shuold i use for compiling currently i use mikroc pro for pic v6.0.0
but they get an error
Ligo George
sunny
is this a prototype?
Ligo George
karthik
Current Transformer and voltage transformer can be replaced with any other
electronic circuit its possible ..
Ligo George
karthik
karthik
karthik
Ligo George
Ligo George
I think.. no modification is needed in the circuit but you should modify the
program It is my logic I have tested it only once so you should modify the
program by conducting some practical tests and calibrating this project..
mehmet iek
Brother, is int powerFactor() a kind of interrupt? Can you explain it or give some
documants?
Ligo George
No, it is not a kind of interrupt.. it is a function to evaluate power factor using internal
timer modules of pic microcontroller..
naim
im doing this project for my final year project.can you please share this project with
me?send it to my e-mail ([email protected])
naim
what is the value of power factor correction capacitor at the ac main output?
naim
Ligo George
Ligo George
Ligo George
The complete project details including the project files are shared above..
RyRS
Excuse me sir, but I didnt see any download link are shared above. Thank you.
Ligo George
I have an Arduino micro-controller & I creating a Power factor meter. So i need some
help my brothers..
Ligo George
Mithun
Ligo George
RyRS
Would you mind to share or send to email the hex file perhaps? My mikroc pro for pic
6.0 seems giving an hex file size 1kb only after I compile the code. Thank you.
Ligo George
RyRS
A few of modification of circuit and using ccs c compiler ccp(capture) example, i got
a power factor based on comparison between two signal using proteus simulation.
Hope you dont mind that i did some modification on your circuit. I wont share my
email to public, so thank you for giving an idea about measuring power
factor.
Ligo George
OK..
Shaik Aryan
Ligo George
Cabir
hi all
this circuit sucks
The in and outputs of uln2003 are on the wrong side
Ligo George
Sorry for the inconvenience caused It is corrected.. Please try after clearing your
cache..
dalwinder singh
tm = (float)b/a;
pf = cos(tm*2*3.14);
x=abs(ceil(pf*100));
can you elaborate this function i.e. what (a) and (b) shows
dalwinder singh
Ligo George
It is the measured timer value of current and voltage waves
Ligo George
dalwinder
dalwinder
Ligo George
Wavelength of pulse..
Ligo George
Giscard Hangi
Hi , I am working on a similar project but for a 3 phase system. I would like to know
how did you manage the problem of linearity and phase displacement of the CT in
particula?
kaushal
Can you please mention in my email, what current sensor and what rating voltage
transformer to use
Thank you
kaushal
can I run this code in mplab
vohsty
Hallo sir
Please send me the corrected code because when i load his one on proteus nothing
happens although it compiles without errors
my email is [email protected]
juhi
mughees ahmed
Please send me the corrected code because when i load his one on proteus nothing
happens although it compiles without errors
my email is [email protected]
There should be some header files. See your code does not include any header files ,
compiler crazy about where does that Lcd_init(); or Lcd_write() came from?
May be you could have longer delays.250ms is not enough at all. Since the power
factor does not change quickly you could have delay at least 10seconds. Or give the
user a configuration option to configure it.
ahmedduaa
hey , please can you send me the file of this project i need it for my collage
my email: [email protected]
faheem
Nauman Safdar
Did Some one practically implemented this? i tried but the display value changes
randomly for the same load
Jigar
arslan rao
i don t know why this program did not compile. can i know what exact version of
mikroC it has written for. thank you?
Please send me the corrected code because when i load his one on proteus nothing
happens although it compiles without errors
my email [email protected]
arslan rao
juhi
naim
what type of current transformer did you used?i mean the name of the transformer or
no or something else that i can find and buy it
anwar
hi im doing the project with atmega 16 . i have made the required changes in this code
to be compatible with atmega. the code compiles without error but nothing happens
on proteus. kindly help me out with this. i have to submit my project very soon
Angelo
Regards
aregawi
Stefan
Monjur Morshed
bro,,,i worked with the pf calculation part only,,,& the code compiles fine,,,,,,,but
when i tried it in proteus it gives error & Lcd is blank
lous mow
ahsan
did you get the rating of current transformer and potential transfortmer ?
ahsan
ahsan
Hey please tell me where i can find Current transformer in Proteus software ?
Ligo George
Ligo George
It depends on your requirements..
Ligo George
Ligo George
Check clock frequencies in mikroc project setting and pic properties in proteus.
Ligo George
It is not a joke man. .It is 100% working but it needs improvement.. in the power
factor correction section..
Ligo George
Above program is correct.. but it needs improvement in the power factor correcting
section..
Ligo George
I have only the above code.. It is written for MikroC Pro compiler..
It is working code.. only thing is it need improvement in the power factor correction
section..
Monjur Morshed
Ligo George
If the clock frequencies are correct in mikroc project settings and pic properties in
proteus..
Check the PIC used in mikroc project settings and proteus are same.. PIC 16F877A..
fazz
Hi mr. ligo,appreciate if you able to send the full correct code to my
email [email protected] to do for my house use.
Ligo George
ahsan
what rating you use of current transformer and voltage transformer please reply. i m
waiting for your concideration.
Ligo George
For voltage transformer you can use a 230/3V, 500mA transformer available in the
market
For current transformer.. you can wind depending on your requirements.. provide a
secondary voltage about 3V.
ahsan
alright thank you so much, please guide me can i use normal step down 12v, 2A
transformer in series for current measuring in lm358 ?
ahsan
ahsan
bdzah
Ligo George
We have no other codes.
Santosh
hi sir
i dont know how to create a hex file
i am doing the project in protecus???
is this good on going for that or whether i need to change the software ???
i dont how miroC works?????? can we build this same circut over there
santosh
Ligo George
MikroC is a compiler while proteus is a simulator.. You can compile your code with
MikroC to generate hex file.
Ligo George
Jaya Krishna G
Ligo George
ahsan
Ligo please help me, when i running this code in simulation it give an error of stack
underflow please correct this error or send me the correct code its not working.
please i have to submit my project at the end of this month.
Ligo George
Hello,
The above code is correct, it will work. only problems is that power factor
correction section needs improvement There is no errors..
I think, it is not good to simulate projects like this. Try in real hardware..
ahsan
Okay Mr.Ligo thanks for positive response. my hardware its almost ready i hope it
will work.
Fantan Moja
the code compiled successfully, just be smart on how you go about it in Micro C pro.
pranay
I have tried this programme but it isnt working with proteus simulation. Can you
send me hex file for this programme?
My email id is: [email protected].
Ligo George
You might not be able to simulate above project in proteus properly Try in real
hardware..
bhaskar
bhaskar
Ligo George
use a 3V transformer.
Ligo George
ur mean to say both rating (potential transformer & current transformer) are equal
(same) ?
Ligo George
Ligo George
thats what Im asking is that the op voltage of the both should be equal .
Ligo George
Output voltage always depends on the input I said about maximum / rms.
noufal
Plz send hex code
[email protected]
Ligo George
rajesh
kaustubh
will u please tell about the CT and PT ratings, i mean their turn ratio and current
rating
Ligo George
Ligo George
You should wind transformers depending on your current and voltage ratings
Design with 3V secondary voltage.
Ligo George
These are built in library functions of MikroC Pro compiler they dont require
header files..
habtamu
Ligo George
Basic function is explained in the article itself. The configuration of Timer 1 is not
explained.. it differs from microcontroller to microcontroller.
ibrahim
Please send me a correct [email protected]
Udit Jain
Ligo George
habtamutolasa
can you help me with pic microcontroller based ic tester for 74 series
here is my email [email protected]
madhu
sir whenever i tried to built the programme its showing demo limit in micro c pro
so iam not able to generate hex file because my compiler is a demo version so
plz send me the hex file or suggest wat to do to generate hex file .if u tel me to buy
original version of micro c pro its costlier..i cant afford tat much moneyy so kindly
give me some other option
mail id: [email protected]
Noor Ahmed
mukesh gupta
Ligo George
Ankur Chakraborty
The program is only showing black boxes on the LCD when done on hardware..what
to do? I checked all my connections
Ligo George
vikas
Bruno TARANTO
Nice project! My friend, i have to do this work using pic18f4550, could you help me
send me the files to ease my work? Please? [email protected] Thank you very
much!
Ligo George
Current transformers are commonly available now a days. You can even get it online.
Ligo George
zeeshan akbar
zeeshan akbar
Ligo George
agbor roland
hello please sir what is the reference values of the voltage and current transformers on
the power factor correction circuit you can reply me
on [email protected] thanks sir.
agbor roland
sir please tell me the reference values of the current and voltage transformers
avinash
avinash
Upload the hex file of this code this would be easier to dump to PIC
Rahul Raju
Iam doing this project now can you please send more information about this project
and the program i really dont have much program skill so please help my mail
id [email protected]
Karthick Selvan
Ligo George
No need of rectifier. The comparator will compare and will produce pulses.
Karthick Selvan
thanks sir and i have another doubt is this program corrects the pf automatically.
swapnil pandey
Hey can u tell the rating of ct for above circuit . I just need a reference as to by what
value current should be reduced???
Ligo George
No you need to improve that section. It is not completely correct. But reading section
is correct.
Ligo George
You can use a CT depending on the maximum current required for your load.
Karthick Selvan
Mouin Zwayni
sai teja
sir! im getting difficlty in running the program! can u plz check and send me the exact
code?
mail : [email protected] please! a kind request!
Ligo George
You need to select proper power factor selection capacitors depending on your load
requirements.
You need to improve power factor correction mechanism of the program.
Ligo George
There is no download for this. You can take the program above.
nanjegowda
nanjegowda
iam not able to generate hex file because my compiler is a demo version so plz send
me the hex file or suggest wat to do to generate hex file .if u tel me to buy original
version of micro c pro its costlier..i cant afford tat much moneyy so kindly give me
some other option
mail id: [email protected]
nanjegowda
melese
pleas send me the materials and theire properties that you use on proteus software on
[email protected] i make mistak when i constract the circuit.
Ligo George
You can use the compiler MikroC Pro for doing it.
Ligo George
We are not providing the hex file as the project is not complete. Its power factor
measuring section is correct, but correction is not correct.
Ligo George
Sorry, we dont have the hex file. You can compile and generate it.
Ligo George
Tapiwanashe Augustine
Hey man thanks for the code, got it kicking on Proteus 8. Have had an exciting past
day since i couldnt use microc (2k limit). So I translated your code into Hitech C.
And just a pointer,,,,, ADCON1 = 0x06 if you want to make all of PORTA pins
digital input. Again, thanks for sharing, really helpful you guys.
Uzer
Saurabh
can you please send me your simulation in Proteus. Doing this project as my minor
and need help asap.
Tapiwanashe Augustine
email me at [email protected]
Ligo George
Ligo George
Ligo George
I didnt do any simulation for this project. Only tested in real hardware.
shaker
shaker
i don t know why this program did not compile. can i know what exact version of
mikroC it has written for. thank you?
shaker
in the last of the code write demo limit ? what is mean how can i remove this error
Rahul Wagh
please send me your hitech compiler code, i want this code because i use hitech
compiler and mplab IDE [email protected]
Rahul Wagh
sir, i try but not propery work, please send corrected code
melkamu
Ligo please help me, when i running this code in simulation it give
an error of stack underflow please correct this error or send me the
correct code its not working.
melkamu
melkamu
Ligo please help me, when i running this code in simulation it give
an error of stack underflow please correct this error or send me the
correct code its not working and how to improve power factor correction using pic
8051
Ardian
Vaibhav Chauhan