SALES INQUIRIES: 1 (888) 767-9864

Arduino Solar Power Control System :: Student Project

When Ray installed his new solar electric system, he was excited about the ability to implement this to use solar energy for his home.

However, he was in for a sunny surprise when he discovered that he either did not have enough solar energy to supply the loads he had connected or had an excess of solar energy that was going to waste.

But Ray didn’t let this stop him at all! He decided to come up with an Arduino power control system that allowed him to have more control over just how the rays of sunshine he collected went to powering his home. Take a look below at his radiant creation!


Arduino, solar, controller

Solar Power Controller showing the AUTO mode screen

Hi Ray! So, tell us about your project.

I designed a control system that will provide load shedding/load leveling.

The controller continually examines the amount of solar energy available and connects or disconnects loads such that the maximum amount of available solar power is being used, and thus minimizes the use of grid power, protects the battery bank from being too deeply discharged, and lengthens the battery life.

arduino, load shedding, load shedding design, solar controller

Whoa, wait a minute. What a cool idea! Why did you decide to build this?

In 2017, I purchased a 4400-watt two-phase solar electric system that could generate enough electric power to power my entire household whenever solar energy was available.

It consisted of 12 solar panels, 12 AGM batteries, an inverter, a charge controller for the batteries, and a system controller.

Unlike the more typical solar systems currently being installed, which simply generate power to be sold back to the utility company, this system was designed to provide household power even in the event of a grid power failure.

However, the delivery system did not give me sufficient control to avoid a lot of ongoing human interaction to operate the system. So, I elected to design my own controller as a ‘front end’ to the system.

That’s some great innovation there! So, tell us more about how your project works?

Well, the controller allows the optimal electrical load to run on solar power. When solar energy is not available (such as at night) all loads are normally connected to grid power and, if necessary, the batteries are recharged from grid power.

Five relays (dubbed R1 through R5) switch their respective two-phase loads between solar and grid power. Relays R1 and R2 are used to remove grid power from the load group for a fraction of a second when they are being toggled.

This prevents the possibility of creating an arc between solar and grid power.

The inverter is programmed in a mode called Auto Connect. When grid power is available at the inverter input, inversion ceases and the inverter is bypassed, powering any solar loads directly from the grid.

Thus, R4 controls the presence or absence of grid voltage at the inverter input. All eight relays are also controlled by the Controller.

There is also a timer running in the background which interrupts the loop code every minute. If any major changes in the system state have occurred since the last interrupt, appropriate action is taken.

Every 15 minutes, the solar conditions are re-evaluated, and an additional load group is placed on solar power if sufficient solar power is available, one load group is removed and placed on grid power if not, or the load is left unchanged.

Wow, that’s amazing. Can you elaborate a bit on all this information being sent to the Controller?

Inputs to the Controller consist of the following measurements: grid voltage, battery voltage, battery current, and solar energy.

The grid voltage is measured to sense grid power failures. Battery voltage I measured to sense the battery condition. Battery current is measured to sense if the battery is being charged or discharged.

Available solar energy is measured by a pyranometer.

Such a plethora of information being sent to the Controller! How exactly do you, well, control the Controller?

Operating the Controller is done via three pushbutton switches.  These pushbuttons create hardware interrupts.

Thus, the loop code consists of continually checking for interrupt flags and taking appropriate actions. The MODE button allows the user access to all of the available screens.

The INCrement button allows the user to choose between the various options shown on the current screen.  For example, in the MODE screen, the user chooses another screen that they desire to view.

In the MAN screen, the user chooses which relay he wishes to toggle. The SELect button allows the user to select the choice made via the INC button.

arduino, solar control, pushbutton, menu, map, mode screen, manual screen, auto screen

Wow! Could you also tell us more about how the users interact with your program?

Six different LCD screens are available to the user.  In the MAN screen, the eight relays are directly controlled.

This MANual mode is intended only for handling problem conditions that could occur. The AUTO screen displays the load groups currently being powered by solar.

The intent is that the controller will remain in this mode without human intervention for very long periods of time (months). It is designed to handle the presence or absence of grid power, low battery conditions, etc., without human intervention.

The other screens are the CONDition screen in which current system conditions are displayed, the HISTory screen showing the number of load groups that have been connected to solar power during the last 10 hours, the SHUTDOWN screen that provides a well-behaved shutdown procedure, and the MODE screen which allows the user to switch between different screens.

So, if there is a manual mode, can you talk about how the AUTO mode works as well?

The AUTO mode is where the controller is intended to operate essentially all the time, without interruption, without regard to variations in operating conditions. It is designed to operate in a variety of conditions.

The three basic system parameters are

  • The presence or absence of Grid Power.
  • The presence or absence of Solar Energy.
  • The battery voltage condition, whether above or below desired levels.

Every 15 minutes the auto mode routine is executed.

If solar is available, the controller decides whether to add or remove a load group from solar or to leave the load as is, based on whether the batteries are currently being charged or discharged. That way, the use of solar power is maximized without needlessly discharging the batteries.

Every minute, system conditions are examined to see if any of the three basic system parameters have changed.  If so, auto mode is executed and the 15-minute cycle clock is reset.

arduino, solar power controller, solar panel, inverter

The entire solar panel including the solar panel charge controller on the right, the inverter and associated equipment in the center, and the front-end Arduino controller on the left

Were there some aspects of this project that you struggled with?

Well, the simplicity of the operation of this device does come at a cost.

The software which implements all the various possibilities of pushbutton combinations is quite involved and required about 800 lines of Arduino/C++ code.

Congratulations on completing such a task! What other components did you use in your project?

The controller is implemented by an Arduino MEGA2560 microcomputer programmed in Arduino/ C++ language.

It consists of the MEGA2560, a 40 character by 4-line LCD display, three push buttons, an on/off switch, and all of the necessary signal conditioning and interface circuitry.

Arduino code:

Ray was kind enough to share his source code with us. You can see his code listed below:

Ray also included his design files for his project; check those out here:

Solar Power Controller Design File

Solar Power Controller Design File – Addeendum

About Ray:

Ray has a Ph.D. in Electrical Engineering, with experience programming in several different languages.

However, this is his first time programming in C++. He is an 80-year-old retiree who developed a newfound interest in Arduino as an affordable platform to accomplish his goals.


  1. Avatar Mike Koens on May 10, 2019 at 4:45 am

    Wow Ray, that is impressive. I have been considering a similar unit for my solar setup, which is very similar to yours,1.8kw of PV panels, 48 volt 600Ahr battery and a 5kw inverter with built in MPPT charger. The one thing I want to do differently, is to switch an optional extra load into the circuit, if the batteries reach full charge with plenty of solar input still available, such as a small aircon unit on the battery box, or an ice maker. I also want to run two inverters, a smaller 500 watt or 1 kw unit when load conditions are light. I find the 5 kw inverter is drawing nearly 2 amps from the battery all night, even without a load at all, and this is a waste of solar/battery power,whereas a smaller inverter will draw proportionally less power at low loads.

  2. Avatar Jay on May 14, 2019 at 12:13 am

    This is awesome, I live in Australia and we get rebates from the government to put up solar on our roof. Any chance you will consider releasing the lot of it as open source code and hardware? I don’t remember seeing where you lived but if you had sun like us this system would be so much better than the 1/4 of the cost you get back from putting it in the grid. So we may pay $0.28 per kw and get $0.08 back

    • Avatar Michael James on May 15, 2019 at 4:41 pm

      Hi Jay, we updated the post to include Rays code and his design write up. I hope this helps!

Leave a Comment