• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: Home / Battery Charger Circuits / Smart Buck-Boost MPPT Solar Charger Circuit for 12V 24V Battery

DIY Circuits | Learn Basics | Arduino Coding




Smart Buck-Boost MPPT Solar Charger Circuit for 12V 24V Battery

Last Updated on July 10, 2025 by Swagatam 2 Comments

In this post we are going to learn how we can make one real working smart solar battery charger circuit which can do MPPT charging. We are using Arduino Nano as the brain for controlling everything. We will also use INA219 sensor module so that we can read the solar voltage and current properly.

And then we will use buck-boost converter so that it can reduce or increase voltage depending on battery level and panel level.

After that we are going to show everything on lcd screen so that we can see solar voltage current battery voltage and power.

This one will support both 12V and 24V batteries and we can also add two batteries and charge them one by one automatically using relay switch.

So this project is very useful for people who have solar panel and want to charge different batteries with smart control.

Parts Required

partspecificationquantity
arduino nanowith usb port1
ina219 modulecurrent + voltage sensor1
buck-boost convlm2587 or xl6009 or custom1
lcd display16x2 with i2c module1
relay module2 channel, 5v1
mosfetirf540n or irlz44n2
diode1n5822 schottky2
capacitor470uf 35v + 100nffew
resistors10k, 220 ohmfew
potentiometer10k trimmer1
solar panel18v or 24v 100w or more1
battery12v and 24v lead acid1 or 2

Main Features

So this charger is having many smart features which makes it better than normal pwm charger. First thing is that it is doing real mppt by tracking power point from solar panel.

Then it can charge both 12V and 24V battery. Also it can handle low voltage panel or high voltage panel and still charge properly because we are using buck boost converter.

Also we are using two relay output so that we can connect two batteries and charge them one after one. On top of that we can see all reading on lcd like voltage current power and pwm value.

How this MPPT Charger Works

So what we are doing here is very simple to understand in basic way. We are giving solar panel output to one current sensor module INA219. This one reads the voltage and current from panel. Then we give that to buck boost converter input.

The output of this converter goes to battery through one mosfet and schottky diode. Arduino Nano is reading everything and checking solar power value. It increases or decreases pwm to find the maximum point.

This is called perturb and observe technique which is used for mppt. It also checks battery voltage and cutoff when full. And it switches between battery 1 and battery 2 using relays.

Step by Step Connection Guide

1. how to connect solar panel to the current sensor ina219

So first we will take the two output wires from our solar panel. One will be the positive wire and other will be the negative wire.

Now we take the positive wire of the solar panel and connect that one to the Vin+ pin of the INA219 module. After that we take the negative wire of the panel and connect it to the GND pin of the INA219.

Now after doing that we have to connect the Vin– pin of the INA219 module to the positive input terminal of the buck-boost converter.

Then the GND pin from the INA219 (which is also connected to solar panel negative) should also go to the negative input terminal of the buck-boost converter. So this way the INA219 module comes in series with the solar positive line and reads the current correctly.

So final:

  • solar positive → ina219 Vin+
  • ina219 Vin– → buck-boost input +
  • solar negative → ina219 GND → buck-boost input –

2. how to connect the output of buck-boost to the battery through mosfet and diode

Now we will take the output positive terminal of the buck-boost module and connect that to the Source pin of the IRF540N or IRLZ44N mosfet. This source pin is usually the first leg from the left side when the flat face is in front of us.

Now the Drain pin of the same mosfet should go to the Anode of one Schottky diode like 1N5822. Then the Cathode of this diode should be connected to the positive terminal of the battery. This diode will stop the battery from discharging back into the converter.

The negative output terminal of the buck-boost converter should be connected directly to the negative terminal of the battery. No switching is needed here.

So this completes the controlled battery charging path using the mosfet and diode.

So final:

  • buck-boost output + → mosfet source
  • mosfet drain → diode anode → battery positive
  • buck-boost output – → battery negative

3. how to connect battery voltage sensing to arduino

Now we have to read the battery voltage using Arduino. But since battery voltage can be 12V or 24V and Arduino can only read up to 5V, we must use a voltage divider.

We will use two resistors in series, one 10k and one 2.2k resistor. First we connect the battery positive to the top end of the 10k resistor. Then the bottom end of the 10k goes to the top of the 2.2k resistor. And the bottom of the 2.2k resistor goes to GND.

Now we take the middle point between 10k and 2.2k and connect that one to A1 pin of the Arduino Nano. This will give scaled down battery voltage.

So final:

  • battery positive → 10k → 2.2k → GND
  • 10k-2.2k middle point → Arduino A1

why we must monitor battery voltage during charging

The main purpose of sensing the battery voltage using a voltage divider in the MPPT Arduino code is exactly that, to monitor the battery level and cut off charging when the battery becomes fully charged.

So when we are using MPPT solar charging system with Arduino, the solar panel is giving full power to the battery based on sunlight and maximum power point. But if we do not check the battery voltage then the charging will continue forever. That will make the battery overcharged which is very dangerous. It can overheat, bulge, leak or even blast in some rare cases.

So we must always keep track of the battery voltage during charging and we must stop the charging when battery reaches safe full charge limit.

4. how to connect pwm signal to buck boost converter

Now we have to control the duty cycle of the buck boost converter using PWM signal from Arduino. If the buck-boost module already has a PWM input pin, then we simply connect Arduino D9 pin to that PWM control pin of the module.

But if the module does not support pwm, then we must build a custom circuit using mosfet, diode, inductor and capacitor that behaves like buck-boost and then drive the mosfet with PWM from D9.

So final:

  • Arduino D9 → PWM input of converter (or mosfet gate in custom build)

5. how to connect two batteries using relay module

So now if we want to connect two batteries, then we use one 2-channel relay module. This module has two relays, each with three terminals — NO (Normally Open), COM (Common), and NC (Normally Closed).

We connect the NO terminal of Relay 1 to the positive terminal of Battery 1. We connect the NO terminal of Relay 2 to the positive terminal of Battery 2.

Now we take both COM terminals from Relay 1 and Relay 2 and join them together, and then connect that to the output of the converter through a Schottky diode. That diode blocks reverse flow from battery to converter.

This way when Relay 1 is activated, Battery 1 gets charged. When Relay 2 is activated, Battery 2 gets charged.

The IN1 and IN2 pins of the relay module are connected to D6 and D7 of Arduino. Arduino will switch them as needed.

So final:

  • Relay1 NO → Battery1 +
  • Relay2 NO → Battery2 +
  • Relay1 COM and Relay2 COM joined → Diode → converter output +
  • Relay IN1 → Arduino D6
  • Relay IN2 → Arduino D7

6. how to connect lcd i2c display

Now we connect the 16x2 LCD with I2C module to Arduino.

  • Connect the SDA pin of the LCD to A4 of Arduino Nano.
  • Connect the SCL pin of the LCD to A5 of Arduino Nano.
  • Connect the VCC of LCD to 5V pin of Arduino.
  • Connect the GND of LCD to GND of Arduino.

So final:

  • LCD SDA → Arduino A4
  • LCD SCL → Arduino A5
  • LCD VCC → 5V
  • LCD GND → GND

Arduino Logic

Now I will tell how Arduino is working in this project. First Arduino will take readings from solar panel using INA219 module. It will get voltage and current and then multiply both to get power.

Then it compares that with last reading. If power is increased then it increases pwm little. If power is decreased then it reduces pwm.

This way it finds maximum point of power and keeps it there. Then it reads battery voltage using voltage divider and analog read.

It shows all values on LCD screen. It also controls relay 1 and relay 2 so that we can charge both batteries one after one. If battery is full then it cuts charging.

Circuit Diagram

Arduino Code

#include <Wire.h>
#include <Adafruit_INA219.h>
#include <LiquidCrystal_I2C.h>

Adafruit_INA219 ina219;
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD with I2C

int pwmPin = 9;
int battPin = A1;

float voltage = 0;
float current = 0;
float oldPower = 0;
int pwmValue = 100;

float batteryVolt = 0;
float fullLimit = 14.4; // full charge cutoff voltage
bool cutoff = false;    // latch flag

void setup() {
  Serial.begin(9600);
  ina219.begin();
  lcd.begin();
  lcd.backlight();
  pinMode(pwmPin, OUTPUT);
  analogWrite(pwmPin, pwmValue);
}

void loop() {
  // read battery voltage
  float raw = analogRead(battPin);
  float sensed = raw * (5.0 / 1023.0);
  batteryVolt = sensed * ((10.0 + 2.2) / 2.2);  // voltage divider scaling

  // check for full charge
  if (batteryVolt >= fullLimit) {
    analogWrite(pwmPin, 0);  // turn off PWM
    cutoff = true;           // set latch
  }

  // do mppt only if not cutoff
  if (!cutoff) {
    voltage = ina219.getBusVoltage_V();
    current = ina219.getCurrent_mA() / 1000.0;
    float power = voltage * current;

    if (power > oldPower) pwmValue += 1;
    else pwmValue -= 1;
    pwmValue = constrain(pwmValue, 50, 230);
    analogWrite(pwmPin, pwmValue);
    oldPower = power;
  }

  // display everything
  lcd.setCursor(0, 0);
  lcd.print("S:");
  lcd.print(voltage, 1); lcd.print("V ");
  lcd.print(current, 1); lcd.print("A");

  lcd.setCursor(0, 1);
  lcd.print("B:");
  lcd.print(batteryVolt, 1); lcd.print("V ");
  lcd.print(pwmValue);

  delay(1000);
}

You'll also like:

  • solarpaneloptimizerHow to Make a Solar Panel Optimizer Circuit
  • simplempptchargercircuitHomemade Solar MPPT Circuit – Poor Man’s Maximum Power Point Tracker
  • 12v2B52Bamp2Btransformerless2Bbattery2Bcharger2Bcircuit12V, 5 Amp SMPS Battery Charger Circuit
  • AlternatorPowerBooster5B15DGenerator/Alternator AC Voltage Booster Circuit

Filed Under: Battery Charger Circuits, Solar Controller Circuits Tagged With: Boost, Buck, Charger, MPPT, Smart, Solar

About Swagatam

I am an electronics engineer and doing practical hands-on work from more than 15 years now. Building real circuits, testing them and also making PCB layouts by myself. I really love doing all these things like inventing something new, designing electronics and also helping other people like hobby guys who want to make their own cool circuits at home.

And that is the main reason why I started this website homemade-circuits.com, to share different types of circuit ideas..

If you are having any kind of doubt or question related to circuits then just write down your question in the comment box below, I am like always checking, so I guarantee I will reply you for sure!

Previous Post: « SMPS Flyback Boost Converter Calculator
Next Post: THE HIGGINS ENGINE: Generating Electricity from Gravity »

Reader Interactions

Comments

Anto Das8 says:
September 13, 2025 at 2:26 pm

Is it possible to make this a buck boost converter without the battery charging and MPPT part and power it with any random power source between 3.5V – 12V

Reply
Swagatam says:
September 13, 2025 at 6:46 pm

Yes…You can try the following concept:
https://www.homemade-circuits.com/buck-boost-converter-calculator/

Reply

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

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

Primary Sidebar

circuit simulator image



Subscribe to get New Circuits in your Email



Categories

  • Arduino Projects (93)
  • Audio and Amplifier Projects (133)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (85)
  • Datasheets and Components (109)
  • Electronics Theory (149)
  • Energy from Magnets (27)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (20)
  • Health related Projects (27)
  • Home Electrical Circuits (13)
  • Indicator Circuits (16)
  • Inverter Circuits (95)
  • Lamps and Lights (159)
  • Meters and Testers (71)
  • Mini Projects (28)
  • Motor Controller (68)
  • Oscillator Circuits (28)
  • Pets and Pests (15)
  • Power Supply Circuits (91)
  • Remote Control Circuits (50)
  • Renewable Energy (12)
  • Security and Alarm (64)
  • Sensors and Detectors (106)
  • SMPS and Converters (34)
  • Solar Controller Circuits (60)
  • Temperature Controllers (43)
  • Timer and Delay Relay (49)
  • Voltage Control and Protection (42)
  • Water Controller (36)
  • Wireless Circuits (30)





Other Links

  • Privacy Policy
  • Cookie Policy
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap



People also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Stack Exchange
  • Linkedin



Recent Comments

  • Swagatam on Arduino 2-Step Programmable Timer Circuit
  • Swagatam on Simple Buck-Boost Converter Circuits Explained
  • Swagatam on IC IR2111 H-Bridge MOSFET, IGBT Driver IC: Full Datasheet, Circuit Diagram
  • Swagatam on Electronic Circuit Projects, Tutorials, and Practical Engineering Solutions
  • Kadir on Simple 3 Phase Inverter Circuit

© 2026 · Swagatam Innovations