ARDUINO SOLAR CHARGE CONTROLLER ( Version 2.0)

663,070

2,039

804

[ Play Video ]

One year ago, I began building my own solar system to provide power for my village house. Initially, I made a LM317 based charge controller and an Energy meter for monitoring the system. Finally, I made a PWM charge controller. In April-2014 I posted my PWM solar charge controller designs on the web, it became very popular. Lots of people all over the world have built their own. So many students have made it for their college project by taking help from me. I got several emails every day from people with questions regarding hardware and software modification for different rated solar panel and battery. A very large percentage of the emails are regarding the modification of the charge controller for a 12Volt solar system.

You can find all of my projects on https://www.opengreenenergy.com/

You can see my other version charge controllers

ARDUINO MPPT SOLAR CHARGE CONTROLLER ( Version-3.0)
ARDUINO SOLAR CHARGE CONTROLLER (Version-1)

To solve this problem I made this new version charge controller so that anyone can use it without changing the hardware and software. I combine both the energy meter and charge controller in this design.

Specification of version-2 charge controller :


1.Charge controller as well as energy meter

2. Automatic Battery Voltage Selection (6V/12V)

3.PWM charging algorithm with auto charge setpoint according to the battery voltage

4.LED indication for the state of charge and load status

5. 20x4 character LCD display for displaying voltages, current, power, energy, and temperature.

6.Lightning protection

7.Reverse current flow protection

8.Short Circuit and Overload protection

9. Temperature Compensation for Charging


Electrical specifications :

1.Rated Voltage= 6v /12V

2.Maximum current = 10A

3.Maximum load current =10A

4.Open Circuit Voltage = 8-11V for 6V system /15 -25V for 12V system

Step 1: Parts and Tools Required :

Parts:

1.Arduino Nano (Amazon / Banggood)

2.P-MOSFET ( Amazon / IRF 9540 x2 )

3.Power diode ( Amazon / MBR 2045 for 10A and IN5402 for 2A)

4.Buck Converter ( Amazon / Banggood)

5.Temperature Sensor( Amazon / Banggood)

6.Current Sensor ( Amazon / Banggood)

7.TVS diode ( Amazon / P6KE36CA)

8.Transistors ( 2N3904 or Banggood )

9.Resistors ( 100k x 2, 20k x 2,10k x 2,1k x 2, 330ohm x 5) : Banggood

10.Ceramic Capacitors (0.1uF x 2) : Banggood

11.Electrolytic Capacitors ( 100uF and 10uF): Banggood

12. 20x4 I2C LCD ( Amazon / Banggood)

13.RGB LED ( Amazon / Banggood)

14.Bi Color LED ( Amazon )

15.Jumper Wires/Wires(Banggood)

16.Header Pins ( Amazon / Banggood )

17.Heat Sink ( Amazon / Banggood)

18.Fuse Holder and fuses ( Amazon / eBay)

19.Push Button ( Amazon / Banggood )

20.Perforated Board (Amazon / Banggood)

21.Project Enclosure ( Banggood )

22.Screw terminals ( 3x 2pin and 1x6 pin) : Banggood

23.Nuts/Screws/Bolts ( Banggood )

24.Plastic Base

Tools :

1.Soldering Iron ( Amazon )

2.Wire Cutter and Stripper ( Amazon )

3.Screw Driver ( Amazon )

4.Cordless Drill ( Amazon )

5.Dremel ( Amazon )

6.Glue Gun ( Amazon )

7.Hobby Knife ( Amazon )


Step 2: How the Charge Controller Works :

The heart of the charge controller is Arduino nano board. The Arduino MCU senses the solar panel and battery voltages. According to these voltages, it decides how to charge the battery and control the load.

The amount of charging current is determined by the difference between battery voltage and charge setpoint voltages. The controller uses two stages charging algorithm. According to the charging algorithm, it gives a fixed frequency PWM signal to the solar panel side p-MOSFET. The frequency of the PWM signal is 490.20Hz(default frequency for pin-3). The duty cycle 0-100% is adjusted by the error signal.

The controller gives a HIGH or LOW command to the load side p-MOSFET according to the dusk/dawn and battery voltage.

The full schematic is attached below.

Step 3: Main Functions of Solar Charge Controller:

The charge controller is designed by taking care of the following points.

1. Prevent Battery Overcharge: To limit the energy supplied to the battery by the solar panel when the battery becomes fully charged. This is implemented in charge_cycle() of my code.

2. Prevent Battery Over discharge: To disconnect the battery from electrical loads when the battery reaches a low state of charge. This is implemented in load_control() of my code.

3. Provide Load Control Functions: To automatically connect and disconnect an electrical load at a specified time. The load will ON when the sunset and OFF when sunrise. This is implemented in load_control() of my code.

4.Monitoring Power and Energy: To monitor the load power and energy and display it.

5. Protect from abnormal Condition: To protect the circuit from the different abnormal situation like lightning, overvoltage, overcurrent and short circuit, etc.

6.Indicating and Displaying: To indicate and display the various parameters

7.Serial Communication: To print various parameters in the serial monitor

Step 4: Sensing Voltages,Current and Temperature :

1.Voltage Sensor:

The voltage sensors are used to sense the voltage of solar panel and battery. It is implemented by using two voltage divider circuits. It consists of two resistors R1=100k and R2=20k for sensing the solar panel voltage and similarly R3=100k and R4=20k for battery voltage. The output from the R1and R2 is connected to Arduino analog pin A0 and output from the R3 and R4 is connected to Arduino analog pin A1.

2.Current Sensor :

The current sensor is used for measuring the load current. later this current is used to calculate the load power and energy. I used a hall effect current sensor (ACS712-20A)

3.Temperature Sensor :

The temperature sensor is used to sense room temperature. I used the LM35 temperature sensor which is rated for −55°C to +150°C Range.

Why Temperature monitoring is Required?

The battery’s chemical reactions change with temperature. As the battery gets warmer, the gassing increases. As the battery gets colder, it becomes more resistant to charging. Depending on how much the battery temperature varies, it is important to adjust the charging for temperature changes. So it is important to adjust charging to account for the temperature effects. The temperature sensor will measure the battery temperature, and the Solar Charge Controller uses this input to adjust the charge set point as required. The compensation value is - 5mv /degC/cell for lead-acid type batteries. (–30mV/ºC for 12V and 15mV/ºC for 6V battery).The negative sign of temperature compensation indicates an increase in temperature requires a reduction in charge setpoint.

For more details on Understanding and Optimizing Battery Temperature Compensation

Step 5: Sensors Callibration

Voltage Sensors :

5V = ADC count 1024

1 ADC count = (5/1024)Volt= 0.0048828Volt

Vout=Vin*R2/(R1+R2)

Vin = Vout*(R1+R2)/R2 R1=100 and R2=20

Vin= ADC count*0.00488*(120/20) Volt

Current Sensor:

As per seller information for ACS 712 current sensor

Sensitivity is =100mV / A =0.100V/A

No test current through the output voltage is VCC / 2= 2.5

ADC count= 1024/5*Vin and Vin=2.5+0.100*I (where I=current)

ADC count= 204.8(2.5+0.1*I) =512+20.48*I

=> 20.48*I = (ADC count-512)

=> I =(ADC count/20.48)- 512/20.48

Current (I) =0.04882*ADC -25

More details on ACS712

Temperature Sensor :

As per data sheet of LM35

Sensitivity=10 mV/°C

Temp in deg C =(5/1024)*ADC count*100

Note : The sensors are calibrated by assuming the arduino Vcc= 5V reference.But in practical it is not 5V always.So there may be chance of getting wrong value from the actual value.It can be solved by following way.

Measure the voltage between Arduino 5V and GND by a multimeter. Use this voltage instead of 5V for Vcc in your code. Hit and try to edit this value until it matches the actual value.

Example: I got 4.47V instead of 5V.So the change should be 4.47/1024=0.0043652 instead of 0.0048828.

Step 6: Charging Algorithm

1.Bulk: At this mode, a preset maximum constant amount of current (amps) is fed into the battery as no PWM is present. As the battery is being charged up, the voltage of the battery increases gradually

2. Absorption: When the battery reaches the bulk charge set voltage, the PWM begins to hold the voltage constant. This is to avoid over-heating and over-gassing the battery. The current will taper down to safe levels as the battery becomes more fully charged.
3. Float: When the battery is fully recharged, the charging voltage is reduced to prevent further heating or gassing of the battery

This is the ideal charging procedure.

The present charge cycle block of code is not implemented 3 stages charging. I use an easier logic in 2 stages. It works well.

I am trying the following logic for implementing the 3 stages charging.

Future Planning for Charging Cycle :

The bulk charge begins when the solar panel voltage is larger than the battery voltage. When the battery voltage reaches 14.4V, absorption charge will be entered. The charging current will be regulated by the PWM signal to maintain the battery voltage at 14.4V for one hour. Float charge will then enter after one hour. The float stage generates a trickle charge to keep the battery voltage at 13.6V. When the battery voltage falls below 13.6V for 10mins, the charging cycle will be repeated.

I request community members to help me for writing the piece of code to implement the above logic.

Step 7: Load Control

To automatically connect and disconnect the load by monitoring dusk/dawn and battery voltage, load control is used.

The primary purpose of load control is to disconnect the load from the battery to protect it from deep discharging. Deep discharging could damage the battery.

The DC load terminal is designed for low power DC load such as street light.

The PV panel itself is used as the light sensor.

Assuming solar panel voltage >5V means dawn and when < 5V dusk.

ON Condition:

In the evening, when the PV voltage level falls below 5V and the battery voltage is higher than LVD setting, the controller will turn on the load and the load green led will glow.

OFF Condition:

The load will cut off in the following two conditions.

1. In the morning when the PV voltage is larger than 5v,

2.When the battery voltage is lower than the LVD setting

The load red led ON indicates that load is cut off.

LVD is referred to as Low Voltage Disconnect

Step 8: Power and Energy

Power :

Power is the product of voltage (volt) and current (Amp)

P=VxI

Unit of power is Watt or KW

Energy:

Energy is the product of power (watt) and time (Hour)

E= Pxt

Unit of Energy is Watt Hour or Kilowatt Hour (kWh)

To monitor the load power and energy above logic is implemented in software and the parameters are displayed in a 20x4 char LCD.

Step 9: Protection

1.Reverse polarity protection for solar panel

2. Overcharge protection

3. Deep discharge protection

4. Short circuit and Overload protection

5.Reverse current protection at night

6.Overvoltage protection at solar panel input

For reverse polarity and reverse current flow protection I used a power diode (MBR2045). Power diode is used to handle a large amount of current. In my earlier design, I used a normal diode(IN4007).

Overcharge and Deep discharge protection are implemented by the software.

Overcurrent and overload protection is implemented by using two fuses ( one at the solar panel side and other at load side).

Temporary overvoltages occur in power systems for a variety of reasons, but lightning causes the most severe overvoltages. This is particularly true with PV systems due to the exposed locations and system connecting cables. In this new design, I used a 600-watt bidirectional TVS diode (P6KE36CA ) to suppress the lightning and overvoltage at the PV terminals. In my earlier design, I used a Zener diode. You can also use a similar TVS diode on the load side.

For selection guide of TVS diode click here

For choosing a right part no for TVS diode click here

Step 10: LED Indication

Battery State Of Charge (SOC) LED:

One important parameter that defines the energy content of the battery is the State of Charge (SOC). This parameter indicates how much charge is available in the battery

An RGB LED is used to indicate the battery state of charge. For connection refer to the above schematic

Battery LED ------------>Battery Status

RED --------------------> Voltage is LOW

GREEN --------------------> Voltage is Healthy

BLUE --------------------> Fully Charged

Load LED :

A bi-color (red/green) led is used for load status indication. Refer the above schematic for connection.

Load LED --------------------->Load Status

GREEN -------------------------> Connected (ON)

RED ---------------------------> Disconnected (OFF)

I include a third led for indicating the solar panel status.

Step 11: LCD Display

To display the voltage, current, power, energy and temperature a 20x4 I2C LCD is used. If you do not want to display the parameter then disable the lcd_display() from the void loop() function. After disable you have indication led to monitoring the battery and load status.

You can refer this instructable for I2C LCD

Download the LiquidCrystal _I2C library from here

Note: In code, you have to change the I2C module address. You can use the address scanner code given in the link.

Step 12: Bread Board Testing

It is always a good idea to test your circuit on a breadboard before soldering it together.

After connecting everything upload the code. The code is attached below.

The entire software is broken into the small functional block for flexibility. Suppose the user is not interested to use an LCD display and happy with the led indication. Then just disable the lcd_display() from the void loop(). That's all.

Similarly, according to the user requirement, he can enable and disable the various functionality.

Download the code from my GitHub Account

ARDUINO-SOLAR-CHARGE-CONTROLLER-V-2

Step 13: Power Supply and Terminals :

Terminals :

Add 3 screw terminals for solar input, battery and load terminal connections. Then solder it. I used the middle screw terminal for battery connection, left to it is for solar panel and the right one is for the load.

Power Supply:

In my previous version, the power supply for Arduino was provided by a 9V battery. In this version, the power is taken from the charging battery itself. The battery voltage is step down to 5V by a voltage regulator(LM7805).

Solder LM7805 voltage regulator near to the battery terminal. Then solder the electrolytic capacitors as per schematic. At this stage connect the battery to the screw terminal and check the voltage between pin 2 and 3 of LM7805. It should be near to 5V.

When I used a 6V battery the LM7805 works perfectly. But for the 12V battery, it heated up after some time. So I request to use a heat sink for it.

Efficient Power supply :

After a few testing, I found that the voltage regulator LM7805 is not the best way to power the Arduino as it wastes lots of power in the form of heat. So I decide to change it by a DC-DC buck converter which is highly efficient. If you plan to make this controller, I advise using a buck converter rather than LM7805 voltage regulator.

Buck Converter Connection:

IN+ -------> BAT+

IN- --------> BAT-

OUT+ -----> 5V

OUT- -----> GND

Refer the above pictures.

You can buy it from eBay

Step 14: Mount the Arduino :

Cut 2 female header strips of 15 pins each. Place the nano board for reference. Insert the two headers according to the nano pin. Check it whether the nano board is perfect to fit into it. Then solder it back side.

Insert two rows of the male header on both sides of the Nano board for external connections. Then join the solder points between Arduino pin and header pins. See the above picture.

Initially, I forgot to add Vcc and GND headers. At this stage, you can put headers with 4 to 5 pins for Vcc and GND.

As you can see I connected the voltage regulator 5V and GND to the nano 5V and GND by red and black wire. Later I removed it and soldered at the back side for a better look of the board.

Step 15: Solder the Components

Before soldering the components make holes at corners for mounting.

Solder all the components as per schematic.

Apply heat sink to two MOSFETs as well as power diode.

Note: The power diode MBR2045 have two anodes and one cathode. So short the two anodes.

I used thick wire for power lines and ground and thin wires for signal.signal. Thick wire is mandatory as the controller is designed for higher current.

Step 16: Connect the Current Sensor

After connecting all the components solder two thick wire to the load MOSFET's drain and upper terminal of load side fuse holder. Then connect these wires to the screw terminal provided in the current sensor( ACS 712).

Step 17: Make the Indication and Temperature Sensor Panel

I have shown two led in my schematic. But I added a third led(bi-color) for indicating the solar panel status in future.

Prepare small size perforated board as shown. Then make two holes (3.5mm) by drill on left and right( for mounting).

Insert the LEDs and solder it to the back side of the board.

Insert a 3 pins female header for the temperature sensor and then solder it.

Solder 10 pins right angle header for external connection.

Now connect the RGB led anode terminal to the temperature sensor Vcc(pin-1).

Solder the cathode terminals of two bi-color led.

Then join the solder points the LEDs terminal to the headers. You can paste a sticker with pin name for easy identifications.

Step 18: ​Connections for Charge Controller

Connect the Charge Controller to the Battery first, because this allows the Charge Controller to get calibrated to whether it is the 6V or 12V system. Connect the negative terminal first and then positive. Connect the solar panel(negative first and then positive) At last connect the load.

The charge controller load terminal is suitable for only the DC load.

How to run an AC Load?

If you want to run AC appliances then you must need an inverter. Connect the inverter directly to the battery. See the above picture.

Step 19: Final Testing :

After making the main board and indication board connect the header with jumper wires(female-female)

Refer to the schematic during this connection. Wrong connection may damage the circuits. So be care full in this stage.

Plug the USB cable to the Arduino and then upload the code. Remove the USB cable. If you want to see the serial monitor then keep it connected.

Fuse Rating: In demo, I have put a 5A fuse in the fuse holder. But in practical use, put a fuse with 120 to 125% of short circuit current.

Example :A 100W solar panel having Isc=6.32A needs a fuse 6.32x1.25 = 7.9 or 8A

How to test?

I used a buck-boost converter and black cloth to test the controller. The converter input terminals are connected to the battery and the output is connected to the charge controller battery terminal.

Battery status :

Rotate the converter potentiometer by a screwdriver to simulate different battery voltages. As the battery voltages change the corresponding led will turn off and turn on.

Note: During this process, Solar panel should be disconnected or covered with a black cloth or cardboard.

Dawn/Dusk: To simulate dawn and dusk using black cloth.

Night: Cover the solar panel entirely.

Day: Remove the cloth from the solar panel.

Transition: slow the remove or cover the cloth to adjust different solar panel voltages.

Load Control: According to the battery condition and dawn/dusk situation the load will turn on and off.

Temperature Compensation :

Hold the temperature sensor to increase the temperature and place any cold things like ice to decrease the temp. It will be immediately displayed on the LCD.

The compensated charge setpoint value can be seen on the serial monitor.

In the next step onward I will describe the making of enclosure for this charge controller.

Step 20: Mounting the Main Board:

Place the main board inside the enclosure. Mark the hole position by a pencil.

Then apply hot glue to the marking position.

Place the plastic base over the glue.

Then place the board over the base and screw the nuts.

Step 21: Make Space for LCD:

Mark the LCD size on the front cover of the enclosure.

Cut out the marked portion by using a Dremel or any other cutting tool. After cutting finish it by using a hobby knife.

Step 22: Drill Holes:

Drill holes for mounting the LCD,Led indication panel,Reset button and external terminals

Step 23: Mount Everything:

After making holes mount the panels, 6 pin screw terminal and reset button.

Step 24: Connect the External 6 Pin Terminal :

For connecting the solar panel, battery and load an external 6pin screw terminal is used.

Connect the external terminal to the corresponding terminal of the main board.

Step 25: Connect the LCD, Indicator Panel and Reset Button :

Connect the indicator panel and LCD to the main board as per the schematic. (Use female-female jumper wires)

One terminal of the reset button goes to RST of Arduino and other goes to GND.

After all connections. Close the front cover and screw it.

Step 26: Ideas and Planning

How to plot real-time graphs?

It is very interesting if you can plot the serial monitor parameters (like battery and solar voltages) on a graph on your laptop screen. It can be done very easily if you know a little bit on Processing.

To know more you can refer to Arduino and Processing ( Graph Example ).

How to save that data?

This can be done easily by using SD card but this includes more complexity and cost. To solve this I searched through the internet and found an easy solution. You can save data in Excel sheets.

For details, you can refer seeing-sensors-how-to-visualize-and-save-arduino-sensed-data

The above pictures downloaded from the web. I attached to understand what I want to do and what you can do.

Future Planning :

1. Remote data logging via Ethernet or WiFi.

2. More powerful charging algorithm and load control

3.Adding a USB charging point for smartphone/tablets

Hope you enjoy my Instructables.

Please suggest any improvements. Raise comments if any mistakes or errors.

Follow me for more updates and new interesting projects.

Thanks :)

Tech Contest

Runner Up in the
Tech Contest

Microcontroller Contest

Runner Up in the
Microcontroller Contest

Formlabs Contest

Participated in the
Formlabs Contest

15 People Made This Project!

Recommendations

  • Games Contest

    Games Contest
  • Sensors Contest

    Sensors Contest
  • Sew Tough Challenge

    Sew Tough Challenge

804 Discussions

0
None
KaiS21

Question 24 days ago

I've built this circuit for 6V, now I needed help setting the values
Where do I measure the values and where do I enter them with Arduino code?
Please answer
20190628_224132.jpg
6 answers
1
None
farmerkeithKaiS21

Answer 16 days ago

Hello KaiS21,
I see your display shows 6.05 V for the battery. If you can put your multimeter across the battery, what do you get? If the number on the multimeter differs significantly from the value on the display, you can adjust the calibration factor in the software (I can tell you where if you can't find it).
Your panel voltage shows 0 volts, which is consistent with the panel being disconnected or in the dark. To calibrate the panel voltage measurement, you need a panel connected with the sun on it, or else another artificial source of voltage such as a mains powered power supply. Again, you measure the panel voltage with your multimeter, and compare it with the display.
You display current is showing a negative value. This should be the load current, but the negative value could be an incorrect zero offset, or the ACS712 being connected backwards. Both of these can be fixed with software changes if required, but first you need to work out the correct zero offset.
Looking at the photo you provided, the ACS712 is in the right of the photo. Its Vcc wire is red and its data (output) wire is white. With the load disconnected, you should measure both of these relative to ground. The data wire should be exactly 1/2 of the red wire. for example if the red wire measures 4.80 Volts, the white wire should measure 2.40 volts. The other end of the white wire should go to pin A2 on the Arduino, and should also show the same voltage.
If your measurements do not follow what I explained above, you can do adjustments in the software to correct for the difference. If you tell me your numbers, I can advise you on how to change the software if that is appropriate.
Keith


0
None
KaiS21farmerkeith

Reply 1 day ago

Ich habe einige Änderungen vorgenommen, siehe Abbildung 1,
Abbildung 2, Verkabelung unterhalb
meiner Messung am ACS712, unbedeckt am roten Kabel mit der Masse 4,63 und am weißen Kabel mit der Masse 2,32.
Messung Batterie 6.18
Bitte geben Sie die Nummer nur als an eine PN oder E-Mail

Bild1.jpgBild2.jpg
0
None
farmerkeithKaiS21

Reply 1 day ago

good morning KaiS21. I cannot see any difference between these images and the ones you sent yesterday. Did you attach the correct files?
Also your last line, when translated by the robot, generates a sentence I can't understand. It says "Please enter the number only as a PN or email". Can you re-phrase it so maybe it makes sense?
Thanks,
Keith

0
None
KaiS21farmerkeith

Reply 1 day ago

Hallo KaiS21,
ich sehe dein Display zeigt 6,05 V für die Batterie. Was bekommen Sie, wenn Sie Ihr Multimeter über die Batterie schieben können? Wenn die Zahl auf dem Multimeter erheblich vom Wert auf dem Display abweicht, können Sie den Kalibrierungsfaktor in der Software anpassen.
The voltage your paneels shows 0 volt an, was with the isolation of the paneels or the dark is match. Um die Panelspannungsmessung zu kalibrieren, müssen Sie mit der Sonne verbundenes Panel oder eine andere künstliche Spannungsquelle, z. B. ein netzbetriebenes Netzteil. Auch hier messen Sie die Panel-Spannung mit Ihrem Multimeter und vergleichen Sie mit dem Display.
Sie zeigen an, dass aktuell ein negativer Wert angezeigt wird. Dies sollte der Laststrom sein, aber der negative Wert kann eine falsche Nullpunktverschiebung sein oder der ACS712 ist rückwärts angeschlossen. Beides kann bei Bedarf durch Softwareänderungen behoben werden. Zunächst müssen Sie jedoch die richtige Nullpunktverschiebung ermitteln.
Wenn Sie sich das von Ihnen bereitgestellte Foto ansehen, befindet sich der ACS712 rechts auf dem Foto. Sein Vcc-Kabel ist rot und sein Datenkabel (Ausgangskabel) ist weiß. Wenn das letzte nicht angeschlossen ist, sollten Sie beide Werte relativ zur Masse messen. Die Datenleitung sollte genau die Hälfte der roten Leitung betragen. Wenn beispielsweise der rote Draht 4,80 Volt misst, sollte der weiße Draht 2,40 Volt messen. The other end of the white cable is an pin a2 the arduino connected and the same voltage display.
Wenn Ihre Messungen nicht den oben erläuterten Werten entsprechen, können Sie Anpassungen in der Software vornehmen, um den Unterschied zu korrigieren.



((Wenn Sie mir Ihre Nummern mitteilen, können Sie beraten, wie Sie die Software ändern.))


Keith

Ich nahm Bezug auf den Satz siehe klammer


Kai

0
None
farmerkeithKaiS21

Reply 1 day ago

Kai, this is getting more puzzling.
Do you have a question?
Keith

0
None
KaiS21farmerkeith

Reply 1 day ago

was mus ich wo eintragen oder ender in der Software das es richtig leuft

0
None
fonetainer

11 months ago

aim getting following error while uploading the code to Arduino nano

Arduino: 1.8.5 (Mac OS X), Board: "Arduino Nano, ATmega328P"

V2_Deba_168:91: error: 'POSITIVE' was not declared in this scope

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address // In my case 0x27

^

/Users/paaker/Documents/Arduino/V2_Deba_168/V2_Deba_168.ino: In function 'void setup()':

V2_Deba_168:106: error: no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'

lcd.begin(20, 4); // initialize the lcd for 16 chars 2 lines, turn on backlight

^

/Users/paaker/Documents/Arduino/V2_Deba_168/V2_Deba_168.ino:106:18: note: candidate is:

In file included from /Users/paaker/Documents/Arduino/V2_Deba_168/V2_Deba_168.ino:8:0:

/Users/paaker/Documents/Arduino/libraries/Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note: void LiquidCrystal_I2C::begin()

void begin();

^

/Users/paaker/Documents/Arduino/libraries/Arduino-LiquidCrystal-I2C-library-master/LiquidCrystal_I2C.h:76:7: note: candidate expects 0 arguments, 2 provided

exit status 1

'POSITIVE' was not declared in this scope

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Invalid library found in /Users/paaker/Documents/Arduino/libraries/LiquidCrystal_I2C: /Users/paaker/Documents/Arduino/libraries/LiquidCrystal_I2C

Invalid library found in /Users/paaker/Documents/Arduino/libraries/LiquidCrystal_I2C: /Users/paaker/Documents/Arduino/libraries/LiquidCrystal_I2C

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

7 replies
0
None
tgray1fonetainer

Reply 4 days ago

I also had a lot of trouble with the LCD using the original code. I removed all of Dutta's libraries but two:
'#include <Wire.h>
#include <LiquidCrystal_I2C.h>
I edited the I2C address as
LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD I2C address for 20 characters and 4 lines
I added the init command at the top of the lcd section in Setup:
lcd.init(); //turn on the display
These changes fixed all my lcd display issues.

0
None
farmerkeithfonetainer

Reply 10 months ago

Hi fonetainer, You seem to have a lot of problems with this software upload.

Are you able to upload a simple sketch to your Arduino? eg the Blink example in the standard distribution.

Once that is OK, you need to check what library (if any) you have for the LCD. It should be LiquidCrystal_I2C.h although there are several different versions of this library and some work better than others. You may need to change versions if it will not work with the one you have. However first just getting the loading correct and post your new error messages would be a good step.

Keith

0
None
fonetainerfarmerkeith

Reply 10 months ago

Hi Keith,

after very long fight I found some other codes has lcd address something different. I just copy it and past it. now code updated and I can see it on LCD.

aim still not connect the Arduino to Circuit and on the third row current it show minus values even watts also minus value.

0
None
mohammads272fonetainer

Reply 8 months ago

hi fontainer,
i have this problem
please send the new code

0
None
fonetainerfarmerkeith

Reply 10 months ago

Hi Keith,

yes some problem on software or code. I have try several other codes on same Arduino nano. its perfect working the lcd. even the Hello world code is work perfect.

in the original Debate 168 code has like this ,

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address // In my case 0x27

once I try to upload it always say ( POSITIVE was not declared on this scope)

Then I change it to

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

after change it I can upload the code to Arduino. app show Success: Done uploading.

but I can't see any difference on LCD. it still show Hello, World!

This is all done with Online Arduino editor.

if i try same code with my Desktop Arduino, aim getting following error,

Arduino: 1.8.5 (Mac OS X), Board: "Arduino Nano, ATmega328P"

/Users/paaker/Documents/Arduino/sketch_aug31c/sketch_aug31c.ino: In function 'void setup()':

sketch_aug31c:106: error: no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'

lcd.begin(20,4); // initialize the lcd for 16 chars 2 lines, turn on backlight

^

/Users/paaker/Documents/Arduino/sketch_aug31c/sketch_aug31c.ino:106:15: note: candidate is:

In file included from /Users/paaker/Documents/Arduino/sketch_aug31c/sketch_aug31c.ino:8:0:

/Users/paaker/Documents/Arduino/libraries/LiquidCrystal-I2C/LiquidCrystal_I2C.h:76:7: note: void LiquidCrystal_I2C::begin()

void begin();

^

/Users/paaker/Documents/Arduino/libraries/LiquidCrystal-I2C/LiquidCrystal_I2C.h:76:7: note: candidate expects 0 arguments, 2 provided

exit status 1

no matching function for call to 'LiquidCrystal_I2C::begin(int, int)'

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

Regards,

Descktop app.png
0
None
farmerkeithfonetainer

Reply 10 months ago

Hi fonetainer, I think the lcd library you are using has a problem. Maybe an error in the file download, or maybe a bad version. I suggest you delete the current one and reinstall it.

You can probably remove the "POSITIVE" from the function call without affecting how it works, but I think this is not your real problem, which is something to do with the library.

Keith

0
None
Frederiq

Question 4 weeks ago

Hello Debasish Dutta, I am impressed by you project, also the V3 version. I am living off the grid on solar energy, I have a home-made battery charger that can handle 80A from parallel solar panels (24V), it works very with 6 MOSfets in parallel. It works with a simple transistor circuit, which limits the battery voltage to the maximum bulk voltage. Your scheme does that too, if I understand well your Arduino code. Although I did not understand clearly yet whether you maintain the charging voltage at the bulk set point and whether and under which condition you change to float set point voltage. I want to make a new microcontroller (Arduino) charger with better load characteristics, departing from your V2 design. My (very expensive!) lead batteries (4 x 6V = 24V) really require a well defined absorption stage. Battery instructions tell me that when reaching the bulk voltage (29,2V in my case) there is still 25% of the batteries' capacity to be loaded in an absorption stage. During that stage the voltage must be kept at max bulk voltage. You don't have to reach this 100% charge level every day (every cycle), but a least a few times per month, to prevent sulphation (this destroyed my previous battery set). You may not over-charge either, therefore regulating absorption is critical. One can determine the end of absorption by the load current dropping to 0,007 x C20 (depending on battery type), but is would even be better to monitor the current (in and out, as there are also loads in the day time in my case) and voltage over time and calculate the charge until you have added 25% of the battery capacity. After that the voltage should be dropped to float level (around 28V). Your charger has a total charge meter (voltage * current * time), that could be used for determining the end of the absorption phase, if the meter was set to zero when absorption starts. It could be extended by measuring not only the current into the battery, but also out of the battery, and by deducting the corresponding charge from the charge during the absorption phase. I have ordered my Aduino board and started to write code for this. I am still new to Arduino code, but done C programming before; so I hope I will get through it. I hope that my previous experience with MOSFets regulation will also help. My question: has anyone done this before?
Final note: I am not into your MPPT design yet, because I need a charger that can handle up to 100A, and that is still somewhat of a challenge for your V3 project, do you agree?

4 answers
0
None
farmerkeithFrederiq

Answer 16 days ago

Hi Frederiq,
There are certainly many people who have asked about higher power solar chargers, however I am not aware of any published designs in the sort of power ratings you are looking for.
Usually at the sort of power levels you are looking at, the appropriate solution is an MPPT charger, since the additional energy obtained more than justifies the additional cost and complexity of the MPPT design. There are commercial chargers available at these power levels, but no published DIY designs that I am aware of.
There are significant challenges for MPPT at these power levels, and also some for PWM designs but not so serious.
I think I can help you if you want to share some more information.
I understand you are using a 24V lead acid battery and want to charge it will up to 100Amps. Is this correct?
What is the capacity of the battery (in amp-hours)?
What are the solar panels you are using? Are they the typical 60-cell panels used for solar grid connect installations, with a typical power rating of 250 Watts or so? How many panels will you be using?
What sort of climate are you in? Do you have many days with intense sunshine, or is it cloudy a lot of the time?
I understand your focus on the charging voltage, which means you need an accurate voltage measuring capability. The 10-bit ADC of the Arduino Nano/Uno etc. may be adequate if carefully calibrated. If you set the full scale range of the battery voltage divider to 30V, the measurement step size will be 30mV (0.03V) which seems OK, but usually there is some jitter and the real accuracy is going to be more like 0.1V or maybe a bit worse. If you are concerned about this you could go to an external ADC device like the ADS1115 which will give you considerably better accuracy.
The V2.0 PWM design has a current limit of the order of around 5 amps, mainly due to the series diode (MBR2045). At high currents you lose a lot of energy in the forward voltage drop of this diode, and even putting multiple diodes in parallel does not solve that problem. The real solution is to move to a MOSFET diode design, but that has impacts on the way the software works so really the whole design has to be revised for the sort of currents you are looking at. AND you will still have the limitations of a PWM solution.
For a MPPT design, you could look at a modular approach using commercial DC-DC converters. You can find some information along this direction on my github repositories using the SZBK07 converter.
Of course it also depends on what you want to do.
Regards,
Keith

0
None
Frederiqfarmerkeith

Reply 12 days ago

Dear Keith, thanks for your reply and for offering your help; that is really great! I am really hoping to get discussions about this project going also with other people. I was wondering if this website or this thread is still active and whether interested people are still following this. Since you answered, Keith, probably it isn’t a bad place. But would like to make a continuous report about the project, and include discussions. Is there another place on the internet where I could do that? Or I am allowed to make a new Instructable?
I have been running my household in a sunny place in the Caribbean exclusively on solar power for 6 years now. Cooking, washing, water pump, swimming pool filter, even welding, well, just about everything runs on solar electricity here, but we have no aircos or wash dryers (and we don’t need them). The first years we were totally off the grid, but recently I have invested in a connection with the public grid, be it for only 3000W max. But that helps a lot in prolonging battery life as now and then we have days at length of cloudy weather. The set up is: 9 230W solar panels (parallel interconnection), a DYI battery charger (to be improved), 6000W Outback inverters for 230/110V alternating current, 450Ah wet lead-acid batteries at 24V (4 x 6V).
The panels are actually not producing 230W, but about 190W under ideal circumstances. The maximum charging current is 70A. My next charger should be able to handle 100A, as a goal, as I may add more solar panels, however that means that in the gassing phase (>28,8V at 20ºC) the charger should be capable of limiting the current (to about 65A in my case). Because when gassing high currents physically damage wet lead-acid batteries.
PWM or MPPT? I agree that MPPT is to be preferred, and my aim is to get into MPPT regulation in a later stage. But MPPT for 100A is too challenging for me now, and I need a quick result. I am not interested in buying anything from the shelve, but thanks for your suggestions, Keith. I have made a MOSFET PWM charger, that works well, although with limited functionality. With 6 MOSFETs type IRF4905 in parallel, it easily handles 70A, and should be capable to handle 100A. A PWM charger can work on a low frequency, like 40Hz (in MTTP, the size of the coil makes a much higher frequency desirable, but a PWM charger does not have a coil, and the batteries don’t mind the low frequency). MOSFETS heat up mostly during the on-off transition; therefore the lower the frequency the lower the heat loss. I like to work with p-channel MOSFETS as switches because they can be placed in the positive leads so that all negative leads can be interconnected and grounded; the IRF4905 has a forward resistance of 0,02 Ohm, which is about 5 times as much as the best n-channel MOSFET I know of, but the heat loss is nevertheless very acceptable, my charger gets hand-warm, I guess it is dissipating not more than 15W while handling 1700W (60A at 28V for example). Also no super fast MOSFET driver is necessary: a couple a general purpose transistors can do the job when switching at a low frequency.
My present charger is very good in power handling. But bad in charging algorithm. Just like the V2.0 PWM design (and the V3.0 MPPT for that matter) it goes on charging in the absorption phase until it night falls, and this can result in over charging on sunny days when there is little load. This really destroys batteries. One must find a way to measure the state of charge. That’s why I want to include a microprocessor.
Even though MTTP is superior, I wonder if its efficiency it not overstated sometimes. If I look at the V-A curve of my solar panels (yes Keith, 60 cells), with full sunshine their maximum power point is around 29V. In the bulk phase that is not far from the voltage range during which most of the charging takes place (27-29V). An interesting paper about MTTP-PWM can by found at the Victron website, which I found to be very informative also on other aspects of solar energy. https://www.victronenergy.com/upload/documents/White-paper-Which-solar-charge-controller-PWM-or-MPPT.pdf
Accuracy of voltage measurement. I expect that 0.1V accuracy is good enough. But will keep the ADS1115 in mind. Thanks for that suggestion.
The blocking diode. I have looked into this some time ago, I don’t remember the details anymore, but isn’t it so that the type of power MOSFETs that we are using have a built-in body diode, which in case of a IRF9540 (or a IRF4905, or any p-channel power MOSFET for that matter) would conduct in the drain → source direction, and therefore it would not isolate the battery from the panels at night? Or am I now completely off track?
My charger does not have a blocking diode (or FET) because the solar panels are connected in parallel and they have each a series blocking diode.
I have a question regarding voltage and current measurement as in the V2.0 design. If I understand the code correctly, for any measurement 8 (or so) measurements are made, and then the average is calculated, and given as output. My question is, a random measurement could happen in off or on state of the MOSFET. Is the timing of the 8 measurements so that they exactly cover one cycle of the switch? Or a number of complete cycles? What are the considerations behind the V2.0 design in choosing the number of measurements and the length of the time interval between them. Is there a discussion about this?
Greetings, Frederiq

0
None
farmerkeithFrederiq

Reply 6 days ago

Hi Frederiq, I have been having a look at the Victron paper you provided a link for, and extending it to your situation. I think it is a really useful document and I thank you for providing the link.
Based on my analysis, I think you may have a real problem using your 60-cell panels with a 24V lead acid battery, due to the influence of temperature on panel output voltage.
The essential problem is that 60-cell panels work well with charging a 24V battery in the region of 28 to 29 V, provided the panel temperature is no more than 50 Celsius.
I looked up the average maximum temperatures in Martinique and it is about 30 Celsius. Assuming that (which may not be correct for you), the temperature rise in the panel would have to be less than 20 C, which according to the relevant chart in the Victron document requires a free standing panel installation (ie not close to a roof) and wind of about 1.5 - 2 m/s (ie 5 to 8 km/h).
For hotter panel temperatures, up to around 75 C, the charger will still work but with greatly reduced power yield.
The system performance will be significantly impacted by having diodes in series with each panel, which will lose about 1 Volt between the panel voltage and the battery voltage. As a very minimum, I think these diodes need to be removed and the function performed with a MOSFET diode.
Maybe you have real world measurements which are at variance with this analysis, in which case you may be able to use this system.
I would be interested to know the installation parameters of your 9 solar panels, such as free-standing or on a roof, sloping or horizontal. Also the expected cable voltage drop between the panels and the charge controller and battery.
In the Victron paper, they recommend putting panels in series and using an MPPT charger. Another option they do not canvas is using a Buck-boost MPPT charger. As far as I know there are no commercial designs of this type, but it should be entirely possible - although the power levels you require would be a challenge.
If your panel installation is on a roof with minimal clearance between the panels and the roof, and if you commonly do not experience daytime breezes (or at least not commonly enough to rely on the breeze to make your charger work) then maybe you need to consider one of these possibilities.
One way forward would be to build the PWM charger you originally had in mind, with good data collection functions, and use the data from that to determine whether there is a problem and if so the type of solution that is needed.
Food for thought?
Regards,
Keith

PWM yield 60cell 24Vbat.png
0
None
farmerkeithFrederiq

Reply 11 days ago

Hi Frederiq,
Regarding the best forum, it is really up to you to decide but it seems to me that a good solution would be to write your own Instructable about your current setup, experiences and the existing solar charge controller design, and then add to it from time to time as the design evolves. Instructables supports adding new steps (eg as you add design improvements) and also editing of existing steps (eg correcting mistakes or adding missing information). You do have other options, like Facebook, Hackaday, Pinterest, blogspot, and probably others but from my limited knowledge Instructables would be the best. You can share your unpublished drafts with others (eg me) before going "live" if you wish by sending a link to them.
I appreciate your point about PWM being OK for you.
Given that you have a blocking diode installed in each panel, you don't need that function in the solar charge controller. I am thinking about whether there is any benefit in moving that diode function into the controller. More on that another time.
You should be aware that I am not the designer of the V2.0 PWM controller. Deba168 is the author. He (with some help from me) recently published the update v2.01 including a PCB. I doubt if that is a great deal of benefit to you.
As I understand it, the voltage measuring by the ADC of the microcontroller, and the cycle of the PWM, are not synchronised by any active mechanism. Therefore, when in PWM mode, the measured battery voltage, and the measured solar panel voltage, are some variable mix of ON and OFF states. It probably makes the battery voltage rather variable and possibly unsuitable for you.
To fix this you probably need to use a software PWM under which you have precise control of which PWM phase the battery measurement is taken. However this brings me to another question, which I forgot to include in my earlier reply. Which is:
What are your desires regarding control and monitoring of the charge controller?
You should note that the V2.1 (and V2.01) design provides monitoring using an LCD display, and the only "control" mechanism is to update the software. There is no provision for changing any of the set points during operation. Are you OK with this?
Or would you like to have a more capable arrangement?
My current idea is to replace the Nano with an ESP32 which will give WiFi communication, so you can then use either your own or one of the public internet data collection, display and control services. The one I have some experience with, and which I think is pretty good, is Blynk. Blynk would allow you to track the hourly, daily, weekly, monthly charging cycles and also allow you to adjust set points such as the float voltage and absorption time. I find this more atractive than re-loading software each time you find it necessary, and is also an easy way to collect data.
If you don't have, or want to use, WiFi then you can still collect data using a micro-SD card or a USB memory stick. However this requires you to collect it from time to time, and does not give you real-time status information.
What do you think about that?
I am aware that there are many other options for adding WiFi capability, however I have recently started using an ESP32 so that would be the most comfortable for me. I have been using the WeMos D1 mini pro, which is based on the ESP8266, for some time. It has WiFi, however it does not have enough ADC inputs, so it would definitely need the addition of an external ADC such as ADS1115. That would be another option instead of the ESP32.
Regards,
Keith