Solar and Battery Management System using Arduino Nano

Index

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 over-(dis)charge (quantity) and high (dis)charge (rate) conditions.

Also see the flowchart.

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.

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

Screens:
  1. INFO | Battery voltage (left, Volts) and current (right, Ampere)
  2. INFO | Battery voltage (left, Volts) and power being drawn from or fed to the battery (product of voltage and current) (right, Watt)
  3. INFO | PV array voltage (left, Volts) and current (right, Ampere)
  4. INFO | PV array voltage (left, Volts) and power (product of voltage and current) (right, Watt)
  5. INFO | Clock (left, 24h format) and temperature (right, °C)
  6. BVfull | Battery full charge voltage (Volts, range: 12.0-16.0, default: 14.4)
  7. BVlow | Battery discharged voltage low threshold (Volts, range: 10.0-13.0, default: 12.0 (≈ 50% DoD))
  8. BVcrit | Battery discharged voltage critical threshold (Volts, range: 9.0-12.0, default: 11.0)
  9. BIcrit | Battery discharge current critical threshold (Ampere, range: 20-60, default: 50)
  10. BIhigh | Battery discharge current high threshold (Ampere, range: 10-30, default: 20 (@ C10))
  11. BIlow | Battery discharge current low threshold (Ampere, range: 1-15, default: 5)
  12. Prioritize solar or grid (Selection, options: SUB / USB, default: SUB)
  13. Delay before switching AC load to inverter after starting inverter (Seconds, range: 0-10, default: 5)
  14. 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)
  15. SOLAR | Delay before switching AC load back to inverter (daytime) after inverter was turned off due to sunlight not sufficient, now let's retry (Minutes, range: 15-60, default: 15)
  16. SOLAR | Delay before switching AC load back to inverter (daytime) after inverter was turned off for any other reason (Minutes, range: 1-10, default: 5)
  17. Window before switching AC load to grid if battery voltages are between BVlow and BVcrit (Minutes, range: 1-10, default: 2)
  18. Window before switching AC load to grid if battery discharge current is between BIcrit and BIhigh (Seconds, range: 5-60, default: 10)
  19. SOLAR | Window before switching AC load to grid (daytime) if battery discharge current is between BIhigh and BIlow (Minutes, range: 1-10, default: 2)
  20. SOLAR | Window before switching AC load to grid (daytime) if battery discharge current is below BIlow (Minutes, range: 1-15, default: 5)
  21. SOLAR | Check sun time (Selection, options: 1 (true) / 0 (false), default: 1)
  22. SOLAR | Clock time (24h format)
  23. SOLAR | Solar on time (24h format, range: 05:00-10:00, default: 07:00)
  24. SOLAR | Solar off time (24h format, range: 14:00-19:00, default: 17:00)
  25. SOLAR | Solar minimum current required from PV array (Ampere, range: 1-30, default: 15)
  26. Display brightness (Level, range: 1-10, default: 1)
  27. Buzzer loudness (Level, range: 1-10, default: 1)
  28. CALIB | Show the following battery/PV voltage/current calibration screens (Selection, options: 1 (true) / 0 (false), default: 0)
  29. CALIB | Battery voltage offset (Volts, range: ±10, default: 0)
  30. CALIB | Battery voltage factor (Multiplier, range: 0.5-2, default: 1)
  31. CALIB | Battery current offset (Volts, range: ±10, default: 0)
  32. CALIB | Battery current factor (Multiplier, range: 0.5-2, default: 1)
  33. CALIB | Solar voltage offset (Volts, range: ±10, default: 0)
  34. CALIB | Solar voltage factor (Multiplier, range: 0.5-2, default: 1)
  35. CALIB | Solar current offset (Volts, range: ±10, default: 0)
  36. CALIB | Solar current factor (Multiplier, range: 0.5-2, default: 1)
  37. Save

Actual checks and details are a bit complex but a simplified version is:

Minor Parts

For PV Current / Voltage Sensing: For Battery Current / Voltage Sensing: For H11AA1 Optocoupler: For Buzzer: For Relay (AC): For Relay (Inverter): For Fan: For Battery Power Supply (LC Filter): Others:

1. FL-2C Shunt + HCPL-7840 + B0505S (PV Array)

2. FL-2C Shunt + HCPL-7840 (Battery)

3. H11AA1 Optocoupler – AC Detection

4. DS3231 RTC Module

5. Relay (AC Changeover)

6. Relay (Inverter)

7. MAX7219 8-Digit Display

8. 5–12V Active Buzzer

9. Push Buttons (x3)

10. IR Proximity Sensor

11. Fan

12. MP1584 Buck Converter (12V)

13. MP1584 Buck Converter (5V)

14. Power Supply

Solid boxes show external components. Dotted boxes show units.

Arduino Circuit:

Solar and AC (Grid + Inverter) Circuit:

This circuit works independent of Arduino control. But Arduino control depends on this circuit.

Switches:

Isolated Current / Voltage Sensor Module:

2 x HCPL-7840 + filters / protectors. Details for PV and for battery.

Pin config for PV / battery:

  1. SHT / BAT-
  2. GND_ISO / GND
  3. 5V_ISO / 5V
  4. ADS1_A3 / ADS2_A3
  5. ADS1_A2 / ADS2_A2
  6. GND_ISO / GND
  7. VD1 / VD2
  8. ADS1_A1 / ADS2_A1
  9. ADS1_A0 / ADS2_A0
  10. 5V
  11. GND

Or (swapping input / outputs of identical halves):

  1. VD1 / VD2
  2. Same
  3. Same
  4. ADS1_A1 / ADS2_A1
  5. ADS1_A0 / ADS2_A0
  6. Same
  7. SHT / BAT-
  8. ADS1_A3 / ADS2_A3
  9. ADS1_A2 / ADS2_A2
  10. Same
  11. Same

Front:

  1. Relay
  2. Connector
  3. Fuse
  4. LED
  5. 330Ω
  6. 220kΩ
  7. 10kΩ Potentiometer
  8. 220kΩ
  9. H11AA1
  10. 0.1µF
  11. MAX7219
  12. Jumper
  13. 0.1µF
  14. MP2307
  15. Arduino Nano
  16. Push Button
  17. Push Button
  18. Push Button
  19. Connector
  20. Connector
  21. Connector
  22. Connector
  23. 2N3904
  24. 2N3904
  25. 1kΩ
  26. 1kΩ
  27. IV Module (Battery)
  28. IV Module (PV)
  29. 100kΩ
  30. 820Ω
  31. ADS1115
  32. ADS1115
  33. IR Proximity Sensor
  34. 100µH
  35. 100µH
  36. Fuse
  37. 0.1µF
  38. 100µF
  39. 0.01µF
  40. 100kΩ
  41. 470Ω
  42. 2.2kΩ
  43. 6.8kΩ
  44. 10kΩ
  45. 22kΩ
  46. 100kΩ
  47. TL431
  48. 10µF
  49. 10µF
  50. B0505S
  51. MP1584
  52. Jumper
  53. 0.1µF
  54. 2N2222A
  55. 330Ω
  56. Connector
  57. DS3231
  58. 22µF
  59. 1kΩ
  60. 2N3904
  61. Connector

  1. AC_REL
  2. MAIN_N
  3. MAIN_L
  4. GND - Relay (Inverter)
  5. 5V - Relay (Inverter)
  6. BAT- - Shunt (Battery) Battery-Side
  7. GND - Shunt (Battery) Load-Side
  8. GND - Shunt (Battery) Load-Side
  9. BAT+
  10. PV- - Shunt (PV) PV-Side
  11. SHT - Shunt (PV) Load-Side
  12. PV+
  13. 12V - Buzzer
  14. GND - Buzzer

Back:

  1. SI2301
  2. 1N4007
  3. 1N4007
  4. 1N4007
  5. PV- source
  6. SHT source
  7. PV+ source
  8. PV+
  9. BSP1
  10. GND
  11. TL_REF
  12. TL_REF
  13. BSP2
  14. GND
  15. 5V_ISO source
  16. GND_ISO source / PV-
  17. 5V
  18. GND
  19. 5V source
  20. D14
  21. GND
  22. 12V
  23. GND
  24. 5V
  25. SDA
  26. SCL
  27. GND
  28. D6
  29. 12V
  30. BAT+
  31. GND source (BAT- via shunt)
  32. GND
  33. BAT-
  34. SHT
  35. GND_ISO
  36. 5V_ISO
  37. ADS1_A3
  38. ADS1_A2
  39. GND_ISO
  40. VD1
  41. ADS1_A1
  42. ADS1_A0
  43. 5V
  44. GND
  45. BAT-
  46. GND
  47. 5V
  48. ADS2_A3
  49. ADS2_A2
  50. GND
  51. VD2
  52. ADS2_A1
  53. ADS2_A0
  54. 5V
  55. GND
  56. GND_ISO
  57. BSP1
  58. GND
  59. 5V
  60. GND
  61. SCL
  62. SDA
  63. ADS1_A0 source
  64. ADS1_A1 source
  65. ADS1_A2 source
  66. ADS1_A3 source
  67. 5V
  68. GND
  69. SCL
  70. SDA
  71. 5V
  72. ADS2_A0 source
  73. ADS2_A1 source
  74. ADS2_A2 source
  75. ADS2_A3 source
  76. D3
  77. GND
  78. 5V
  79. 5V
  80. GND
  81. D5
  82. D4
  83. AC_RC-
  84. AC_RC-
  85. 5V
  86. AC_RC-
  87. 5V
  88. AC_REL
  89. AC_REL
  90. MAIN_N
  91. MAIN_L
  92. 220V_L
  93. 220V_L
  94. GND
  95. D2
  96. 12V source
  97. GND
  98. BSP2
  99. D2 source
  100. D3 source
  101. D4 source
  102. D5 source
  103. D6 source
  104. D7 source
  105. D8 source
  106. D9 source
  107. D10 source
  108. D11 source
  109. D12 source
  110. SCL source
  111. SDA source
  112. D14 source
  113. D10
  114. D11
  115. D12
  116. GND
  117. 5V
  118. D7
  119. D8
  120. D9
  121. GND
  122. GND
  123. GND

Joints:

Components Current (mA) Pin Mode Pin Source (+) / Sink (-)
Current (mA)
H11AA1 Optocoupler – AC sensor
(pulled-up @ ~20kΩ)
D2 Input -0.25
IR proximity sensor module 10-20 D3 Input ~0
2N3904 - drives a 5V relay
(AC)
60 D4 Output 6
2N3904 - drives a 5V relay
(inverter)
60 D5 Output 6
2N3904 - drives a 12V buzzer 40 @ 12V D6 Output 4
Push button (pulled-up @ ~20kΩ) D7-D9 Input -0.25 × 3 = -0.75
MAX7219 8-digit display module 50-100 D10-D12 SPI/Output ±0.1 × 3 = ±0.3
2N2222A - drives a 12V fan 50-100 @ 12V D14 Output 10
DS3231 clock module 0.5-1.5 A4-A5 I2C -0.25 × 2 = -0.5
(SDA/SCL pulled LOW)
Battery sensor:
ADS1115 module &
2 x HCPL-7840
0.2 (ADS1115)

11 × 2 = 22
(7840)

Solar sensor:
ADS1115 module &
2 x HCPL-7840 &
B0505S
0.2 (ADS1115)

11 × 125% = 13.75
(7840_IN)

11 (7840_OUT)

5 (B0505S)

Total:

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

Libraries:

  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
  21. https://digilog.pk/products/mini-360-dc-to-dc-step-down-buck-converter-module-in-pakistan
  22. https://digilog.pk/products/ir-infrared-obstacle-avoidance-sensor-module-in-pakistan
  23. https://digilog.pk/products/hcpl-7840-smd-optocoupler-in-pakistan
  24. https://industryparts.pk/products/fl-2c-75mv-current-meter-shunt-dc-ammeter-splitter
  25. https://digilog.pk/products/ca3130-operational-amplifier-in-pakistan
  26. https://digilog.pk/products/lm7805-7805-voltage-regulator-5v-voltage-regulator
  27. https://www.rcscomponents.kiev.ua/datasheets/hcpl-7840-000e-datasheet.pdf
  28. https://digilog.pk/products/5v-raspberry-pi-cooling-fan-in-pakistan
  29. https://digilog.pk/products/lm78l05-78l05-voltage-regulator-5v-voltage-regulator-to-92
  30. https://digilog.pk/products/6n137-high-speed-optocoupler
  31. https://www.ti.com/lit/ds/symlink/ina219.pdf
  32. https://digilog.pk/products/tl431-regulator-in-pakistan
  33. https://www.analog.com/en/resources/app-notes/an-913.html
  34. https://toshiba.semicon-storage.com/content/dam/toshiba-ss-v3/master/en/semiconductor/design-development/innovationcentre/whitepapers/TCM0646_Toshiba_Isolated_I2C_Communications_Using_Optoisolators.pdf
  35. https://www.vishay.com/docs/84901/opticalisolatorfoti2cvussystem.pdf
  36. https://www.daraz.pk/products/i433460246-s2080834429.html
  37. https://www.daraz.pk/products/i260624136-s1478880694.html
  38. https://digilog.pk/products/ads1115
  39. https://github.com/wollewald/ADS1115_WE
  40. https://digilog.pk/products/mini-mp1584en-dc-dc-buck-adjustable-step-down-module-4-5v-28v-input-0-8v-20v-output
  41. https://digilog.pk/products/mini-jumpers-hard-drive-jumper-in-pakistan
  42. https://digilog.pk/products/40mm-x-40mm-x-10mm-4010-12v-0-15a-dc-brushless-ball-bearing-cooling-fan-2pin