Go Down

Topic: arduino based PV monitor -- issues (Read 170 times) previous topic - next topic

puneet1984

 Hello Everyone,

I am a hobbyist and new to this field.

Writing my code in PlatformIO as well as Arduino IDE.

I am trying to build a Arduino based solar charging monitoring system for my personal use.

I am using a separate buck converter for charging the lead acid 12V battery.

please find the schematic and code  and the picture of the fabricated PCB attached for your reference.

My queries-

1) with capacitor attached to battery voltage divider i am getting very high values and when i remove the capacitor the values are in sync with the multimeter readings. ( have changed the values of the voltage divider resistors)

2) i am unable to change the LED connected to D2/3/4 using the code based on the battery voltage. I can change the LED status if I change the pin manually in code.

3) Unable to switch on the mosfet and thus no output on the load side of the circuit.

Any help/corrections will be appreciated.

Code: [Select]

#include <Wire.h>
//oled library
#include <SPI.h>  //oled library
#include <Adafruit_GFX.h> //oled library
#include <Adafruit_SSD1306.h> //oled library

// Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); ////oled library initialise
Adafruit_SSD1306 display(128, 32, &Wire, 4); ////oled library initialise

//defining variables

byte numReadings = 64; //averaging reads
unsigned int ampsum0; // holds <= 64 analogReads //bat
unsigned int ampsum1; // holds <= 64 analogReads //sol
unsigned int ampsum2; // holds <= 64 analogReads //load
float offset0 = 510.0; // calibrate zero current //bat
float offset1 = 510.0; // calibrate zero current //sol
float offset2 = 510.0; // calibrate zero current //load
float span = 0.05; // calibrate max current | 0.05 is for 20A sensor
float current0; // holds final current // bat side
float current1; // holds final current // sol side
float current2; // holds final current // load side
float sol_v; //solar voltage
float bat_v; //battery voltage
float load_v; //load voltage
int vd_sol;
int vd_bat;
//int vd_load;

int b_full = 3; //battery full LED green
int b_partial = 2; //battery partial LED blue
int b_low = 4; //battery low LED red
int pv_on = 5; //solar status LED
int loadoff = 6; // load on/off LED



void setup() {
  pinMode(b_full, OUTPUT);
  pinMode(b_partial, OUTPUT);
  pinMode(b_low, OUTPUT);
  pinMode(pv_on, OUTPUT);
  pinMode(loadoff, OUTPUT);
  digitalWrite(b_full, LOW);
  digitalWrite(b_partial, LOW);
  digitalWrite(b_low, LOW);
  digitalWrite(pv_on, LOW);
  digitalWrite(loadoff, LOW);

  Serial.begin(115200);

  //  OLED setup
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
}

void loop() {
  ampsum0 = 0; // reset
  ampsum1 = 0; // reset
  ampsum2 = 0; // reset
  vd_sol = 0;
  vd_bat = 0;
  //  vd_load = 0;

  for (int i = 0; i < numReadings; i++) ampsum0 += analogRead(A6); //PV current
  current0 = (ampsum0 / numReadings - offset0) * span;
  for (int j = 0; j < numReadings; j++) ampsum1 += analogRead(A3); //Bat current
  current1 = (ampsum1 / numReadings - offset1) * span;
  for (int k = 0; k < numReadings; k++) ampsum2 += analogRead(A2); //load current
  current2 = (ampsum2 / numReadings - offset2) * span;

  for (int l = 0; l < numReadings; l++) vd_sol += analogRead(A0); //PV voltage
  sol_v = (vd_sol * 6.5 * 0.00475) / numReadings;
  for (int m = 0; m < numReadings; m++) vd_bat += analogRead(A1); //Bat voltage
  bat_v = (vd_bat * 4.5 * 0.00475) / numReadings;
  //for (int n = 0; n < numReadings; n++) vd_load += analogRead(A7);
  //load_v = (vd_load * 10.9 * 0.00488) / numReadings;
  load_v = bat_v;

  //serial print
  //Serial.println(ampsum0 / numReadings);
  //Serial.println(ampsum1 / numReadings);
  //Serial.println(ampsum2 / numReadings);

  Serial.println(String("Sol ") + current1 + "A " + sol_v + "V " + (current1 * sol_v) + "W " + "Wh");
  Serial.println(String("Bat ") + current0 + "A " + bat_v + "V " + (current0 * bat_v) + "W " + "Wh");
  Serial.println(String("Load ") + current2 + "A " + load_v + "V " + (current2 * load_v) + "W " + "Wh");

  if (bat_v >= 13) {
    digitalWrite(b_partial, LOW);
    digitalWrite(b_low, LOW);
    digitalWrite(b_full, HIGH);
    digitalWrite(loadoff,LOW);
  } else if (12.5 < bat_v < 13) {
    digitalWrite(b_full, LOW);
    digitalWrite(b_low, LOW);
    digitalWrite(b_partial, HIGH);
    digitalWrite(loadoff,LOW);
  } else if (bat_v <= 12.5) {
    digitalWrite(b_partial, LOW);
    digitalWrite(b_full, LOW);
    digitalWrite(b_low, HIGH);
    digitalWrite(loadoff, HIGH);
  }

  if (sol_v >= 15) {
    digitalWrite(pv_on, HIGH);
  }
  else {
    digitalWrite(pv_on, LOW);
  }


  //OLED display
  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(WHITE);        // Draw white text
  display.setCursor(0, 0);
  display.print(String("S ") + current1 + "A " + sol_v + "V " + (current1 * sol_v) + "W ");
  display.setCursor(0, 10);
  display.print(String("B ") + current0 + "A " + bat_v + "V " + (current0 * bat_v) + "W ");
  display.setCursor(0, 20);
  display.print(String("L ") + current2 + "A " + (current2 * bat_v) + "W ");
  display.display();
  delay(500); // human readable
}





hammy

#1
Sep 11, 2019, 06:11 pm Last Edit: Sep 11, 2019, 06:31 pm by hammy
1. Capacitors in the wrong way around or too low a voltage rating. Short circuit /blown capacitor ?
2. Transistors fitted in upside down - can't see how the led1 would light normally as it's shorted out by Vbe of the transistor ( ~.6v), or maybe because the rest is not yet working?
3. See two.

- D3,2,4 ? Share the same resistor - that is a poor way to do it , you may not get more than one to light as the forward voltages Will differ. If only one is every intended to be on - then no problem

There may be software issues , not looked, and the board may too have errors, have you checked it out to see if it agrees with your schematic ?

Not a good idea to separately fuse the nano. If the fuse goes , but you still have voltages on other pins , then you could destroy the Nano

puneet1984

Hello
Thanks a lot for the reply.

As far as the caps are in question i am using 33uF 25V caps for battery voltage divider and 47uF 25V for PV voltage divider.

D2/3/4 are actually a RGB LED (single) and the cathode is common thus i have added a single resistor. Also i have checked it on breadboard and all three LED light up individually with a single resistor on the cathode. The use for this LED is for visual battery status thus at a particular time only one color will be active.

All the peripherals like ACS and LCD are powered by separate 5V supply, and i can route the supply from the board also (by jumper wire).
Also i have added the fuse (PPTC - self resetting) for extra protection for the arduino as I am powering the board directly from the lead acid battery.

Will definitely appreciate if you can debug the code as well and let me know if you find any errors.

I have checked separately, on hooking 5V supply ACS/LCD works.

puneet1984

anyone???
Please help me out here.

James456709

I think you must check other solution to resolve this.

TomGeorge

#5
Sep 12, 2019, 10:32 am Last Edit: Sep 12, 2019, 10:45 am by TomGeorge
Hi,
Did you breadboard the prototype before going to a PCB?
When you wrote the code did you check each function separately and with a variable power supply to confirm your codes operation?

Can you please repost your schematic with up to date corrections and EXPORT it as a jpg file, rather than photgraph a printed sheet?

Can you please draw a circuit diagram that shows ALL the peripherals around your monitor, not just connectors and place wires where the components on your schematic go, rather than use flags.
Wires show ALL connections for a wire instantly, flags don't, you have to play "Search a Word" to trace signal flow.
Please take this a constructive criticism, I know flag type schematics are good for PCB design, but a nightmare when it comes to trouble-shooting systems. :)

This is a monitor, do you have a PV regulator/controller between the monitor and the PV?
If so check how the controller switches the PV to the battery, most switch the negative side of the PV output.

Under what conditions do you want he output MOSFET to switch ON?

Can you post diagrams of your PCB thanks.

Thanks.. Tom.. :)
PS. I know its a lot, but you have all the info with you and we don't. :)


Everything runs on smoke, let the smoke out, it stops running....

puneet1984

#6
Sep 14, 2019, 08:23 pm Last Edit: Sep 14, 2019, 11:37 pm by puneet1984
Hello

As per your request I have uploaded updated schematic for your reference.

I have had similar monitor running for last 8-10 months without any issues made on perf board. Have updated few components in this one as this is supposed to be "final one". thus most of the code is copied from the earlier version which was running well. What i have added is
load control and fuse
LED for battery level
LED for solar present
LED for load on/off
ACS for load side power calculations


Also I have removed the caps at the voltage dividers.

I am using a 10A buck converter for the battery charging with common negative.

As far as mosfet is concerned, what i have planned is to keep to mosfet on when there is sufficient battery voltage and then turn off the mosfet to stop the current flow from battery to load. This I plan to get by using a transistor (BC547) connected to D6 and ground the gate of the mosfet to switch if off.
I think i have written reverse code for the D6, should be low when load on and high when load off.

At present, I am able to get the different LED 'on' based on the variable voltage but using the actual battery i am getting negative values from voltage divider. Any idea why this is happening??



TomGeorge

#7
Sep 15, 2019, 03:40 am Last Edit: Sep 15, 2019, 04:09 am by TomGeorge
Hi,

Can you post diagrams of your PCB thanks. (Export jpg from EasyEda)

Can you post a diagram of the system please, how all this connects up, you have headers and sockets labeled but where do they go in your system?
What do P1 to P6 connect to?

Have you just connected your PCB up to a variable power supply to see how the PV input circuit and code perform?

Quote
This I plan to get by using a transistor (BC547) connected to D6 and ground the gate of the mosfet to switch if off.
I think i have written reverse code for the D6, should be low when load on and high when load off.
The MOSFET is a P-Ch, grounding the gate will turn it ON as you will be biasing the gate negative with respect to the source.
D6 HIGH will turn Q2 ON which will turn Q1 ON.

LED3 may not light because it is across the base-emitter of Q2, and that will not rise above 0.6V when the base is biased ON by D6.

Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

TomGeorge

#8
Sep 15, 2019, 03:56 am Last Edit: Sep 15, 2019, 04:08 am by TomGeorge
Hi,
Your code would be more readable if you tried not to abbreviate your code.

Code: [Select]
for (int i = 0; i < numReadings; i++)  //PV current
{
  ampsum0 += analogRead(A6);
}
current0 = (ampsum0 / numReadings - offset0) * span;


for (int j = 0; j < numReadings; j++)  //Bat current
{
  ampsum1 += analogRead(A3);
}
current1 = (ampsum1 / numReadings - offset1) * span;


for (int k = 0; k < numReadings; k++)  //load current
{
  ampsum2 += analogRead(A2);
}
current2 = (ampsum2 / numReadings - offset2) * span;


for (int l = 0; l < numReadings; l++)  //PV voltage
{
  vd_sol += analogRead(A0);
}
sol_v = (vd_sol * 6.5 * 0.00475) / numReadings;


for (int m = 0; m < numReadings; m++)  //Bat voltage
{
  vd_bat += analogRead(A1); //Bat voltage
}
bat_v = (vd_bat * 4.5 * 0.00475) / numReadings;


0.1uF caps should be sufficient on ALL the analog inputs.

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

puneet1984

#9
Sep 15, 2019, 09:40 am Last Edit: Sep 15, 2019, 09:41 am by puneet1984
Quote
Can you post diagrams of your PCB thanks. (Export jpg from EasyEda)
please find the PCB layout attached for your reference.
Quote
Have you just connected your PCB up to a variable power supply to see how the PV input circuit and code perform?
I have tested it using a potentiometer working as variable power source for the arduino analog pin but i have not tested it using a actual variable power supply.
Quote
The MOSFET is a P-Ch, grounding the gate will turn it ON as you will be biasing the gate negative with respect to the source. D6 HIGH will turn Q2 ON which will turn Q1 ON.
Yup, i got my mistake, and i have corrected the code.
Code: [Select]

// battery level indicator and load on/off
  if (bat_v >= 13) {
    digitalWrite(b_partial, LOW);
    digitalWrite(b_low, LOW);
    digitalWrite(b_full, HIGH);
    digitalWrite(loadoff, HIGH); //transistor is ON thus gate of mosfet is at GND thus mosfet is ON
  } else if (bat_v >= 12.5) {
    digitalWrite(b_full, LOW);
    digitalWrite(b_low, LOW);
    digitalWrite(b_partial, HIGH);
    digitalWrite(loadoff, HIGH); //transistor is ON thus gate of mosfet is at GND thus mosfet is ON
  } else  {
    digitalWrite(b_partial, LOW);
    digitalWrite(b_full, LOW);
    digitalWrite(b_low, HIGH);
    digitalWrite(loadoff, LOW); //transistor is OFF thus gate of mosfet is at BAT voltage thus mosfet is OFF
  }

Quote
LED3 may not light because it is across the base-emitter of Q2, and that will not rise above 0.6V when the base is biased ON by D6.
ok so then what should be my approach?
Quote
Your code would be more readable if you tried not to abbreviate your code.
I agree but at that time i thought it was OK and now even i think the full coding is better.

This is the updated version of the PCB.
P6 is a two way slider switch to change power supply to ACS/LED from seperate 5V supply to arudino 5V supply.

Go Up