Solar and Battery Management System Using Arduino Nano

Project Objective

This project aims to develop a solar and battery power management system using an Arduino Nano. The system prioritizes solar energy during daytime (in SUB mode) to power an inverter and charge a battery, while intelligently switching to utility power (WAPDA) when necessary. The primary objective is to ensure continuous power availability while protecting the battery from overcharge (high charge quantity), over-feeding (high charging rate), over-discharge (high discharge quantity), and overload (high discharge rate) conditions.

System Overview

Operational Logic

  1. During daytime, power is drawn from solar to run the inverter (if sunlight is sufficient and/or according to solar on/off time settings) and charge the battery.
  2. If the AC load exceeds solar supply and the battery begins to discharge, switch to grid, even during daytime.
  3. At night or on cloudy days:
  4. If USB mode is selected (instead of SUB), grid is always given priority. This can be useful in winters when not much power is needed during daytime. So inverter runs only during power outages.

Battery Protection Rules

Alarms

Raise alarm (start beeping) if any of the following is true:

Before raising alarms, give a 5-30 seconds window for temporary spikes / dips in battery voltage / current.

On-Screen Warnings

Inverter turned off (and switched to grid) due to:

Display + Settings

Screens:

  1. Battery voltage (left, Volts) and current (right, Ampere)
  2. Battery voltage (left, Volts) and power being drawn from or fed to the battery (product of voltage and current) (right, Watt)
  3. Battery voltage (left, Volts) and temperature (right, °C)
  4. BVfull: Battery full charge voltage (Volts, range: 12.0-16.0, default: 14.4)
  5. BVlow: Battery discharged voltage low threshold (Volts, range: 10.0-13.0, default: 12.0 (≈ 50% DoD))
  6. BVcrit: Battery discharged voltage critical threshold (Volts, range: 9.0-12.0, default: 11.0)
  7. BIcrit: Battery discharge current critical threshold (Ampere, range: 20-60, default: 50)
  8. BIhigh: Battery discharge current high threshold (Ampere, range: 10-30, default: 20 (@ C10))
  9. BIlow: Battery discharge current low threshold (Ampere, range: 1-15, default: 5)
  10. Prioritize solar or grid (Selection, options: SUB / USB, default: SUB)
  11. Delay before switching AC load back to inverter after inverter turned off due to battery overloaded (high current drained) or voltage dropped, now no grid and battery is above BVlow (Minutes, range: 1-10, default: 5)
  12. Delay before switching AC load back to inverter (daytime) after inverter was turned off for any reason (e.g. due to clouds, or battery overload or low voltage condition), now solar is available (Minutes, range: 1-10, default: 5)
  13. Window before switching AC load to grid if battery voltages are between BVlow and BVcrit (Minutes, range: 1-10, default: 2)
  14. Window before switching AC load to grid if battery discharge current is between BIcrit and BIhigh (Seconds, range: 5-60, default: 10)
  15. Window before switching AC load to grid (daytime) if battery discharge current is between BIhigh and BIlow (Minutes, range: 1-10, default: 2)
  16. Window before switching AC load to grid (daytime) if battery discharge current is below BIlow (Minutes, range: 1-15, default: 5)
  17. Delay before switching AC load to inverter after starting inverter (Seconds, range: 0-10, default: 5)
  18. Clock time (24h format)
  19. Time before solar on time, try switch to solar (Minutes, range: 0-60, default: 0)
  20. Solar on time (24h format, range: 05:00-10:00, default: 07:00)
  21. Solar off time (24h format, range: 14:00-19:00, default: 17:00)
  22. Display brightness (Level, range: 1-10, default: 1)
  23. Buzzer loudness (Level, range: 1-10, default: 1)
  24. Save

Hardware Components

Minor Parts

For H11AA1 Optocoupler: For Buzzer: For Relay (inverter) Others:

Connections

1. INA219 Current Sensor & FL-2C Shunt

2. 0–25V DC Voltage Sensor

3. AC Detection

Use any of the both methods.

3 (a). ZMPT101B AC Voltage Sensor

3 (b). H11AA1 Optocoupler

4. DS3231 RTC Module

5. 5V Relay Module (AC Changeover)

6. 5V Relay (Inverter)

7. MAX7219 8-Digit Display

8. 5–12V Active Buzzer

9. Push Buttons (x3)

10. LM2596 Buck Converter

11. Power Supply Summary

Schematics

Arduino Circuit:

Solar and AC (Grid + Inverter) Circuit:

Flowchart:

Code:

https://github.com/mirfatif/SolarBMS/SolarBMS.ino

Libraries:

Finally:

Links

  1. https://digilog.pk/products/arduino-nano-v3-with-usb-cable-in-pakistan
  2. https://digilog.pk/products/ina219-bi-direction-dc-current-power-supply-sensor-module-gy-219-module-in-pakistan
  3. https://wolles-elektronikkiste.de/en/ina219-current-and-power-sensor
  4. https://www.aliexpress.com/item/1005007796473791.html
  5. https://digilog.pk/products/dc-0-to-25v-voltage-sensor-module-for-arduino-in-pakistan
  6. https://digilog.pk/products/zmpt-single-phase-ac-voltage-sensor-module-in-pakistan
  7. https://digilog.pk/products/ds3231-rtc-module
  8. https://instock.pk/ambient-light-intensity-lux-sensor-bh-1750.html
  9. https://digilog.pk/products/1-channel-5v-arduino-relay-module-in-pakistan
  10. https://digilog.pk/products/spdt-6v-or-5v-relay
  11. https://digilog.pk/products/max7219-8-digit-7-segment-module-assembled-in-pakistan
  12. https://digilog.pk/products/buzzer-alarm-active-piezo-electronic-wires-dc-3-12v
  13. https://digilog.pk/products/12x12x9mm-tactile-push-button-switch
  14. https://digilog.pk/products/411a-lm2596-buck-converter-step-down-module-power-supply
  15. https://digilog.pk/products/h11aa1-optocoupler-dip-6-pin-ic
  16. https://github.com/NorthernWidget/DS3231
  17. https://github.com/wollewald/INA219_WE
  18. https://github.com/JemRF/max7219
  19. https://github.com/Abdurraziq/ZMPT101B-arduino
  20. https://github.com/kotwatthana/TimerOne_V2