In a solar power system, you want to take the maximum possible power from the photovoltaic (PV) panel. A maximum power point tracking (MPPT) controller does this. It keeps adjusting the panel’s operating point so the panel always delivers its highest power. In this step-by-step guide, we cover building an MPPT controller with Arduino and a synchronous buck converter, from theory to a tested PCB.

In this article
  • What MPPT does and why a synchronous buck
  • Inductor selection with worked calculations
  • Building the controller with Arduino
  • Firmware and tracking algorithm
Advertisements

Working with electricity involves serious risk. Ensure you have the necessary skills and take proper safety precautions before attempting any electrical projects. Proceed at your own risk — the author assumes no responsibility for any damage, injury, or issues resulting from the use or misuse of the information provided.

All content on this website is original and protected by copyright. Please do not copy or reproduce content without permission. While most of the resources shared here are open-source and freely accessible for your learning and benefit, your respect for our intellectual effort is appreciated.

If you find our tutorials helpful, consider supporting us by purchasing related materials or sharing our work — it helps keep the content flowing.

Need help or have questions? Leave a comment below — the author is always happy to assist!

Before we start building an MPPT controller with Arduino, we need to understand two things: MPPT itself and the synchronous buck converter.

Understanding MPPT and Synchronous Buck Converter

MPPT stands for maximum power point tracking. Solar charge controllers use it, and so do some wind turbine controllers, to get the most power from the source as conditions change.

Here is how it works:

  • The panel output varies: a solar panel’s voltage and current change with sunlight, temperature and shading.
  • There is one best point: for each set of conditions, one voltage and current combination gives the highest power. This is the maximum power point (MPP).
  • MPPT finds that point: the controller keeps measuring the panel and adjusts its own input so the panel stays at or near the MPP. As a result, the most power reaches the battery or grid.

Think of a bicycle. You produce the most power at one pedalling speed. If you pedal too slowly or too fast, you produce less. MPPT works like automatic gears: it changes the “gear” so the panel always works at its best speed.

For a solar panel, the power curve looks like this:

Building an MPPT Controller with Arduino

A worked example

For example, take a panel with an open-circuit voltage of 22 V and a short-circuit current of 10 A. If you draw no current, the voltage stays at 22 V. However, the current is zero, so the power is:

Power=Voltage×Current=22V×0A=0W

On the other hand, if you short the panel and draw the full 10 A, the voltage falls to 0 V:

Power=Voltage×Current=0V×10A=0W

So at both extremes, the panel delivers no power at all.

Now, if you run the panel at about 17 V, it may deliver about 8 A. The power is then:

Power=Voltage×Current=17V×8A=136W

This is the idea behind MPPT. The controller holds the panel at the voltage and current that give the highest power, which in this example is 136 W at 17 V.

🧮 Free tool for this topic

Use of MPPT

MPPT is mainly used in solar charge controllers. Here is why it matters:

  • More energy: compared with a simple PWM controller, MPPT typically harvests 10–30 % more energy. The gain is largest in cold weather and when the panel voltage is well above the battery voltage.
  • Better in changing conditions: MPPT keeps tracking as clouds pass or temperature changes. Note, however, that a simple tracker can lock onto a local peak under partial shading.
  • Flexible voltages: you can use a higher-voltage panel string with a lower-voltage battery. This also reduces cable current and losses.

In summary, MPPT makes a solar system more efficient, because it keeps the panel at its maximum power point.

Now, let us make our own MPPT controller. Before that, I recommend reading my other article:
Make an MPPT solar charge controller with a synchronous buck converter

What is a synchronous buck converter

A synchronous buck converter is a DC/DC converter that steps a higher input voltage down to a lower output voltage with high efficiency. It is used everywhere, from processor supplies to solar chargers.

***If you want to learn other DC/DC converters, read this article here.

In simple terms:

  1. What Does It Do?
    • It converts a higher voltage, such as 24 V, to a lower one, such as 12 V or 5 V.
    • It wastes very little energy, so it suits battery and solar systems.
  2. Why Is It Called “Synchronous”?
    • A standard buck converter uses a diode as the low-side switch. A synchronous buck converter replaces that diode with a second MOSFET. Because a MOSFET drops much less voltage than a diode, it wastes less energy as heat.
  3. How Does It Work?
    • The converter switches the MOSFETs on and off at high frequency.
    • An inductor and a capacitor smooth the pulses into a steady lower voltage.

How a synchronous buck converter works

Let us look at the circuit step by step.

In this example, the main control switch (a MOSFET) sits at the top. When it turns on, it connects the input to the output through the inductor. During this time, the inductor current rises and the inductor stores energy.

When the control switch turns off, the inductor keeps the current flowing. In a standard buck converter, a diode carries this current. However, the diode drops about 0.4–0.7 V, so it wastes power and lowers the efficiency.

To fix this, we replace the diode with a synchronous rectifier (SR) MOSFET. When it is on, its voltage drop is only the current times its on-resistance, which is much lower than a diode drop. As a result, the converter loses much less power.

Building an MPPT Controller with Arduino

For example, at 10 A, a Schottky diode with a 0.5 V drop wastes about 5 W. In contrast, a MOSFET with 5 mΩ on-resistance wastes only 0.5 W.

For this to work, the SR MOSFET must turn on only when the control switch (CS) MOSFET is off. In addition, you must leave a short dead time between the two. Otherwise, both MOSFETs can be on together and short the input supply.

Done right, this gives high efficiency and safe operation.

Now, let us design our MPPT controller circuit with this concept.

Building an MPPT Controller with Arduino

Here is the circuit diagram of our MPPT controller with Arduino and a synchronous buck converter:

Building an MPPT Controller with Arduino

In this circuit, Q1 and Q4 are extra MOSFETs. They work as “ideal diodes” on the panel side and the battery side. For example, they stop the battery from feeding current back into the panel at night. Because a MOSFET drops far less voltage than a Schottky diode, they also cut conduction losses.

The gate drive keeps these MOSFETs in step with the main switch. We use this technique in our own products to improve both efficiency and protection.

Why the inductor matters

In a synchronous buck converter driven by a gate driver such as the IR2104, the right inductor is just as important as the right circuit.

A higher inductance reduces the current ripple, which makes control easier. However, it needs more turns, so the winding resistance and copper loss rise. On the other hand, a lower inductance reduces copper loss but increases ripple. As a result, the RMS current, core loss and component stress all rise.

Therefore, you need a balance. Calculate the inductor from the output current, switching frequency, allowed ripple and load conditions.


Inductor selection guide:

Inductor selection is a key step in designing a synchronous buck converter, because it sets the efficiency, ripple current and transient response. Here is how to calculate the inductor value:

Building an MPPT Controller with Arduino

Key Parameters

Before you choose the inductor, you need to know:
1. Input voltage (Vin)
2. Output voltage (Vout)
3. Output current (Iout)
4. Switching frequency (f)
5. Inductor ripple current (ΔIL), typically 20–40 % of the output current.


Formula to Calculate Inductor Value

Step-by-Step Guide to Building an MPPT Controller with Arduino and a Synchronous Buck Converter – Formula to Calculate Induct

Where:

  • D=Vout/Vin ​​ is the duty cycle of the converter.

Step-by-Step Calculation

  1. Define Ripple Current (ΔIL​):
    Ripple current is chosen as a fraction of the maximum output current:ΔIL=k⋅Iout where k is the ripple current ratio (e.g., k=0.3  for 30%).
  2. Determine the Duty Cycle (D):D=Vout/Vin.
  3. Calculate Inductance (L): Using the formula: L=Vout⋅(1−D)ΔIL⋅Fs.

Example Calculation

Consider the following example:
Vin = 12V, Vout = 5V, Iout = 2A, f = 100kHz, and ΔIL = 30% of Iout.


1. Calculate the duty cycle:
   D = Vout / Vin = 5 / 12 ≈ 0.4167

2. Calculate the ripple current:
   ΔIL = 0.3 × Iout = 0.3 × 2 = 0.6A

3. Calculate the inductance:
   L = (Vout × (1 - D)) / (ΔIL × f)
     = (5 × (1 - 0.4167)) / (0.6 × 100,000)
     = (5 × 0.5833) / 60,000
     ≈ 48.6 μH


Thus, a 47 μH or 50 μH inductor would be a good practical choice.


Additional Considerations

1. Saturation current: the inductor’s saturation current must be higher than the peak current, with margin. The peak current is:
  Ipeak = Iout + (ΔIL / 2)

2. Core material: choose a core with low loss at your switching frequency.
3. Size and temperature: make sure the inductor fits and stays within its temperature rating at full load.

You can also use the calculators in All-in-one electronic tools and calculators to design your inductor.

With some practice, this becomes easy. Now, let us see what I built.

PCB of MPPT controller using Arduino

Here is the finished PCB:

Building an MPPT Controller with Arduino

Next, we need to test the circuit. First, we define the algorithm, and then we write the code. In this project, I use the perturb and observe (P&O) method for MPPT. It is one of the most common MPPT algorithms.

Although there are other algorithms available, I prefer the P&O method because of its simplicity and effectiveness in tracking the maximum power point of solar panels.

The charging algorithm

In this project, the algorithm works like this:

  1. Bulk mode: when solar power is available, the controller starts in bulk mode. It delivers as much current as the panel can give until the battery reaches the bulk voltage limit (14.2 V in this code).
  2. Float mode: after that, the controller holds the battery between 13.6 V and 13.8 V. The charging current falls slowly until it drops below the lowest current threshold (0.3 A).
  3. Rest mode: after float mode, charging stops for a while and the battery settles.
  4. Restart: if the battery voltage drops below the rest limit, the controller starts again in bulk mode.

This approach charges the battery safely and helps it last longer.

Note: the MPPT algorithm runs only in bulk mode, where we want maximum power. Once the battery reaches the bulk limit, the controller must not let the voltage go higher.

For more detail, read my article on lead-acid battery charging:

  1. Get a long life of your Lead-Acid battery by selecting the right charging method

Arduino code for our MPPT controller

#include <Adafruit_SSD1306.h>
#include "Wire.h"

#define SCREEN_WIDTH 128     // OLED display width, in pixels
#define SCREEN_HEIGHT 32     // OLED display height, in pixels
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Analog input pins
#define SOLAR_VOLTAGE_PIN A2
#define SOLAR_CURRENT_PIN A3
#define BATTERY_VOLTAGE_PIN A0
#define BATTERY_CURRENT_PIN A1

// PWM pin
#define PWM_PIN 3

// Global variables
float solarVoltage = 0.0;
float batteryVoltage = 0.0;
float solarCurrent = 0.0;
float batteryCurrent = 0.0;

// Constants
const int PWM_FREQUENCY = 20000;  // 20 kHz

const int pwmMin = 1;         // Minimum duty cycle
const int pwmMax = 100;       // Maximum duty cycle
const float stepSize = 0.02;  // Step size for perturbation

// Global variables
float oldPower = 0;    // Previous power reading
float newPower = 0;    // Current power reading
int pwmDuty = pwmMin;  // Initial PWM duty cycle
int lockoutCnt = 0;
int batteryPercentage = 0;

//control variables
const int BULK = 0, FLOAT = 1, NONE = 2, FULL = 3;
int chargeStage = BULK;
const float minimumBatteryVoltage = 8.0;
const float voltageDifferenceThreshold = 1.0;
const float bulkChargeVoltageThreshold = 14.2;

//Float charging settings
const float LowestBatChargingCurrent = 0.3;  //Amp
const float BatUpperLimit = 13.8;            //Volt
const float BatLowerLimit = 13.6;            //volt

//Full charging settings
unsigned long lastCurrentStableTime = 0;
const unsigned long waitTime = 20 * 60 * 1000;


void setup() {
  // Initialize Serial
  Serial.begin(115200);
  IntDisplay();
  InitPWM20KHz();
  DispintMsg();
}

void loop() {


  solarVoltage = ReadSolarVoltage();
  batteryVoltage = ReadBatteryVoltage();
  solarCurrent = ReadSolarCurrent();
  batteryCurrent = ReadBatteryCurrent();

  SetChargingModes();


  if (chargeStage == BULK) {
    perturbAndObserve();
  } else if (chargeStage == FLOAT) {
    FloatCharge();
  } else if (chargeStage == FULL) {
    MaintainBattery();
  }


  dispPages();
  delay(500);  // Update every second
}

Code explanation

#include <Adafruit_SSD1306.h> and #include "Wire.h"
These libraries are included to control the OLED display using the I2C protocol.

Then,

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

This initializes the OLED display with a resolution of 128×32 pixels and the I2C address 0x3C.

After that, the code defines other variables. Each one has a comment that explains it.

How the main loop works

In the main loop():

void loop() {
  solarVoltage = ReadSolarVoltage();
  batteryVoltage = ReadBatteryVoltage();
  solarCurrent = ReadSolarCurrent();
  batteryCurrent = ReadBatteryCurrent();

  SetChargingModes();

  if (chargeStage == BULK) {
    perturbAndObserve();
  } else if (chargeStage == FLOAT) {
    FloatCharge();
  } else if (chargeStage == FULL) {
    MaintainBattery();
  }

  dispPages();
  delay(500);
}

Reading Sensor Data:

ReadSolarVoltage(), ReadBatteryVoltage(), ReadSolarCurrent() and ReadBatteryCurrent() read the analog sensors. They are not shown here. Together, they give the panel and battery voltage and current.

Charging Mode Selection:

SetChargingModes() chooses the charging stage from the voltage, current and thresholds.

Bulk Charging:

In bulk mode, the code runs the MPPT algorithm perturbAndObserve() to take the maximum power from the panel.

Float Charging:

When the battery reaches the bulk limit, the code switches to float mode and calls FloatCharge(). This reduces the current and holds a safe battery voltage.

Full Charging:

When the float conditions are met, the code enters the full stage. Here, MaintainBattery() keeps the battery charged and stable.

Display Update:

dispPages() shows the system values on the OLED: voltage, current, charging mode and so on.

The loop has a 500 ms delay, so the display and the MPPT step update twice a second.

Charging Modes in Detail

  • Bulk Mode:
    The MPPT algorithm perturbs the PWM duty cycle to track the maximum power point of the solar panel.
  • Float mode:
    The current is reduced, and the battery voltage stays between 13.6 V and 13.8 V.
  • Full mode:
    After float charging, the controller monitors the battery. If the voltage drops below a set level, charging starts again.

The other functions are in separate files.

Building an MPPT Controller with Arduino

Now, let us test the project.

Testing of our MPPT controller using Arduino

Building an MPPT Controller with Arduino
Building an MPPT Controller with Arduino

Overall, the controller works well. I designed it as a base for a larger version. If you are interested in that, let me know.


Conclusion

In this article, we built an MPPT controller with Arduino step by step: the theory, the synchronous buck converter, the inductor calculation, the PCB and the code. I hope it helps you with your own design.

If you need a custom MPPT controller or have any questions, contact us on WhatsApp.

Liked this article? Subscribe to our newsletter:

Loading

or,

Visit LabProjectsBD.com for more inspiring projects and tutorials.

Thank you!

Read more:

See you again!

Related on LabProjectsBD

Building a solar charger or battery product? We design power electronics, embedded firmware and production-ready PCBs for clients. Message us on WhatsApp or use the contact form.


MKDas

Mithun K. Das. B.Sc. in Electrical and Electronic Engineering (EEE) from KUET. Senior Embedded Systems Designer at a leading international company. Welcome to my personal blog! I share articles on various electronics topics, breaking them down into simple and easy-to-understand explanations, especially for beginners. My goal is to make learning electronics accessible and enjoyable for everyone. If you have any questions or need further assistance, feel free to reach out through the Contact Us page. Thank you for visiting, and happy learning!

37 Comments

CHIMEZIE · 01/02/2025 at 1:23 am

thank you very much for this project, please i will love to build this MPPT unit but i have some questions
1. the code dose not mention the allowed max charging current, so how dose the system chooses the correct current during bulk charge.
2. to increase the solar input voltage to 80 volts what do i need to change in the circuit apart from R8 and R9 voltage divider, also what has to change in the code to achieve this new input voltage level,, thanks..

    MKDas · 02/02/2025 at 11:29 am

    Thank you for your comment. Designing for higher voltage and current ranges requires careful attention to additional protective measures and voltage conversion stages.

    Current Range: There’s no specific limit on the maximum current in the code. The key is selecting a solar panel with the appropriate power (wattage) rating. The MPPT algorithm will always attempt to extract the maximum possible power from the panel.

    High-Voltage Input (e.g., 80V):

    Inductor (Coil) Design: Ensure the coil is optimized for higher voltages and currents.
    MOSFET Selection: Choose MOSFETs with adequate voltage and current ratings, low Rds(on), and high efficiency.
    Thermal Management: Use proper heat sinks and, if necessary, additional cooling fans.
    Temperature Monitoring: Include temperature sensors to monitor and protect against overheating.
    Power Supply and Voltage Sensing: Modify the power supply circuit and sensing stages to handle the higher voltage safely.
    Firmware Adjustments: Update code variables to accommodate higher operating ranges.
    If you need professional assistance, feel free to contact me on WhatsApp.

      CHIMEZIE · 02/03/2025 at 10:42 pm

      Engineer thank you very much for your reply,

      I have been struggling to understand your MOSFETs configuration in the schematic,

      example gates off Q1 and Q4 are linked together from a single resistance R2 of 22ohm ,

      also Q4 have a higher gate resistance of 1k, is this an error or not? Please how does it work.. thanks

        MKDas · 04/03/2025 at 11:40 am

        Well, thats the interesting part of this design. Those MOSFETs are used as Diode and while the Main switch Q2 is switched on, those are also. But while Q3 is also acting as a synchronous diode, those two are kept off to prevent short circuit.

        Usually, people do not use Q4. But I use in my practical designs to reduce heat loss. Q4 gate resistance is higher, because the signal is already boosts by IR2104. To keep it under Vgs range, resistors are used.

        I hope you got it now.

          CHIMEZIE · 10/03/2025 at 2:14 am

          Engineer thank you for replying, I now understand,

          One final observation in the circuit the gate resistor 22ohm R2 is shared by Q1 and Q2 and not separate,
          Please why are they not using separate gate resistors?

          MKDas · 10/03/2025 at 11:59 am

          No needed. but if you want to use extra resistor, you can use

Enrique · 02/02/2025 at 9:42 pm

Excelente trabajo ,soy aficionado a la electrónica todo lo que tiene que ver con fuentes me interesa mucho y estas publicaciones me ayudan mucho para entender de forma practica el funcionamiento. muchas gracias, sigo todas sus publicaciones

    MKDas · 04/02/2025 at 11:15 am

    Thank you! 👍👍👍

PAUL · 02/03/2025 at 11:04 pm

Please am having issues designing this

C1 is 10uf, what is the voltage of C1..?

Also can i use 1N4148 for D1…?

Finally I noticed that R3 and R4 are directly connected to the gate of Q3… Please is the connection correct or an error?

    MKDas · 04/03/2025 at 11:41 am

    use 25 or 50v one for C1. And for diode, use any fast diode that can support minimum 50KHz. R3 and R4 are correct.

Ige Daniel · 30/04/2025 at 1:05 am

I got the inductor calculations but I have difficulty in designing the appropriate one, not giving the expected results, please kindly help.

Oscar · 06/05/2025 at 4:26 pm

I am interested in this project, but I want to know if the IR2104 is connected correctly. I have no experience with 2104 before. I found that the Vcc port of IR2104 is not connected to any input power source in the circuit diagram.

    MKDas · 06/05/2025 at 6:06 pm

    If you are using 12V setup then connect that VCC pin to solar positive. if you use 24V setup, then connect that to B+ with a 100R 0.5W Resistor.

Paul · 06/10/2025 at 9:55 pm

Hello sir, please I have an issue, Q4 heats up rapidly and output efficiency is around 75%, please what could be the issue and did you encounter this behavior too, please suggest a solution for me.. thanks

    MKDas · 07/10/2025 at 12:03 pm

    Check the Vgs of Q4. Also ensure Rgs is not less than 10K.

Paul · 15/10/2025 at 1:09 am

Sir please is it also important to reduce R6 to a lower resistance value..? To enable full switching of Q4.. and finally Sir please what is the expected efficiency from your experience…?

    MKDas · 16/10/2025 at 12:26 pm

    R6 used for noise filtering. use minimum 10K max 100K

Paul · 17/10/2025 at 9:20 pm

Thanks for your quick reply sir,

Please check the circuit again as R6 is actually 1k (gate resistor).. my question is don’t you think the 1k is preventing Q4 from switching fully..?

    MKDas · 18/10/2025 at 1:02 pm

    not really. just use high pull down resistor.

noop K A · 18/10/2025 at 2:15 pm

sir code uploading error
Compilation error: ‘IntDisplay’ was not declared in this scope

    MKDas · 22/10/2025 at 12:29 pm

    Check if you missed the file

Anoop k A · 18/10/2025 at 11:58 pm

I made this circuit but i can’t upload code compiling error please send the code

    MKDas · 22/10/2025 at 12:29 pm

    send your erros images to WhatsApp

Ben · 29/10/2025 at 7:19 am

Hello sir, please I have a question. First, does the Arduino’s GND need to be connected to the IR2104’s COM? And second, can I use a Fully 12V 7Ah lead-acid battery as a load directly? Will it draw current? Please suggest a solution for me. Thanks

    MKDas · 01/11/2025 at 11:42 am

    both arduino and IR2104 GND / COM are common.

    you can use 12V lead acid batteries in the place of BAT

      Ben · 02/11/2025 at 10:06 am

      Thank you for your reply.
      I have a few more questions that I would like to ask for your advice on.
      First, can I use a power supply instead of a solar panel for testing purposes?
      Also, if I use an LM2596 step-down module to convert a Vin of 18V down to 12V, would it be suitable to supply power to both the IR2104 and a 7805 regulator for the Arduino?

        MKDas · 02/11/2025 at 6:53 pm

        if you use power supply, it will draw the max possible output from power supply. yes you can use it but it will show the power supply is always at high amp output.

        and you can use LM2596 for DC/DC no issue.

      Ben · 04/11/2025 at 8:38 pm

      The code you uploaded can’t be used as is yet, right? It still needs configuration in the sections for Reading Sensor Data and Charging Mode Selection, such as the voltage divider circuit or the ACS712.

        MKDas · 06/11/2025 at 12:08 pm

        if you change in the hardware then you must configure that properly.

Selasi · 09/11/2025 at 9:29 pm

I have a feeling that leading international company you work at is Tesla.

Rainto · 19/12/2025 at 11:41 am

Hi, Please need full code if available. Thank you

    MKDas · 19/12/2025 at 12:02 pm

    Full code is give here.

Nono · 16/01/2026 at 8:36 pm

Hi!
I would like to create this MPPT regulator for a school project in which I am trying to compare the charge of a 3S lithium battery with a solar panel with and without a regulator. So I was wondering if it was possible to create it for a fairly high panel output voltage (40V). I don’t know much about electronics, should these components be connected to a microlab board?
Thank you for your help.

    MKDas · 17/01/2026 at 2:16 pm

    That is totally risky. But if you understand the concept, then you can design the buck converter to convert incoming voltage to suitable output range for your cells. then control using the algorithm

Saurabh sharma · 07/02/2026 at 8:48 pm

Sir, if we use synchronous half bridge design to make buck mppt, when connect battery on output it makes spikes like short circuit and blows mosfets or fuses, if we run from solar first then conne t battery it works well. How can i solve this issue? I am not using q4 as like you.

    MKDas · 13/02/2026 at 12:15 pm

    because of the diode. check you are not using any diode on the output. if you don’t use any diode, the lower switch will short the battery through inductor. so it will get burnt itself.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *