WoodsieLord
New Member
It all started around 2018. Just like Homer Simpson building the circus tent with puree while dining it struck me: I've always wanted get into solar, why wait? "I'm already grown up, I have a job and I definitely want to" I told myself. So after coming back from vacation, around march 2019 I bought 4x 340w mono panels and a PWM charge controller...
It just happens that I live in Buenos Aires city. More precisely on the 9th (and topmost) step, and the elevator stops at the 8th step. I had to think a safe way to put the panels on the roof while being able to fit everything inside the modest elevator.
Once I got the panels, I stacked them by the bed where I had to look at them each day for almost a year.
(the smiley thing was a gift for my son ?. Also, I'm not a tidy person. I could say 'Our wiring jobs speak for our tidiness')
Long story extremely short: First solar project. I planned the whole thing around an online UPS I own that I wanted to use as the inverter. No way to monitor State of charge, generation or consumption since I lack the accessory to do so. So I experimented with IoT to try to get data in DIY Style. This is by no means a professional project and I did it to learn. The final goal was to add some kind of intelligence that would read this data and command a relay module to enable or disable AC input from the power company to the UPS in a way that would take benefit from the sun while using my small battery bank as a mere "buffer". So you could say this kind of looks like a dumbed-down grid tie. That is, until I can afford a decent battery bank (appropietly sized).
Reading Volts, Amps and Watts with IoT devices..
I will try to share with you how I managed to read analog information (battery voltage, amps & watts both generated and consumed ) for my solar project. Please take into consideration that I'm no electronic nor electric engineer. I happen to be in IT and I started messing around with Arduinos and Raspberries as a hobby not long ago.
DISCLAIMER:
I'm a messy coder. I usually grab examples from the internet and start modifying them to reach my goals. My resulting code is known to cause nausea, memory loss, deep excruciating pain when staring blank and recalling parts of code even after discontinuing exposure to code, lose of will to live, alcoholism and other afflictions. Read at your own risk!
Also, I have a tendency to comment some lines in a primitive English and some in Spanish. I don't know why I do this but I've been doing that for quite some time.
a. To read DC voltages I use an arduino since the Raspberry pi has no analog pins in its GPIO.
b. To read current I use a separate chip interfaced via I2C to the raspberry. Technically speaking, this chip could also be integrated to the arduino using I2C but since most code examples available happen to be written in python, I chose to connect it to the RPI.
c. Battery State of Charge. If I know how much power comes and goes, I should be able to tell my battery SoC, right? Well.. it's not that easy.
a. Reading Voltages using an Arduino.
Arduinos feature analog pins and an integrated 10 bits analog to digital converter. In other words, some of these pins can be used to read voltages from zero up to "about 5V". This reading is interpreted as a 10 bit number that goes from 0 to 1024. In case of Arduinos, they will assign 1024 to voltages equal to the "VCC" (usually 5V).
If you power your arduino with 4.98V, then the analog pins will throw 1024 when the voltage detected is 4.98V. If you power your arduino with 5.08V, then 5V on the analog pin would be detected as ~ 1008 (since 1024 would be 5.08V).
You don't need to be a genius to understand that VCC can compromise the accuracy of those readings. In my case, I wanted the results to be consistent and I was willing to accept somewhat inaccurate values.
So! Most solar systems that we are used to read in this forum either work with 48V, 24V or 12V. So, reading up to 5V is pretty much useless. The solution is to use a voltage divider which will drop voltages to a desirable range, proportionally.
There are lot of examples and online calculators that I used to determine which resistors I needed and how to build the voltage divider. An engineer might get angry that I put the thing together just following recipes from the internet instead of understanding the underlaying maths, but remember that I started this as an experiment to learn.
useful link: https://circuitdigest.com/calculators/voltage-divider-calculator
Continuing... if 1024 is "VCC", then the Analog reading equals the approximate voltage produced by the voltage divider. With a simple conversion (considering the chosen resistors) we can arrive at an approximation of the actual voltage.
At this point I had a working prototype that I tested with some replaced 12V SLA batteries from an UPS. I've tried many combinations and voltages and compared them with my multimeter. The accuracy shifted when I stopped using the arduino directly to my notebook and started interfacing it with the Rpi (probably because of the VCC). I was happy: after averaging some values, I send the result to the Raspberry through serial (Connected via USB) and I could read the voltage with simple python code.
very early version of my arduino code.
C:
int analogInput = A0;
float vout = 0.0;
float vin = 0.0;
float R1 = 5100.0; //
float R2 = 251.0; //
int value = 0;
float a1 = 0.0;
float a2 = 0.0;
float a3 = 0.0;
float a4 = 0.0;
float a5 = 0.0;
float a6 = 0.0;
float suma = 0;
int contador = 0;
void setup(){
pinMode(analogInput, INPUT);
Serial.begin(9600);
// Serial.print("DC VOLTMETER");
}
void loop(){
// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
// Correcciónes !
if(vin < 28){
vin = vin - (vin * 6 / 100);
}
if(vin>=28 && vin<53){
vin = vin - (vin * 6 / 100);
}
if(vin>=53){
vin = vin - (vin * 6 / 100);
}
if(contador == 0){
a1 = vin;
}
if(contador == 1){
a2 = vin;
}
if(contador == 2){
a3 = vin;
}
if(contador == 3){
a4 = vin;
}
if(contador == 4){
a5 = vin;
}
if(contador == 5){
a6 = vin;
}
if(contador == 6){
suma = a1+a2+a3+a4+a5+a6;
vin = suma/6;
Serial.println(vin,2);
contador = 0;
} else {
contador++;
}
delay(300);
}
(I'll continue with more posts. Feel absolutely FREE to correct me. I'm no expert and my English is not that good either!)