Press enter to see results or esc to cancel.

Power Factor Improvement Plant Using AVR Microcontroller | PART:02

The most challenging task  of this project is to determine power factor. Rest of the tasks are just switching Relays. So our first target is to find power factor using algorithm given in our first tutorial “Power Factor Improvement plant using AVR Microcontroller | Part:01

Before we proceed to download the project files and open schematic using proteus 7.8 or later version and open code using Atmel studio 6.00 or later version.
Power Factor Improvement Plant.rar file includes


  1. Atmel studio 6.2 project file (full source code)
  2. Proteus 7.8 schematic file.
  3. PDF schematic.

Circuit connection:

  1. upload the hex file(filename:PFI test1.hex) in atmega32 and connect lcd. In LCD connection 15(Anode) & 16(Cathode), no pin are not shown in schematic.

    These two pins will be connected with Vcc and GND. Connect VCC and GND with 15 & 16 pins of LCD and if LCD light is on then connection ok. if not, swipe the connection. Calibrate the brightness of LCD using potentiometer connected with VO (3 No) pin if you don’t see any text. 

  2. There is one contradiction in hardware and software connection.For simulation purpose, DC and AC ground are same. But in real circuit Ac ground will be 2.5V dc offset and AC and DC ground would not be shorted.


  3. Connect the current transformer according to the image given below.
  4. It is not good practice to connect all the components initially. Now you just connect the voltage divider for voltage sense and dc offset and a resistive load so that you can calculate power factor.
  5. So when you see for resistive load your power factor close to unity, then your connection may be ok. if not you to debug the connection.
  6. If you find garbage value then check whether your  voltage and current signal are distorted(peak to peak are not +2.5V to -2.5V) or garbage signal. So a USB to serial monitor can help you to see your voltage and current signal.
  7. So you need to print ADC value of voltage and current. So open the source code and uncomment the function print_voltage_current() and upload hex file into atmega32. I hope everything will be clear watching the video.

Some problems and Solutions:

Problem 01: You may face problems with LCD. Sometimes though all the connections are  ok, LCD shows nothing. This is because I connect LCD with C port of Atmega32. Normally in C port JTAG is enabled. So it cannot be used as normal I/O pin. SO before use this as I/O pin JTAG has to be disabled. An interesting topic is though I disabled JTAG twice in code section for some microcontroller(may be many times used atmega32) LCD was not working. That means JTAG was not disabled.
Solution:  In that case I changed LCD port and connected LCD with PORTB. For this, you need to edit lcd.h file. I edited this portion to connect LCD with PORTB.

#define LCD_DATA B  //Port PB0-PB3 are connected to D4-D7
#define LCD_DATA_POS 0 // This is the position first data pin D4.

#define LCD_E B //Enable/strobe signal
#define LCD_E_POS PB4 //Position of enable in above port

#define LCD_RS B //RS SIGNAL
#define LCD_RS_POS PB6

#define LCD_RW B //RW SIGNAL
#define LCD_RW_POS PB5

Problem 02:
At one point I observed through I was connecting capacitors in parallel with resistive load, but power factor was not changing & remained close to unity. Just a  strange and weird problem.
Solution:  I connected USB to the serial(FT232) converter to see waveform and uncomment print_voltage_current() function to plot the graph of voltage and the current waveform. plotting the ADC value in excel according to video given in our first part of this project, I found such graph.

current waveform

As current signal shown unusual behave. The problem is in the resistive load. Connecting new resistive load, the system was behaving accurately.
This is how we solved two problems. There are many problems you may face while doing this project. I hope you can solve the problem by yourself.