Arduino - PV MPPT Solar Charger




Introduction: Arduino - PV MPPT Solar Charger

About: I,m an Electronics Engineer. Love to make things work. Believe in Learn by Making it.

There are many charge controllers available in market. ordinary cheap charge controllers are not efficient to use maximum power from solar Panels. The ones which are efficient, are very costly.

So i decided to make my own charge controller which is Efficient, and smart enough to understand the battery needs and solar conditions. it takes appropriate actions to draw maximum available power from solar and put it inside the battery very efficiently.


Step 1: What Is MPPT and Why Do We Need It?

Our Solar panels are dumb and not smart to understand the battery conditions. Assume we have a 12v/100 watt solar panel and it'll give an output between 18V-21V depends upon manufactures, but batteries are rated for 12v nominal voltage, at full charge conditions they will be 13.6v and will be 11.0v at full discharge. now lets assume our batteries are at 13v charging, panels are giving 18v, 5.5A at 100% working efficiency(not possible to have 100% but lets assume). ordinary controllers have a PWM voltage regulator ckt which drops the voltage to 13.6, but no gain in current. it only provides protection against over charging and leakage current to panels during nights.

So we are having 13.6v*5.5A = 74.8 watt.

We loose approx 25 watt.

To encounter this issue i have used smps buck converter. these kind of convertes have above 90% efficiency. even 90% is considered worst.

Second problem that we have is non-linear output of solar panels. they needs to be operated at certain voltage to harvest maximum available power. Their output varies through the day.

To solve this issue MPPT algorithms are used. MPPT(Maximum Power Point Tracking) as the name suggests this algorithm tracks the maximum available power from panels and varies the output parameters to sustain the condition.

So by using MPPT our panels will be generating maximum available power and buck converter will be putting this charge efficiently into batteries.


I,m not gonna discuss this in detail. so if you wanna understand it have a look to this link -What is MPPT?

In this project i have tracked the input V-I characteristics and output V-I also. by multiplying the input V-I and output V-I we can have the power in watts.

lets say we are having 17 V, 5 A i.e. 17x5 = 85 watt at any time of the day. at the same time our output is 13 V, 6A i.e 13x6 = 78 Watt.

Now MPPT will increase or decrease the output voltage to by comparing to previous input/output power.

if previous input power was high and output voltage was lower than present then output voltage will be lower down again to get back to the high power and if output voltage was high then present voltage will be increased to the previous level. thus it keeps oscillating around maximum power point. this oscillations are minimized by efficient MPPT algorithms.

Step 3: Implementing MPPT on Arduino

This is the brain of this charger. Below is the Arduino code to regulate the output and implementing MPPT in a single code block.

// Iout = output current

// Vout = output voltage

// Vin = input voltage

// Pin = input power, Pin_previous = last input power

// Vout_last = last output voltage, Vout_sense = present output voltage

void regulate(float Iout, float Vin, float Vout) {<br>  if((Vout>Vout_max) || (Iout>Iout_max) || ((Pin>Pin_previous && Vout_sense<Vout_last) || (Pin<Pin_previous && Vout_sense>Vout_last))) 
 duty_cycle -=1;
else if ((Vout<Vout_max) && (Iout<Iout_max) && ( (Pin>Pin_previous && Vout_sense>Vout_last) || (Pin<Pin_previous && Vout_sense<Vout_last)))
{<br>    duty_cycle+=1;
Pin_previous = Pin;
Vin_last = Vin;
Vout_last = Vout;

Step 4: Buck Converter

I have used N-channel mosfet to make the buck converter. usually people choose P-channel mosfet for high side switching and if they choose N-channel mosfet for the same purpose than a driver IC will be required or boot strapping ckt.

but i modified the buck converter ckt to have a low side switching using N-channel mosfet. i,m using N-channel because these are low cost, high power ratings and lower power dissipation. this project uses IRFz44n logic level mosfet, so it can be directly drive by an arduino PWM pin.

for higher load current one should use a transistor to apply 10V at gate to get the mosfet into saturation completely and minimize the power dissipation, i have also did the same.

as you can see in ckt above i have placed the mosfet on -ve voltage, thus using +12v from panel as ground. this configuration allows me to use a N-channel mosfet for buck converter with minimum components.

but it also have some drawbacks. as you have both sides -ve voltage seperated, you don't have a common reference ground anymore. so measuring of voltages are very tricky.

i have connected the Arduino at Solar input terminals and using its -ve line as ground for arduino. we can easily measure the input volateg at this point by using a voltage divider ckt as per our requirement. but can't measure the output voltage so easily as we don't have a common ground.

Now to do this there is a trick. instead of measuring the voltage accros output capacitor, i have measured the voltage between two -ve lines. using solar -ve as ground for arduino and output -ve as the signal/voltage to be measured. value that you have got with this measurement should be substracted from the input voltage measured and you will get the real output voltage across output capacitor.

Vout_sense_temp=Vout_sense_temp*0.92+float(raw_vout)*volt_factor*0.08; //measure volatge across input gnd and output gnd.<br>
  Vout_sense=Vin_sense-Vout_sense_temp-diode_volt; //change voltage difference between two grounds to output voltage.. 

For current measurements i have used ACS-712 current sensing modules. They have been powered by arduino and connected to input gnd.

internal timers are modified to gain 62.5 Khz PWM at pin D6. which is used to drive the mosfet. a output blocking diode will be required to provide reverse leakage and reverse polarity protection use schottky diode of desired current rating for this purpose. Value of inductor depends upon frequency and output current requirements. you can use online available buck converter calculators or use 100uH 5A-10A load. never exceed the maximum output current of inductor by 80%-90%.

Step 5: Final Touch Up -

you can also add additional features to your charger. like mine have LCD too display the parameters and 2 switches to take input from user.

I'll update the final code and complete ckt diagram very soon.

Step 6: UPDATE:- Actual Circuit Diagram, BOM & Code


I have uploaded the code, bom and circuit. it,s slightly different from mine, because it,s easier to make this one.



    • Creative Misuse Contest

      Creative Misuse Contest
    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest

    24 Discussions


    7 months ago

    I am getting error when trying to compile. Please help.

    Arduino: 1.8.2 (Windows 10), Board: "Arduino/Genuino Uno"

    C:\Users\980\Documents\Arduino\PV_MPPT_Solar_Charger\PV_MPPT_Solar_Charger.ino: In function 'void setup()':

    PV_MPPT_Solar_Charger:64: error: expected primary-expression before '/' token

    TCCR0B = TCCR0B & 0b11111000 | 0x01; / set pwm at Max... 62.5 Khz


    PV_MPPT_Solar_Charger:64: error: 'set' was not declared in this scope

    TCCR0B = TCCR0B & 0b11111000 | 0x01; / set pwm at Max... 62.5 Khz


    PV_MPPT_Solar_Charger:88: error: 'Vout_sense_temp' was not declared in this scope



    exit status 1

    expected primary-expression before '/' token

    This report would have more information with

    "Show verbose output during compilation"

    option enabled in File -> Preferences.

    1 reply

    use // instead of / .

    Hello, great project. Can you use a different solar painel? For example, 10w?

    1 reply

    Hello, congrats for your design, and thank you very mush for sharing it !
    It looks really interesting, at last to have a good working and efficient solar charger.
    I don't know so much of battery and electricity, so I have a few questions about your device.
    First I see few feedbacks,in spite of the deep relevance of the MPPT design. Do you have some new observation, did you fix the issue raised by Marbo ?
    Does the charger work well for you ?
    I'd like to use a charger for AGM or "deep discharge"-able battery, will it work properly with this kind of battery ?

    Well firstly a correction 12V lead acid batteries are fully charged at 12.7V.

    Secondly couldn't you put the code in an arduino text file ".ino" for easy download

    4 replies

    current code is highly customized for personal use. i'll clean it up and upload.

    and about batteries you are right but wrong also. A lead acid battery needs higher voltage i.e. 13.2 - 13.8 volts to charge properly. this voltage is considered as Float charging voltage. also if battery is deep discharged below 30% than a voltage of 14.2 - 14.8 volts is required to fast charge the battery, it,s known as Boost charging. this type of charging is required compulsory once in a month to remove sulfation from battery plates thus increases battery life.

    now you are right because a full charge battery have 12.7 volts at resting condition. but it requires higher voltage to force the current into the battery.

    A few tenths of a volt only . Any voltage over whatever the battery voltage sits at will start a current flowing . Going to say 13 Volts is sufficient . What do you think we have all these catchy names for ? . The manufacturer says , yeh- yeh- Boost charge it yeh. I'm saying don't be duped into destroying your batteries .

    yes 13v will force current in to battery but battery will reach to 13v very fast, and it will never be full charged. it,s due to chemical properties. i have worked with lead acid batteries alot due to my job. and personally noticed these conditions.

    Thats spot on, well explained.

    Hello how are you abhiV4 ? first I want to thank you for the work you have done on this project, congratulations, you would have offered me to help with this project, to continue the development for improvements, to upgrade to a higher amperage 20Ah 30Ah 40Ah 60Ah and etc, we need a lot of equipment imported in Brazil the tax is very expensive, to have an example if I buy a MPPT controller in china or the USA paying $ 80 when it arrives in brazil the tax is 3x the value of the product, unfortunately this is a problem that will not have solution, so I'm very excited to be able to design this MPPT controller, I'm waiting, hug and god bless.

    what kind of this MPPT algorithm? is that P&O? and if I want use another algorithm like Incremental conductance is there any changes of hardware?

    Hi! Can I have a copy of your solar_bom file? I cannot download the file you posted on this site as it says "Failed - Forbidden"

    Thank you!

    1 reply

    i have converted the BOM file to TXT file. now you can download the file.

    can you tell me about mosfet driver ic ?

    which one you use ?

    Hi looks great I want to built something like this. First I want to buy a set solar panels, charging station and battery but this turns out quite expensive.

    Your approach looks promising but do you have building plans, bom, and code.

    Awaiting your reply.

    2 replies

    just updated all things. thank you.

    BOM differs with power requirements of user. But only values of capacitor and inductor are changed.

    And yes i do have code but it's messed up. I'll clean it up and post a clean code here to avaoid any risks. Will also upload the complete ckt to build this.

    Excellent project! I was planning to make a MPPT controller for a long time for my 50W system but was not able to find a good tutorial. I would like to make this project. can I have the arduino code for this project? Also I would like to know how to drive the MOSFET gate with 10volts? Thank you!