So i am trying to make a solar charger with arduino and i am taking it one step at a time, i am making the monitoring first, everything is ok and shows up nicely on the screen when the input V and A are not changing, the moment they change, let's say the A turns to 0, the Wh also goes to 0, the total amount of power used is not adding up, only for the current period of time. This is how my lcd looks like, and the code i am using.
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads(0x4B);
Adafruit_ADS1115 adsa(0x4A);
float V1 = 0.0;
float V2 = 0.0;
float V3 = 0.0;
float V4 = 0.0;
float V5 = 0.0;
float V6 = 0.0;
void setup(void)
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
ads.begin();
adsa.begin();
}
unsigned long startMillis;
unsigned long currentMillis;
unsigned long elapsedMillis;
void loop(void)
{
int16_t adc1;
adc1 = ads.readADC_SingleEnded(1);
V1 = (adc1 * 0.0001875) * 6;
int16_t adc2;
adc2 = ads.readADC_SingleEnded(2);
V2 = (adc2 * 0.0001875) * 6;
int16_t adc3;
adc3 = ads.readADC_SingleEnded(3);
V3 = (adc3 * 0.0001875) * 6;
int16_t adc4;
adc4 = adsa.readADC_SingleEnded(1);
V4 = (adc4 * 0.0001875) * 10;
int16_t adc5;
adc5 = adsa.readADC_SingleEnded(2);
V5 = (adc5 * 0.0001875) * 10;
int16_t adc6;
adc6 = adsa.readADC_SingleEnded(3);
V6 = (adc6 * 0.0001875) * 10;
currentMillis = millis();
elapsedMillis = (currentMillis - startMillis);
unsigned long SS = (elapsedMillis / 1000) % 60;
unsigned long MM = (elapsedMillis / (60000)) % 60;
unsigned long HH = (elapsedMillis / (3600000));
lcd.setCursor(0, 0);
lcd.print(V1, 2);
lcd.setCursor(5, 0);
lcd.print("V");
lcd.setCursor(7, 0);
lcd.print(V2, 2);
lcd.setCursor(12, 0);
lcd.print("V");
lcd.setCursor(14, 0);
lcd.print(V3, 2);
lcd.setCursor(19, 0);
lcd.print("V");
lcd.setCursor(0, 1);
lcd.print(V4, 2);
lcd.setCursor(5, 1);
lcd.print("A");
lcd.setCursor(7, 1);
lcd.print(V5, 2);
lcd.setCursor(12, 1);
lcd.print("A");
lcd.setCursor(14, 1);
lcd.print(V6, 2);
lcd.setCursor(19, 1);
lcd.print("A");
lcd.setCursor(0, 2);
lcd.print(V1 * V4, 1);
lcd.setCursor(5, 2);
lcd.print("W");
lcd.setCursor(7, 2);
lcd.print(V2 * V5, 1);
lcd.setCursor(12, 2);
lcd.print("W");
lcd.setCursor(14, 2);
lcd.print(V3 * V6, 1);
lcd.setCursor(19, 2);
lcd.print("W");
lcd.setCursor(0, 3);
lcd.print((((V1 * V4) + (V2 * V5)) * elapsedMillis) / 3600000, 0);
lcd.setCursor(7, 3);
lcd.print(((V3 * V6) * elapsedMillis) / 3600000, 0);
lcd.setCursor(14, 3);
lcd.print(MM);
lcd.setCursor(17, 3);
lcd.print(":");
lcd.setCursor(19, 3);
lcd.print(" ");
lcd.setCursor(18, 3);
lcd.print(SS);
}