diy solar

diy solar

Top balancing setup w/ Arduino Monitoring

schroederjd

Solar Enthusiast
Joined
Nov 12, 2020
Messages
175
Hi Everyone,

While waiting for my cells to come in (16 x 272Ah Lishen) from China, I've been working on a top balancing setup. Objectives were 1) don't damage the cells, 2) get the job done in < 2 wks, 3) don't spend more than $100. After reading several threads related to top balancing with Mean Well power supplies, I decided to go in that direction. I purchased a HRPG-300-3.3 from TRC Electronics. Price was $98 after shipping. I went with the HRPG over the HRP because it has the remote on/off and remote voltage sensing features.

The more interesting part of this is how to meet objective 1 (don't damage the cells) without constantly checking the voltage. That's where the microcontroller comes in. I used a Node32s (ESP-32), as I had one on hand, and it has multiple analog inputs (ESP8266 only has one). I used Arduino IDE for the programming along with the Blynk iOS app for remote monitoring. Wiring diagram of the system is shown below. I'm using an open-loop hall-effect current transducer (LEM DHAB S/133) that came with my TinyBMS for current monitoring. I've coded in a non-reversible remote shut-off for when the current reaches a pre-defined set point. This set up allows me to remote monitor the charging from anywhere, and kills the charging automatically so I don't risk overcharging.

I'll post the code once I have it cleaned up. Probably the most complicated part was trying to get the ESP-32 to provide accurate volatge reading (the ADC has a non-linear response). The Blynk app made the remote monitoring setup super easy.

After a lot of testing and tweaking, the system seems to work great. Voltage and current readings are spot on, and the remote shut-off kicks on reliably. I would really appreciate any feedback (risks, design flaws, ideas for additional functionality, etc.).

Circuit diagram:
Circuit Diagram.png
Here's the dashboard I've set up in the Blynk app. Nothing too spectacular, but it allows me to see what's going on...from anywhere.Blynk App.jpeg
 
Here's the code I'm using. To smooth out the data, this reports the a rolling average of last 10 readings. You can change the number of readings in the average by changing the 'numReadings = XX' constant. Also note that for testing, this is currently set up to take readings every 500 milliseconds. For actual charging, I'll probably slow this down. The set-point for remote shut-off is near the bottom.

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = "XXXXXXXXXXXXX";
char ssid[] = "YYYYYYYYYY";
char pass[] = "ZZZZZZZZZZZ";

const int numReadings = 10;
int Creadings[numReadings];
int CreadIndex = 0;
int Ctotal = 0;
int Caverage = 0;
int Vreadings[numReadings];
int VreadIndex = 0;
int Vtotal = 0;
int Vaverage = 0;

const int volPin = 39; //P39 = ADC3
const int curPin = 36; //P36 = ADC0
float Vout = 0.000;
float Vin = 0.000;
float Iout = 0.000;
float Iin = 0.000;
float R1 = 560.00; // resistance of R1
float R2 = 560.00; // resistance of R2
int vol = 0;
int cur = 0;

void setup(){
Serial.begin(115200);
pinMode(4,OUTPUT);
Blynk.begin(auth, ssid, pass);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
Creadings[thisReading] = 0; Vreadings[thisReading] = 0;
}
}
void loop(){
delay(500);
vol = analogRead(volPin);
delay(50);
Vtotal = Vtotal - Vreadings[VreadIndex];
Vreadings[VreadIndex] = analogRead(volPin);
Vtotal = Vtotal + Vreadings[VreadIndex];
VreadIndex = VreadIndex + 1;
if (VreadIndex >= numReadings) {
VreadIndex = 0;
}
Vaverage = Vtotal / numReadings;
Vout = (((-0.0000354393 * pow(Vaverage,2))+(1.130067 * Vaverage)) * 3.3) / 4095.00;
Vin = Vout / ((R2/(R1+R2)));
delay(50);
cur = analogRead(curPin);
delay(50);
Ctotal = Ctotal - Creadings[CreadIndex];
Creadings[CreadIndex] = analogRead(curPin);
Ctotal = Ctotal + Creadings[CreadIndex];
CreadIndex = CreadIndex + 1;
if (CreadIndex >= numReadings) {
CreadIndex = 0;
}
Caverage = Ctotal / numReadings;
Iout = (((-0.0000354393 * pow(Caverage,2))+(1.130067 * Caverage)) * 3.3) / 4095.00;
Iin = ((5/4.96)*(Iout / ((R2/(R1+R2)))) - 2.5) * (1/0.0333);
Blynk.virtualWrite(5, String(Vin, 2) + " V");
Blynk.virtualWrite(6, String(Iin, 1) + " A");
Blynk.virtualWrite(7, Vin);
Blynk.virtualWrite(8, Iin);
if (Vin >= 3.60) {
digitalWrite (4,HIGH);
}

Blynk.run();
}
 
Looks like a great project. I’ve been doing the same but with Raspberry Pi’s and Grafana pulling data of the UART of OEM solar hardware. You can get similar results with 24x7 coverage and alerts from any location on any device. There are so many cool remote sensing gadgets out there now, its hard to know what to try next!
Keep it going, start a github page and get your project out there so others can use it and build upon it.
 
@schroederjd Is there a problem with backflow(cells to charger) after the charge terminates?
Also if you using a code block will preserve the formatting of your code.
Thanks for your excellent work on this.
 
@schroederjd Is there a problem with backflow(cells to charger) after the charge terminates?
Also if you using a code block will preserve the formatting of your code.
Thanks for your excellent work on this.
Thanks for the reply. Great question about backflow/backfeed. In a previous thread on using Mean Well PSUs for top balancing, this was brought up a couple times, but I didn’t see that the question got answered. Some Mean Well PSUs (eg RSD series) specifically state that the unit is not backfeed protected, and that a protecting diode should be used. The HRPG does not have this statement. Not sure if that means it DOES have backfeed protection. Would appreciate any input on this from those regularly using these PSU’s for charging.

Not sure what you mean by a ‘code block’. Could you clarify (sorry, I’m a complete novice when it comes to programming).
 
Thanks for the reply. Great question about backflow/backfeed. In a previous thread on using Mean Well PSUs for top balancing, this was brought up a couple times, but I didn’t see that the question got answered. Some Mean Well PSUs (eg RSD series) specifically state that the unit is not backfeed protected, and that a protecting diode should be used. The HRPG does not have this statement. Not sure if that means it DOES have backfeed protection. Would appreciate any input on this from those regularly using these PSU’s for charging.

Not sure what you mean by a ‘code block’. Could you clarify (sorry, I’m a complete novice when it comes to programming).
The answer is here https://diysolarforum.com/threads/d...ply-instead-of-benchtop-psu.14973/post-168841
Code:
This is a code block
 
I saw that response, but wasn’t sure if it applied to the HRPG series (couldn’t find that note in the documentation for HPRG, but did see it in RSD documentation). I suppose it’s safest to assume I need it. Now I just need to figure out what to get and how to wire it...

Thanks again.
 
+1 to Github for code sharing

Something else you might try is using the WiFiManager library. It includes a web UI for setting the AP SSID and password so there's no need to put them in your sketch. If I had a dollar for every time I uploaded a file to Github with a password or API key in it... Anything you can do to keep that info out of your code is good! https://diyprojects.io/esp32-test-wifimanager-library-manage-wifi-connections
 
Back
Top