Solucionado FZ0430 lecturas incorrectas en 2 de 4

Sabes que no todos los pines del Arduino son PWM no?

Si, lo se, estoy usando el pin 6 de Arduino uno, ya estoy consiguiendo que inicie el PWM, (batería sin carga) pero no consigo que se apague (bateria cargada) cuando termina de cargar.
Nota: ya enciende y apaga el PWM con la nuevo ajuste de variables.



#define solar_current_in A0
#define solar_voltage_in A1
#define battery_voltage_in A2
#define solar_min_voltage 14.100
#define battery_min_voltage 11.600
#define charging_current 0.400
#define bulk_voltage_max 12.400
#define bulk_voltage_min 12.000
#define absorption_voltage 12.500
#define absorption_max_current 0.260
#define absorption_min_current 0.106
#define float_voltage 12.600
#define float_voltage_max 12.600
#define float_voltage_min 12.500
#define float_max_current 0.120
#define load_enable 2
#define PWM_out 6
#define LCD_refresh_rate 1000

int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;

const int sensorPin = A0;
const unsigned long TIEMPO_CURRENT = 10UL;
float sensorValue = 0;
float currentValue = 0;
float voltsporUnidade = 0.0041012855327468;
float ruido = 0.00;
unsigned long tiempocurrent;
int Current;

double Vout = 0;
const int sensor0 = A5;
const int sensor1 = A4;
const int sensor2 = A3;
const unsigned long TIEMPO_LECTURAS = 3000UL;

byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";

float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;

float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;

float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;

int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;

unsigned long tiempolecturas;

void setup() {

  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  TCCR1B = TCCR1B & B11111000 | B00000001; // PWM 31372.55 Hz
  Serial.begin(9600);
  before_millis = millis;
}

void loop() {

  if (millis() - tiempolecturas > 3000UL) {
    if (millis() - tiempocurrent > 10UL) {
      currentValue = 0;
      for (int index = 0; index < 5000; index++) {
        sensorValue = analogRead(sensorPin);
        sensorValue = (sensorValue - 516.39) * voltsporUnidade;
        currentValue = currentValue + (sensorValue / 100) * 1000;
        delay(1);
      }
      currentValue = currentValue / 5000;
      Serial.print("corrente = " );
      currentValue = currentValue - ruido;
      Serial.print(currentValue, 3);
      Serial.print("\n" );
      Serial.println("pwm ");
      Serial.print(pwm_percentage);
      Serial.print("\n" );

      //Serial.println("");

      if (Current > 0.100) {
        digitalWrite(rele8, HIGH);
      }  if (Current < 0.300) {
        digitalWrite(rele8, LOW);
      }

      solar_voltage = get_solar_voltage(15);
      bat_voltage =   get_battery_voltage(15);
      solar_current = get_solar_current(15);
      solar_power = bat_voltage * solar_current;
      pwm_percentage = map(pwm_value, 0, 255, 0, 100);
      now_millis = millis();
      if (now_millis - before_millis > LCD_refresh_rate)
      {
        before_millis = now_millis;
        Serial.println("solar voltaje");
        Serial.println(solar_voltage, 3);
        Serial.println("pwm");
        Serial.println(pwm_percentage);
         Serial.println("solar_current =");
        Serial.println(solar_current, 3);
        Serial.println(load_status);
        Serial.println(bat_voltage, 3);
      }
      if (bat_voltage < battery_min_voltage) {
        digitalWrite(load_enable, LOW);
        load_status  = "OFF";
      }
      else {
        digitalWrite(load_enable, HIGH);
        load_status  = "ON";
      }
      ////////////////////////////////BATERIA 1 ///////////////////////////////////////////
      adc_value0 = analogRead(sensor0);
      adc_voltage0  = (adc_value0 * ref_voltage0) / 1024.0;
      in_voltage0 = adc_voltage0 / (R2 / (R1 + R2));
      if (in_voltage0 > 16.10) {
        digitalWrite(rele9, HIGH);
      }
      if (in_voltage0 < 15.80) {
        digitalWrite(rele9, LOW);
      }
      //////////////////////BATERIA 2 /////////////////////////////////////////////////////
      adc_value1 = analogRead(sensor1);
      adc_voltage1  = (adc_value1 * ref_voltage1) / 1024.0;
      in_voltage1 = adc_voltage1 / (R4 / (R3 + R4));
      if (in_voltage1 > 12.70) {
        digitalWrite(rele10, HIGH);
      }
      if (in_voltage1 < 12.40) {
        digitalWrite(rele10, LOW);
      }
      ///////////////////////BATERIA 3 /////////////////////////////////////////////////
      adc_value2 = analogRead(sensor2);
      adc_voltage2  = (adc_value2 * ref_voltage2) / 1024.0;
      in_voltage2 = adc_voltage2 / (R6 / (R5 + R6));
      if (in_voltage1 > 8.90) {
        digitalWrite(rele11, HIGH);
      }
      if (in_voltage1 < 8.20) {
        digitalWrite(rele11, LOW);
      }
      /////////////////////////// FLOAT ///////////////////////////
      if (mode == FLOAT) {
        if (bat_voltage < float_voltage_min) {
          mode = BULK;
          mode_str = "BULK";
        }
        else {
          if (solar_current > float_max_current) {
            mode = BULK;
            mode_str = "BULK";
          }
          else {
            if (bat_voltage > float_voltage) {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 254);
            }
            else {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 254);
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      else {
        if (bat_voltage < bulk_voltage_min) {
          mode = BULK;
          mode_str = "BULK";
        }
        else if (bat_voltage > bulk_voltage_max) {
          mode_str = "ABSORPTION";
          mode = ABSORPTION;
        }

        //////////////////////////// BULK /////////////////////
        
        if (mode == BULK) {
          if (solar_current > charging_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 254);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 254);
          }
          analogWrite(PWM_out, pwm_value);
        }
        ///////////////////////// ABSORPTION //////////////////
        
        if (mode == ABSORPTION) {
          if (solar_current > absorption_max_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 254);
          }
          else {
            if (bat_voltage > absorption_voltage) {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 254);
            }
            else {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 254);
            }
            if (solar_current < absorption_min_current) {
              mode = FLOAT;
              mode_str = "FLOAT";
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      
      Serial.println("sensor 0 ");
      Serial.print(in_voltage0, 2);
      Serial.println("V");
      Serial.println("sensor 1 ");
      Serial.print(in_voltage1, 2);
      Serial.println("V");
      Serial.println("sensor 2 ");
      Serial.print(in_voltage2, 2);
      Serial.println("V");
      
      tiempolecturas = millis();
      tiempocurrent = millis();
    }
  }
}
////////////////////  fin vood loop();  ///////////////////////

float get_solar_voltage(int n_samples)
{
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)
  {
    voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 5.610);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples)
{
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)
  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.757);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_solar_current(int n_samples)
{
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)
  {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.51503) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}
float in_voltage(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Es muy difícil ajustarlo, tengo tres días haciendo ajustes, ahora seria bueno minimizarlo creo que hay muchos renglones innecesarios.
Saludos.

Existen algunas cosas mal en tu código.
Mira esta parte al comienzo del loop

  if (millis() - tiempolecturas > 3000UL) {
    if (millis() - tiempocurrent > 10UL) {
        currentValue = 0;
        for (int index = 0; index < 5000; index++) {
            sensorValue = analogRead(sensorPin);
            sensorValue = (sensorValue - 516.39) * voltsporUnidade;
            currentValue = currentValue + (sensorValue / 100) * 1000;
            delay(1);
        }

cada 3 segundo tomas lecturas y luego cada 10 mseg haces un loop que demora 5000 x 1 mseg = 5000 mseg o sea, tu loop insume 5 segundos dentro de uno de 10 mseg que esta dentro de otro de 3 segundos. Como que algo esa mal no?

En el proceso de achicar el código he hecho algunos cambios iniciales.

#include <Arduino.h>

#define bulk_voltage_max         14.000
#define bulk_voltage_min         12.500
#define absorption_voltage       12.300
#define float_voltage_max        13.100
#define battery_min_voltage      10.600
#define solar_min_voltage        14.200
#define charging_current          0.300
#define absorption_max_current    0.266
#define absorption_min_current    0.166
#define float_voltage_min        13.500
#define float_voltage            13.600
#define float_max_current         0.120
#define LCD_refresh_rate       1000
#define PWM_out                   6
#define load_enable               2
#define solar_current_in          A0
#define solar_voltage_in          A1
#define battery_voltage_in        A2

int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;

const int sensorPin = A0;
const unsigned long TIEMPO_CURRENT = 10UL;
unsigned int sensorValue = 0;
unsigned long sumaSensorValue = 0;
float currentValue = 0;
float voltsporUnidad = 0.0041012855327468;
float ruido = 0.00;
unsigned long tiempocurrent;
int Current;

double Vout = 0;
const int sensor0 = A5;
const int sensor1 = A4;
const int sensor2 = A3;

struct Bateria  {
  const int sensor;
  float adc_voltage;
  float in_voltage;
  float ref_voltage;
  float max, min;
  const int rele;
  int R1, R2;
};

Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
                      {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
                      {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
                     };

const unsigned long TIEMPO_LECTURAS = 3000UL;
byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";

float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;

float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;

float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;

int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;

unsigned long tiempolecturas;

void leoBateria(int id) {

  bateria[id].adc_voltage  = (analogRead(bateria[id].sensor) * bateria[id].ref_voltage) / 1024.0;
  bateria[id].in_voltage = bateria[id].adc_voltage / (bateria[id].R2 / (bateria[id].R1 + bateria[id].R2));
  if (bateria[id].in_voltage > bateria[id].max) {
    digitalWrite(bateria[id].rele, HIGH);
  }
  if (bateria[id].in_voltage < bateria[id].min) {
    digitalWrite(bateria[id].rele, LOW);
  }
}

void setup() {

  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  TCCR1B = TCCR1B & B11111000 | B00000001; // PWM 31372.55 Hz
  Serial.begin(9600);
  before_millis = millis();
}

void loop() {

  if (millis() - tiempolecturas > 3000UL) {
    if (millis() - tiempocurrent > 10UL) {
        sumaSensorValue = 0;
        for (int index = 0; index < 5000; index++) {
            sumaSensorValue += analogRead(sensorPin);
        }
        sensorValue = (float) sumaSensorValue/ 5000;
        sensorValue = (sensorValue - 516.39) * voltsporUnidad;
        currentValue += (sensorValue / 100) * 1000;

        Serial.print("corriente = " );
        currentValue = currentValue - ruido;
        Serial.print(currentValue, 3);
        Serial.print("\n" );
        Serial.println("pwm ");
        Serial.print(pwm_percentage);
        Serial.print("\n" );

        //Serial.println("");

        if (Current > 0.100) {
            digitalWrite(rele8, HIGH);
        }  
        if (Current < 0.300) {
            digitalWrite(rele8, LOW);
        }

      solar_voltage = get_solar_voltage(15);
      bat_voltage   = get_battery_voltage(15);
      solar_current = get_solar_current(15);
      solar_power = bat_voltage * solar_current;
      pwm_percentage = map(pwm_value, 0, 255, 0, 100);
      now_millis = millis();
      if (now_millis - before_millis > LCD_refresh_rate)  {
          before_millis = now_millis;
          Serial.println("solar voltaje");
          Serial.println(solar_voltage, 3);
          Serial.println("pwm");
          Serial.println(pwm_percentage);
          Serial.println("solar_current =");
          Serial.println(solar_current, 3);
          Serial.println(load_status);
          Serial.println(bat_voltage, 3);
      }
      if (bat_voltage < battery_min_voltage) {
          digitalWrite(load_enable, LOW);
          load_status  = "OFF";
      }
      else {
          digitalWrite(load_enable, HIGH);
          load_status  = "ON";
      }

      // BATERIA 1
      leoBateria(0);
      // BATERIA 2
      leoBateria(1);
      // BATERIA 3
      leoBateria(2);

      ///////////////////////////FLOAT///////////////////////////
      if (mode == FLOAT) {
        if (bat_voltage < float_voltage_min) {
            mode = BULK;
            mode_str = "BULK";
        }
        else {
          if (solar_current > float_max_current) {
              mode = BULK;
              mode_str = "BULK";
          }
          else {
            if (bat_voltage > float_voltage) {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      else {
        if (bat_voltage < bulk_voltage_min) {
          mode = BULK;
          mode_str = "BULK";
        }
        else if (bat_voltage > bulk_voltage_max) {
          mode_str = "ABSORPTION";
          mode = ABSORPTION;
        }

        ////////////////////////////BULK///////////////////////////
        if (mode == BULK) {
          if (solar_current > charging_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          analogWrite(PWM_out, pwm_value);
        }
        /////////////////////////ABSORPTION/////////////////////////
        if (mode == ABSORPTION) {
          if (solar_current > absorption_max_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            if (bat_voltage > absorption_voltage) {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            if (solar_current < absorption_min_current) {
              mode = FLOAT;
              mode_str = "FLOAT";
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      //Serial.println("    VOLTAJE VCC   ");
      Serial.println("sensor 0 ");
      Serial.print(in_voltage0, 2);
      Serial.println("V");
      Serial.println("sensor 1 ");
      Serial.print(in_voltage1, 2);
      Serial.println("V");
      Serial.println("sensor 2 ");
      Serial.print(in_voltage2, 2);
      Serial.println("V");
      tiempolecturas = millis();
      tiempocurrent = millis();
    }
  }
}

////////////////////fin vood loop();/////////////////////////////////////
float get_solar_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)   {
      voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 4.860);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
      voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples){
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.757);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}

float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.51503) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}

float in_voltage(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Como la parte que te acabo de mencionar requiere tu mirada no quise seguir.

Ya que estamos, esto

currentValue = currentValue + (sensorValue / 100) * 1000;

es lo mismo que esto

currentValue = currentValue + sensorValue * 10.0;

Yo sigo viendo que sigues dando saltos en lugar de pasos, y, lo creas o no, las cosas se resuelven mejor dando pequeños pasos.

Saludos

Tomada la sugerencia, acabo de modificar otras cosas al código #43 pero no lo que has señalado @anon90500195.

Hola @Surbyte, tiene un error de copilado,

Arduino:1.8.19 (Windows 10), Tarjeta:"Arduino Uno"

FZ0430_Surbyte:52:65: error: 'R1' was not declared in this scope

 Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
                                                            ^~
C:\Users\silvi\Desktop\FZ0430_Surbyte\FZ0430_Surbyte.ino:52:65: note: suggested alternative: 'A1'

 Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},

                                                                 ^~

                                                                 A1

FZ0430_Surbyte:52:69: error: 'R2' was not declared in this scope

 Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},

                                                                     ^~

C:\Users\silvi\Desktop\FZ0430_Surbyte\FZ0430_Surbyte.ino:52:69: note: suggested alternative: 'A2'

 Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},

                                                                     ^~

                                                                     A2

FZ0430_Surbyte:53:65: error: 'R3' was not declared in this scope

                       {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},

                                                                 ^~

C:\Users\silvi\Desktop\FZ0430_Surbyte\FZ0430_Surbyte.ino:53:65: note: suggested alternative: 'A3'

                       {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},

                                                                 ^~

                                                                 A3

FZ0430_Surbyte:53:69: error: 'R4' was not declared in this scope

                       {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},

                                                                     ^~

C:\Users\silvi\Desktop\FZ0430_Surbyte\FZ0430_Surbyte.ino:53:69: note: suggested alternative: 'A4'

                       {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},

                                                                     ^~

                                                                     A4

FZ0430_Surbyte:54:65: error: 'R5' was not declared in this scope

                       {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}

                                                                 ^~

C:\Users\silvi\Desktop\FZ0430_Surbyte\FZ0430_Surbyte.ino:54:65: note: suggested alternative: 'A5'

                       {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}

                                                                 ^~

                                                                 A5

FZ0430_Surbyte:54:69: error: 'R6' was not declared in this scope

                       {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}

                                                                     ^~

C:\Users\silvi\Desktop\FZ0430_Surbyte\FZ0430_Surbyte.ino:54:69: note: suggested alternative: 'A6'

                       {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}

     A6
exit status 1

'R1' was not declared in this scope

La intención de (const unsigned long TIEMPO_CURRENT = 10UL;) era sacar un promedio, de la lectura del ACS712 si note que tardaba mucho mas de 3 segundos en imprimir los datos, en el monitor Serial. Del renglon 133 al 138 es la lectura del ACS712 lo mismo del 299 al 310 lee el ACS712 voy a comentar del 133 al 138

Hola @Surbyte , no puedo quitar el error, ya comente la doble lectura del ACS712, al inicio del void loop(){

//https://forum.arduino.cc/t/fz0430-lecturas-incorrectas-en-2-de-4/998825/43


#include <Arduino.h>
#define bulk_voltage_max         14.000
#define bulk_voltage_min         12.500
#define absorption_voltage       12.300
#define float_voltage_max        13.100
#define battery_min_voltage      10.600
#define solar_min_voltage        14.200
#define charging_current          0.300
#define absorption_max_current    0.266
#define absorption_min_current    0.166
#define float_voltage_min        13.500
#define float_voltage            13.600
#define float_max_current         0.120
#define LCD_refresh_rate       1000
#define PWM_out                   6
#define load_enable               2
#define solar_current_in          A0
#define solar_voltage_in          A1
#define battery_voltage_in        A2

int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;

const int sensorPin = A0;
const unsigned long TIEMPO_CURRENT = 10UL;
float sensorValue = 0;
float currentValue = 0;
float voltsporUnidade = 0.0041012855327468;
float ruido = 0.00;
unsigned long tiempocurrent;
int Current;

double Vout = 0;
const int sensor0 = A5;
const int sensor1 = A4;
const int sensor2 = A3;

struct Bateria {
const int sensor;
float adc_voltage;
float in_voltage;
float ref_voltage;
float max, min;
const int rele;
int R1, R2;
int R3,  R4;
int R5, R6;
};

Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
  {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
  {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
};

const unsigned long TIEMPO_LECTURAS = 3000UL;
byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";

float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;

float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;

float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;

int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;

unsigned long tiempolecturas;

void leoBateria(int id) {

  bateria[id].adc_voltage  = (analogRead(bateria[id].sensor) * bateria[id].ref_voltage) / 1024.0;
  bateria[id].in_voltage = bateria[id].adc_voltage / (bateria[id].R2 / (bateria[id].R1 + bateria[id].R2));
  if (bateria[id].in_voltage > bateria[id].max) {
    digitalWrite(bateria[id].rele, HIGH);
  }
  if (bateria[id].in_voltage < bateria[id].min) {
    digitalWrite(bateria[id].rele, LOW);
  }
}

void setup() {

  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  TCCR1B = TCCR1B & B11111000 | B00000001; // PWM 31372.55 Hz
  Serial.begin(9600);
  before_millis = millis();
}

void loop() {

  if (millis() - tiempolecturas > 3000UL) {
    /*
    if (millis() - tiempocurrent > 10UL) {
      currentValue = 0;
      for (int index = 0; index < 5000; index++) {
        sensorValue = analogRead(sensorPin);
        sensorValue = (sensorValue - 516.39) * voltsporUnidade;
        currentValue = currentValue + (sensorValue / 100) * 1000;
        delay(1);
      }
      */
      currentValue = currentValue / 5000;
      Serial.print("corriente = " );
      currentValue = currentValue - ruido;
      Serial.print(currentValue, 3);
      Serial.print("\n" );
      Serial.println("pwm ");
      Serial.print(pwm_percentage);
      Serial.print("\n" );

      //Serial.println("");

      if (Current > 0.100) {
        digitalWrite(rele8, HIGH);
      }
      if (Current < 0.300) {
        digitalWrite(rele8, LOW);
      }

      solar_voltage = get_solar_voltage(15);
      bat_voltage   = get_battery_voltage(15);
      solar_current = get_solar_current(15);
      solar_power = bat_voltage * solar_current;
      pwm_percentage = map(pwm_value, 0, 255, 0, 100);
      now_millis = millis();
      if (now_millis - before_millis > LCD_refresh_rate)  {
        before_millis = now_millis;
        Serial.println("solar voltaje");
        Serial.println(solar_voltage, 3);
        Serial.println("pwm");
        Serial.println(pwm_percentage);
        Serial.println("solar_current =");
        Serial.println(solar_current, 3);
        Serial.println(load_status);
        Serial.println(bat_voltage, 3);
      }
      if (bat_voltage < battery_min_voltage) {
        digitalWrite(load_enable, LOW);
        load_status  = "OFF";
      }
      else {
        digitalWrite(load_enable, HIGH);
        load_status  = "ON";
      }

      // BATERIA 1
      leoBateria(0);
      // BATERIA 2
      leoBateria(1);
      // BATERIA 3
      leoBateria(2);

      ///////////////////////////FLOAT///////////////////////////
      if (mode == FLOAT) {
        if (bat_voltage < float_voltage_min) {
          mode = BULK;
          mode_str = "BULK";
        }
        else {
          if (solar_current > float_max_current) {
            mode = BULK;
            mode_str = "BULK";
          }
          else {
            if (bat_voltage > float_voltage) {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      else {
        if (bat_voltage < bulk_voltage_min) {
          mode = BULK;
          mode_str = "BULK";
        }
        else if (bat_voltage > bulk_voltage_max) {
          mode_str = "ABSORPTION";
          mode = ABSORPTION;
        }

        ////////////////////////////BULK///////////////////////////
        if (mode == BULK) {
          if (solar_current > charging_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          analogWrite(PWM_out, pwm_value);
        }
        /////////////////////////ABSORPTION/////////////////////////
        if (mode == ABSORPTION) {
          if (solar_current > absorption_max_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            if (bat_voltage > absorption_voltage) {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            if (solar_current < absorption_min_current) {
              mode = FLOAT;
              mode_str = "FLOAT";
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }

      Serial.println("sensor 0 ");
      Serial.print(in_voltage0, 2);
      Serial.println("V");
      Serial.println("sensor 1 ");
      Serial.print(in_voltage1, 2);
      Serial.println("V");
      Serial.println("sensor 2 ");
      Serial.print(in_voltage2, 2);
      Serial.println("V");
      tiempolecturas = millis();
     // tiempocurrent = millis();
    //}
  }
}
////////////////////fin vood loop();/////////////////////////////////////
float get_solar_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)   {
    voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 4.860);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.757);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}

float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.51503) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}

float in_voltage(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Saludos.

Hola @Surbyte, regresanso a los TIMMERs, me parece que hay un detalle que hay que corregir, original mente el código tenia al pin digital 9 como emisor PWM, yo lo cambie al pin digital 6, pero veo que los TIMMERs son de diferente configuración, TCCR0B = (TCCR0B & 0b11111000) esta es la configuración para los pines 5 y 6 digitales, y esta es la configuración que tiene el codigo TCCR1B = TCCR1B & B11111000 | B00000001; // PWM 31372.55 Hz coincide con la configuración que creo que es para los pines 9 y 10 digitales, y yo estoy usando el pin 6 digital.

https://playground.arduino.cc/Main/TimerPWMCheatsheet/

Saludos.

Simplemente pones la estructura y su definición mas abajo de los globales y listo.

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  22.0% (used 451 bytes from 2048 bytes)
Flash: [==        ]  24.5% (used 7912 bytes from 32256 bytes)
Building .pio\build\uno\firmware.hex

Aca el código, mira los errores y analiza que hay que hacer.

#include <Arduino.h>

#define bulk_voltage_max         14.000
#define bulk_voltage_min         12.500
#define absorption_voltage       12.300
#define float_voltage_max        13.100
#define battery_min_voltage      10.600
#define solar_min_voltage        14.200
#define charging_current          0.300
#define absorption_max_current    0.266
#define absorption_min_current    0.166
#define float_voltage_min        13.500
#define float_voltage            13.600
#define float_max_current         0.120
#define LCD_refresh_rate       1000
#define PWM_out                   6
#define load_enable               2
#define solar_current_in          A0
#define solar_voltage_in          A1
#define battery_voltage_in        A2

int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;

const int sensorPin = A0;
const unsigned long TIEMPO_CURRENT = 10UL;
unsigned int sensorValue = 0;
unsigned long sumaSensorValue = 0;
float currentValue = 0;
float voltsporUnidad = 0.0041012855327468;
float ruido = 0.00;
unsigned long tiempocurrent;
int Current;

double Vout = 0;
const int sensor0 = A5;
const int sensor1 = A4;
const int sensor2 = A3;

const unsigned long TIEMPO_LECTURAS = 3000UL;
byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";

float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;

float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;

float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;

int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;

unsigned long tiempolecturas;


struct Bateria  {
  const int sensor;
  float adc_voltage;
  float in_voltage;
  float ref_voltage;
  float max, min;
  const int rele;
  int R1, R2;
};

Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
                      {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
                      {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
                     };

void leoBateria(int id) {

  bateria[id].adc_voltage  = (analogRead(bateria[id].sensor) * bateria[id].ref_voltage) / 1024.0;
  bateria[id].in_voltage = bateria[id].adc_voltage / (bateria[id].R2 / (bateria[id].R1 + bateria[id].R2));
  if (bateria[id].in_voltage > bateria[id].max) {
    digitalWrite(bateria[id].rele, HIGH);
  }
  if (bateria[id].in_voltage < bateria[id].min) {
    digitalWrite(bateria[id].rele, LOW);
  }
}

////////////////////fin vood loop();/////////////////////////////////////
float get_solar_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)   {
      voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 4.860);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
      voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples){
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.757);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}

float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.51503) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}

float in_voltage(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void setup() {

  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  TCCR1B = TCCR1B & B11111000 | B00000001; // PWM 31372.55 Hz
  Serial.begin(9600);
  before_millis = millis();
}

void loop() {

  if (millis() - tiempolecturas > 3000UL) {
    if (millis() - tiempocurrent > 10UL) {
        sumaSensorValue = 0;
        for (int index = 0; index < 5000; index++) {
            sumaSensorValue += analogRead(sensorPin);
        }
        sensorValue = (float) sumaSensorValue/ 5000;
        sensorValue = (sensorValue - 516.39) * voltsporUnidad;
        currentValue += (sensorValue / 100) * 1000;

        Serial.print("corriente = " );
        currentValue = currentValue - ruido;
        Serial.print(currentValue, 3);
        Serial.print("\n" );
        Serial.println("pwm ");
        Serial.print(pwm_percentage);
        Serial.print("\n" );

        //Serial.println("");

        if (Current > 0.100) {
            digitalWrite(rele8, HIGH);
        }  
        if (Current < 0.300) {
            digitalWrite(rele8, LOW);
        }

      solar_voltage = get_solar_voltage(15);
      bat_voltage   = get_battery_voltage(15);
      solar_current = get_solar_current(15);
      solar_power = bat_voltage * solar_current;
      pwm_percentage = map(pwm_value, 0, 255, 0, 100);
      now_millis = millis();
      if (now_millis - before_millis > LCD_refresh_rate)  {
          before_millis = now_millis;
          Serial.println("solar voltaje");
          Serial.println(solar_voltage, 3);
          Serial.println("pwm");
          Serial.println(pwm_percentage);
          Serial.println("solar_current =");
          Serial.println(solar_current, 3);
          Serial.println(load_status);
          Serial.println(bat_voltage, 3);
      }
      if (bat_voltage < battery_min_voltage) {
          digitalWrite(load_enable, LOW);
          load_status  = "OFF";
      }
      else {
          digitalWrite(load_enable, HIGH);
          load_status  = "ON";
      }

      // BATERIA 1
      leoBateria(0);
      // BATERIA 2
      leoBateria(1);
      // BATERIA 3
      leoBateria(2);

      ///////////////////////////FLOAT///////////////////////////
      if (mode == FLOAT) {
        if (bat_voltage < float_voltage_min) {
            mode = BULK;
            mode_str = "BULK";
        }
        else {
          if (solar_current > float_max_current) {
              mode = BULK;
              mode_str = "BULK";
          }
          else {
            if (bat_voltage > float_voltage) {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      else {
        if (bat_voltage < bulk_voltage_min) {
          mode = BULK;
          mode_str = "BULK";
        }
        else if (bat_voltage > bulk_voltage_max) {
          mode_str = "ABSORPTION";
          mode = ABSORPTION;
        }

        ////////////////////////////BULK///////////////////////////
        if (mode == BULK) {
          if (solar_current > charging_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          analogWrite(PWM_out, pwm_value);
        }
        /////////////////////////ABSORPTION/////////////////////////
        if (mode == ABSORPTION) {
          if (solar_current > absorption_max_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            if (bat_voltage > absorption_voltage) {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            if (solar_current < absorption_min_current) {
              mode = FLOAT;
              mode_str = "FLOAT";
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      //Serial.println("    VOLTAJE VCC   ");
      Serial.println("sensor 0 ");
      Serial.print(in_voltage0, 2);
      Serial.println("V");
      Serial.println("sensor 1 ");
      Serial.print(in_voltage1, 2);
      Serial.println("V");
      Serial.println("sensor 2 ");
      Serial.print(in_voltage2, 2);
      Serial.println("V");
      tiempolecturas = millis();
      tiempocurrent = millis();
    }
  }
}


Volviendo al tema TIMRERs que te prohibe volver al pin 9, porque lo usas con el Rele9 pero puedes cambiarlo y darle prioridad a algo que sabes funcionaría.
Porque le cabiaste la frecuencia? Normalmente sale con 980Hz aprox, porque 32Khz?

Hola @Surbyte, ya estoy haciendo ´pruebas, las dos primeras funcionaron bien, la tercera no, no apago el PWM estando por encima del limite de carga, ahora voy con la cuarta prueba y ya subió a 100% el PWM y ahora esta bajando tiene que llegar a 0% y después mantenerse en float por tiempo indefinido (5%) seguiré haciendo pruebas hoy y mañana.
Saludos

Nota: según tengo entendido, entre mas altos los Hz. mas tiempo de vida tienen las baterías, de cualquier forma de momento, ya elimine los 32Hz. y lo deje en lo trae por defecto Arduino para su pin 6 .

Hola @Surbyte, en esta área del código esta el problema (Sensor_voltage - "2.48322") / current_factor; cuando ajusto los números que están entre comillas para que el monitor Serial coincida con el voltimetro ya no detiene la carga

float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.4832) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;

cuando desajusto y se queda en 0.00, la corriente, inicia la carga y termina su ciclo de forma correcta, y si ajusto para que la lectura del voltimetro, coincida con el Seria,l el ciclo no se detiene nunca. Creo que aquí no debo hacer el ajuste sino en factor en el renglo 37. Ya le di una limpiada al código.

#include <Arduino.h>
#define bulk_voltage_max         12.400
#define bulk_voltage_min         12.200
#define absorption_voltage       12.500
#define float_voltage_max        12.600
#define battery_min_voltage      10.600
#define solar_min_voltage        14.100
#define charging_current          0.300
#define absorption_max_current    0.266
#define absorption_min_current    0.166
#define float_voltage_min        12.700
#define float_voltage            12.800
#define float_max_current         0.120
#define LCD_refresh_rate       1000
#define PWM_out                   6
#define load_enable               2
#define solar_current_in          A0
#define solar_voltage_in          A1
#define battery_voltage_in        A2
int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;
int Current;
double Vout = 0;
const int sensor0 = A5;
const int sensor1 = A4;
const int sensor2 = A3;
const unsigned long TIEMPO_LECTURAS = 3000UL;
byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";
float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;
float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;
int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;
unsigned long tiempolecturas;
struct Bateria  {
  const int sensor;
  float adc_voltage;
  float in_voltage;
  float ref_voltage;
  float max, min;
  const int rele;
  int R1, R2;
};
Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
  {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
  {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
};
void leoBateria(int id) {
  bateria[id].adc_voltage  = (analogRead(bateria[id].sensor) * bateria[id].ref_voltage) / 1024.0;
  bateria[id].in_voltage = bateria[id].adc_voltage / (bateria[id].R2 / (bateria[id].R1 + bateria[id].R2));
  if (bateria[id].in_voltage > bateria[id].max) {
    digitalWrite(bateria[id].rele, HIGH);
  }
  if (bateria[id].in_voltage < bateria[id].min) {
    digitalWrite(bateria[id].rele, LOW);
  }
}
////////////////////fin vood loop();/////////////////////////////////////
float get_solar_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)   {
    voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 5.060);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.512);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.4832) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}
float in_voltage(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void setup() {
  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  Serial.begin(9600);
  before_millis = millis();
}

void loop() {

  if (millis() - tiempolecturas > 3000UL) {
    Serial.print("corriente = " );
    Serial.print("\n" );
    Serial.println("pwm ");
    Serial.print(pwm_percentage);
    Serial.print("\n" );
    if (Current > 0.100) {
      digitalWrite(rele8, HIGH);
    }
    if (Current < 0.300) {
      digitalWrite(rele8, LOW);
    }
    solar_voltage = get_solar_voltage(15);
    bat_voltage   = get_battery_voltage(15);
    solar_current = get_solar_current(15);
    solar_power = bat_voltage * solar_current;
    pwm_percentage = map(pwm_value, 0, 255, 0, 100);
    now_millis = millis();
    if (now_millis - before_millis > LCD_refresh_rate)  {
      before_millis = now_millis;
      Serial.println("V. fuente");
      Serial.println(solar_voltage, 3);
      Serial.println("V. battery");
      Serial.println(bat_voltage, 3);
      Serial.println("B. current");
      Serial.println(solar_current, 3);
      Serial.println("pwm %");
      Serial.println(pwm_percentage);
      Serial.println(load_status);
    }
    if (bat_voltage < battery_min_voltage) {
      digitalWrite(load_enable, LOW);
      load_status  = "OFF";
    }
    else {
      digitalWrite(load_enable, HIGH);
      load_status  = "ON";
    }
    // BATERIA 1
    leoBateria(0);
    // BATERIA 2
    leoBateria(1);
    // BATERIA 3
    leoBateria(2);
    ///////////////////////////FLOAT///////////////////////////
    if (mode == FLOAT) {
      if (bat_voltage < float_voltage_min) {
        mode = BULK;
        mode_str = "BULK";
      }
      else {
        if (solar_current > float_max_current) {
          mode = BULK;
          mode_str = "BULK";
        }
        else {
          if (bat_voltage > float_voltage) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
        }
        analogWrite(PWM_out, pwm_value);
      }
    }
    else {
      if (bat_voltage < bulk_voltage_min) {
        mode = BULK;
        mode_str = "BULK";
      }
      else if (bat_voltage > bulk_voltage_max) {
        mode_str = "ABSORPTION";
        mode = ABSORPTION;
      }
      ////////////////////////////BULK///////////////////////////
      if (mode == BULK) {
        if (solar_current > charging_current) {
          pwm_value--;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        else {
          pwm_value++;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        analogWrite(PWM_out, pwm_value);
      }
      /////////////////////////ABSORPTION/////////////////////////
      if (mode == ABSORPTION) {
        if (solar_current > absorption_max_current) {
          pwm_value--;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        else {
          if (bat_voltage > absorption_voltage) {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          if (solar_current < absorption_min_current) {
            mode = FLOAT;
            mode_str = "FLOAT";
          }
        }
        analogWrite(PWM_out, pwm_value);
      }
    }
    Serial.println("sensor 0 ");
    Serial.print(in_voltage0, 2);
    Serial.println("V");
    Serial.println("sensor 1 ");
    Serial.print(in_voltage1, 2);
    Serial.println("V");
    Serial.println("sensor 2 ");
    Serial.print(in_voltage2, 2);
    Serial.println("V");
    tiempolecturas = millis();
  }
}

toda vía le sobran mas cosas, ya se las ire quitando.
Nota: Si ven algo incongruente en los ajustes de voltaje me lo dicen porfavor.
Saludos.

Hola @Surbyte, A0-A1-A2, funcionan bien, ya conseguí ajustar la batería acido plomo controlada por estos pines. Los pines A5-A4-A3, ahora ya ni dan lectura en el Monitor Serial si dan pero todo en cero, tampoco activan o desactivan los reles 9- 10-11, el 8 si se activa, ese depende A0, no se si fue tantas cosas que yo le fui quitando al código viendo el historial en el post#42 toda vía funcionan A5-A4-A3 no se en que punto los des habilite.
Saludos.
NOTA: ya empiezo a entender el arreglo de baterías, si que ahorra renglones de código.

Primero no son 32Hz sino 32.000 Hz o 32Khz que no es lo mismo. Eso pudo ser un error de tipeo de tu parte.
Las baterías no tienen larga vida porque la frecuencia principal sea de 32Khz. Estamos hablando de corrientes de carga. La PWM actua sobre la tensión y la corriente de carga resultante es la integración de dicha PWM, eso crea una corriente tipo diente de sierra son escalones con dientes de diferentes anchos. A mayor frecuencia esos escalones son mas suaves que a baja frecuencia.
Eso claramente es mejor.

Me sorprende que no sepas resolver problemas como estos.
Yo usé una estructura para asociar todas las variables comunes en algo que las contiene, manteniendo tus etiquetas pero anteponíendolo bateria[id].etiqueta.
Entonces si ahora no se lee nada solo debes cambiar esto

Serial.println("sensor 0 ");
      Serial.print(in_voltage0, 2);
      Serial.println("V");
      Serial.println("sensor 1 ");
      Serial.print(in_voltage1, 2);
      Serial.println("V");
      Serial.println("sensor 2 ");
      Serial.print(in_voltage2, 2);
      Serial.println("V");

por esto

      Serial.println("sensor 0 ");
      Serial.print(bateria[0].in_voltage, 2);
      Serial.println("V");
      Serial.println("sensor 1 ");
      Serial.print(bateria[1].in_voltage, 2);
      Serial.println("V");
      Serial.println("sensor 2 ");
      Serial.print(bateria[2].in_voltage, 2);
      Serial.println("V");

O reduciendo un poco mas

      for (int i=0; i<3; i++) {
          Serial.println("sensor "+String(i)+" ");
          Serial.print(bateria[i].in_voltage, 2);
          Serial.println("V");
      }

Ahora miro lo de los reles y edito aquí, asi que espera mi respuesta.
El error de pq no funcionan los reles es que puse en la estructura

const int rele; 
// y debe ser
int rele;

Versión completa corregida hasta ahora.

#include <Arduino.h>

#define bulk_voltage_max         14.000
#define bulk_voltage_min         12.500
#define absorption_voltage       12.300
#define float_voltage_max        13.100
#define battery_min_voltage      10.600
#define solar_min_voltage        14.200
#define charging_current          0.300
#define absorption_max_current    0.266
#define absorption_min_current    0.166
#define float_voltage_min        13.500
#define float_voltage            13.600
#define float_max_current         0.120
#define LCD_refresh_rate       1000
#define PWM_out                   6
#define load_enable               2
#define solar_current_in          A0
#define solar_voltage_in          A1
#define battery_voltage_in        A2

int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;

const int sensorPin = A0;
const unsigned long TIEMPO_CURRENT = 10UL;
unsigned int sensorValue = 0;
unsigned long sumaSensorValue = 0;
float currentValue = 0;
float voltsporUnidad = 0.0041012855327468;
float ruido = 0.00;
unsigned long tiempocurrent;
int Current;

double Vout = 0;
const int sensor0 = A5;
const int sensor1 = A4;
const int sensor2 = A3;

const unsigned long TIEMPO_LECTURAS = 3000UL;
byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";

float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;

float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;

float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;

int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;

unsigned long tiempolecturas;


struct Bateria  {
  const int sensor;
  float adc_voltage;
  float in_voltage;
  float ref_voltage;
  float max, min;
  int rele;
  int R1, R2;
};

Bateria bateria[3] = {{A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
                      {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
                      {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
                     };

void leoBateria(int id) {

  bateria[id].adc_voltage  = (analogRead(bateria[id].sensor) * bateria[id].ref_voltage) / 1024.0;
  bateria[id].in_voltage = bateria[id].adc_voltage / (bateria[id].R2 / (bateria[id].R1 + bateria[id].R2));
  if (bateria[id].in_voltage > bateria[id].max) {
    digitalWrite(bateria[id].rele, HIGH);
  }
  if (bateria[id].in_voltage < bateria[id].min) {
    digitalWrite(bateria[id].rele, LOW);
  }
}

////////////////////fin vood loop();/////////////////////////////////////
float get_solar_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)   {
      voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 4.860);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
      voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples){
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.757);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}

float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.51503) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}

float in_voltage(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void setup() {

  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  TCCR1B = TCCR1B & B11111000 | B00000001; // PWM 31372.55 Hz
  Serial.begin(9600);
  before_millis = millis();
}

void loop() {

  if (millis() - tiempolecturas > 3000UL) {
    if (millis() - tiempocurrent > 10UL) {
        sumaSensorValue = 0;
        for (int index = 0; index < 5000; index++) {
            sumaSensorValue += analogRead(sensorPin);
        }
        sensorValue = (float) sumaSensorValue/ 5000;
        sensorValue = (sensorValue - 516.39) * voltsporUnidad;
        currentValue += (sensorValue / 100) * 1000;

        Serial.print("corriente = " );
        currentValue = currentValue - ruido;
        Serial.print(currentValue, 3);
        Serial.print("\n" );
        Serial.println("pwm ");
        Serial.print(pwm_percentage);
        Serial.print("\n" );

        //Serial.println("");

        if (Current > 0.100) {
            digitalWrite(rele8, HIGH);
        }  
        if (Current < 0.300) {
            digitalWrite(rele8, LOW);
        }

      solar_voltage = get_solar_voltage(15);
      bat_voltage   = get_battery_voltage(15);
      solar_current = get_solar_current(15);
      solar_power = bat_voltage * solar_current;
      pwm_percentage = map(pwm_value, 0, 255, 0, 100);
      now_millis = millis();
      if (now_millis - before_millis > LCD_refresh_rate)  {
          before_millis = now_millis;
          Serial.println("solar voltaje");
          Serial.println(solar_voltage, 3);
          Serial.println("pwm");
          Serial.println(pwm_percentage);
          Serial.println("solar_current =");
          Serial.println(solar_current, 3);
          Serial.println(load_status);
          Serial.println(bat_voltage, 3);
      }
      if (bat_voltage < battery_min_voltage) {
          digitalWrite(load_enable, LOW);
          load_status  = "OFF";
      }
      else {
          digitalWrite(load_enable, HIGH);
          load_status  = "ON";
      }

      // BATERIA 1
      leoBateria(0);
      // BATERIA 2
      leoBateria(1);
      // BATERIA 3
      leoBateria(2);

      ///////////////////////////FLOAT///////////////////////////
      if (mode == FLOAT) {
        if (bat_voltage < float_voltage_min) {
            mode = BULK;
            mode_str = "BULK";
        }
        else {
          if (solar_current > float_max_current) {
              mode = BULK;
              mode_str = "BULK";
          }
          else {
            if (bat_voltage > float_voltage) {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      else {
        if (bat_voltage < bulk_voltage_min) {
          mode = BULK;
          mode_str = "BULK";
        }
        else if (bat_voltage > bulk_voltage_max) {
          mode_str = "ABSORPTION";
          mode = ABSORPTION;
        }

        ////////////////////////////BULK///////////////////////////
        if (mode == BULK) {
          if (solar_current > charging_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          analogWrite(PWM_out, pwm_value);
        }
        /////////////////////////ABSORPTION/////////////////////////
        if (mode == ABSORPTION) {
          if (solar_current > absorption_max_current) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            if (bat_voltage > absorption_voltage) {
              pwm_value++;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            else {
              pwm_value--;
              pwm_value = constrain(pwm_value, 0, 255);
            }
            if (solar_current < absorption_min_current) {
              mode = FLOAT;
              mode_str = "FLOAT";
            }
          }
          analogWrite(PWM_out, pwm_value);
        }
      }
      //Serial.println("    VOLTAJE VCC   ");
      for (int i=0; i<3; i++) {
          Serial.println("sensor "+String(i)+" ");
          Serial.print(bateria[i].in_voltage, 2);
          Serial.println("V");
      }
      
      tiempolecturas = millis();
      tiempocurrent = millis();
    }
  }
}

EDICION FINAL de este POST:
Releyendo esta parte del código me encuentro conque aún asi

        for (int index = 0; index < 5000; index++) { 5000*100useg= 
            sumaSensorValue += analogRead(sensorPin);
        }

5000 x 0.1 mseg = 500 mseg
Antes era mas o menos 5000 x 1mseg por que usabas un delay(1) que yo quite.
Estamos aun en 500 mseg lo que es una barbaridad.
Para que tantas muestras?
Recuerda porqué hago la observación? Y se debe a que vienes de un

 if (millis() - tiempocurrent > 10UL) {

y de otro lapso de 3000 mseg o sea, ahora el primer condicional esta bien porque 500 mseg para promediar la corriente estan dentro de tu muestreo cada 3 segundos pero el segundo cada 10 mseg no tiene sentido. Asi que o lo eliminas o achicas la cantidad de iteracciones.
500 muestras serian 50 mseg y aun asi son mayores a tus 10 mseg.

Hola @Surbyte, esto da ahora el monitor Serial.
Haciendo los cambios que me recomendaste

sensor 0 
infV
sensor 1 
infV
sensor 2 
infV

antes daba esto

sensor 0 
0.00V
sensor 1 
0.00V
sensor 2 
0.00V

con adc_voltage

sensor 0 
000110V
sensor 1 
000110V
sensor 2 
000110V

En este código, ya elimine los tiempos y promedios, que estaban de mas.
ordene el Monitor Serial en relacion a los pines A0-A1-A2,
Ya solo tiene 259 renglones, el anterior 299 y me imagino que se puede reducir mas.

#include <Arduino.h>

#define bulk_voltage_max         12.200
#define bulk_voltage_min         12.100
#define absorption_voltage       12.300
#define absorption_max_current    0.266
#define absorption_min_current    0.166
#define float_voltage            12.600
#define float_voltage_max        12.400
#define float_voltage_min        12.450
#define float_max_current         0.120
#define battery_min_voltage      10.000
#define solar_min_voltage        14.200
#define charging_current          0.300
#define PWM_out                   6
#define load_enable               2
#define solar_current_in          A0
#define solar_voltage_in          A1
#define battery_voltage_in        A2
#define LCD_refresh_rate       1000
int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;
int Current
const int sensor0 = A5;
const int sensor1 = A4;
const int sensor2 = A3;
const unsigned long TIEMPO_LECTURAS = 3000UL;
byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";
float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;
float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;
int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;
unsigned long tiempolecturas;
struct Bateria  {
  const int sensor;
  float adc_voltage;
  float in_voltage;
  float ref_voltage;
  float max, min;
  int rele;
  int R1, R2;
};
Bateria bateria[3] = {
  {A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
  {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
  {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
};
void leoBateria(int id) {
  bateria[id].adc_voltage  = (analogRead(bateria[id].sensor) * bateria[id].ref_voltage) / 1024.0;
  bateria[id].in_voltage = bateria[id].adc_voltage / (bateria[id].R2 / (bateria[id].R1 + bateria[id].R2));
  if (bateria[id].in_voltage > bateria[id].max) {
    digitalWrite(bateria[id].rele, HIGH);
  }
  if (bateria[id].in_voltage < bateria[id].min) {
    digitalWrite(bateria[id].rele, LOW);
  }
}
float get_solar_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)   {
    voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 4.860);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.757);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.51503) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}
float in_voltage(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void setup() {
  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  Serial.begin(9600);
  before_millis = millis();
}
void loop() {
  if (millis() - tiempolecturas > 3000UL) {
       if (Current > 0.100) {
      digitalWrite(rele8, HIGH);
    }
    if (Current < 0.300) {
      digitalWrite(rele8, LOW);
    }
    solar_voltage = get_solar_voltage(15);
    bat_voltage   = get_battery_voltage(15);
    solar_current = get_solar_current(15);
    solar_power = bat_voltage * solar_current;
    pwm_percentage = map(pwm_value, 0, 255, 0, 100);
    now_millis = millis();
    if (now_millis - before_millis > LCD_refresh_rate)  {
      before_millis = now_millis;
      Serial.println("V. Fuente");
      Serial.println(solar_voltage, 3);
      Serial.println("V. Bateria");
      Serial.println(bat_voltage, 3);
      Serial.println("pwm");
      Serial.println(pwm_percentage);
      Serial.println("B. AMP");
      Serial.println(solar_current, 3);
      Serial.println(load_status);
    }
    if (bat_voltage < battery_min_voltage) {
      digitalWrite(load_enable, LOW);
      load_status  = "OFF";
    }
    else {
      digitalWrite(load_enable, HIGH);
      load_status  = "ON";
    }
    // BATERIA 1
    leoBateria(0);
    // BATERIA 2
    leoBateria(1);
    // BATERIA 3
    leoBateria(2);

    /////   FLOAT       /////////
    if (mode == FLOAT) {
      if (bat_voltage < float_voltage_min) {
        mode = BULK;
        mode_str = "BULK";
      }
      else {
        if (solar_current > float_max_current) {
          mode = BULK;
          mode_str = "BULK";
        }
        else {
          if (bat_voltage > float_voltage) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
        }
        analogWrite(PWM_out, pwm_value);
      }
    }
    else {
      if (bat_voltage < bulk_voltage_min) {
        mode = BULK;
        mode_str = "BULK";
      }
      else if (bat_voltage > bulk_voltage_max) {
        mode_str = "ABSORPTION";
        mode = ABSORPTION;
      }

      /////////   BULK    ////////////
      if (mode == BULK) {
        if (solar_current > charging_current) {
          pwm_value--;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        else {
          pwm_value++;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        analogWrite(PWM_out, pwm_value);
      }
     ////////  ABSORPTION  ///////
      if (mode == ABSORPTION) {
        if (solar_current > absorption_max_current) {
          pwm_value--;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        else {
          if (bat_voltage > absorption_voltage) {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          if (solar_current < absorption_min_current) {
            mode = FLOAT;
            mode_str = "FLOAT";
          }
        }
        analogWrite(PWM_out, pwm_value);
      }
    }
    for (int i = 0; i < 3; i++) {
      Serial.println("sensor " + String(i) + " ");
      Serial.print(bateria[i].in_voltage, 2);
      Serial.println("V");
    }
    tiempolecturas = millis();    
  }
}

Nota no e podido repara el monitor serial para los pines A5-A4-A3, sigue apareciendo (infV) en lugar del voltaje.
Saludos.

const int sensor;

debería ser

int sensor;

Hola @anon90500195 , ya modifique

int sensor0 = A5;
int sensor1 = A4;
int sensor2 = A3;

Sigue igual el monitor Serial

sensor 0 
infV
sensor 1 
infV
sensor 2 
infV

Nota: a const int sensor; ya lo cambie a int sensor; por sugerencia de @Surbyte .
Saludos.

Esto

struct Bateria { 
  const int sensor; 
  float adc_voltage; 
  float in_voltage;

tenés que cambiar.

Copiar y pegar y/o borrar algunas líneas es fácil, el asunto es entender lo que se hace.

De hecho

int sensor0 = A5;
int sensor1 = A4;
int sensor2 = A3;

está de más porque los pines los defines en

Bateria bateria[3] = { 
 {A5, 0.0, 0.0, 5.0, 16.10, 15.80, rele9, R1, R2},
 {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
 {A3, 0.0, 0.0, 5.0, 8.90, 8.20, rele11, R5, R6}
 };

Pues si lo cambiaste no lo hiciste en el código que nos muestras.

struct Bateria {
  int sensor;
  float adc_voltage;
  float in_voltage;
  float ref_voltage;
  float max, min;
  const int rele;
  int R1, R2;
};
Bateria bateria[3] = {
  {A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
  {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
  {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
};

Hola @anon90500195, así lo tengo en el código que estoy usando para pruebas una disculpa por no hacer la corrección en el código que presente
Saludos.
Nota ya elimine.

int sensor0 = A5;
int sensor1 = A4;
int sensor2 = A3;

Esto define lo que se imprimira en el monitor Serial?

 for (int i = 0; i < 3; i++) {
      Serial.println("sensor " + String(i) + " ");
      Serial.print(bateria[i].in_voltage, 2);
      Serial.println("V");
    }

Si que simplifica el trabajo.
Hice esta modificación en lugar de in_voltage por adc_voltage

 for (int i = 0; i < 3; i++) {
      Serial.println("sensor " + String(i) + " ");
      Serial.print(bateria[i].adc_voltage, 3);
      Serial.println("V");

Y este fue el resultado en el Monitor Serial.

Volt. Fuente
13.780
Volt. Bateria
13.394
pwm
0
Bat. AMP
0.000
ON
sensor 0 
2.734V
sensor 1 
1.909V
sensor 2 
1.611V

Creo que estre es el valor que envia el sensor no esta convertido al valor de lectura.
Nota solo esta conectado un sensor al A5 = sensor0

Silvia por favor!!! Te lo expuse con claridad en el post#53, @anon90500195 te lo vuelve a explicar y posteas en el post#58 el mismo error.

Lee de nuevo mi final y luego vuelve a leer lo que @anon90500195 te dice.

Hola @Surbyte esperoy ahora este corregido correctamente las sugerencias de @anon90500195 y @Surbyte no se ha corregido el monitor Serial para los pines A5, A4, A3.

#include <Arduino.h>
#define bulk_voltage_max         12.200
#define bulk_voltage_min         12.100
#define absorption_voltage       12.300
#define absorption_max_current    0.266
#define absorption_min_current    0.166
#define float_voltage            12.600
#define float_voltage_max        12.400
#define float_voltage_min        12.450
#define float_max_current         0.120
#define battery_min_voltage      10.000
#define solar_min_voltage        14.200
#define charging_current          0.300
#define PWM_out                   6
#define load_enable               2
#define solar_current_in          A0
#define solar_voltage_in          A1
#define battery_voltage_in        A2
#define LCD_refresh_rate       1000
int rele8 = 8;
int rele9 = 9;
int rele10 = 10;
int rele11 = 11;
int Current;
const unsigned long TIEMPO_LECTURAS = 3000UL;
byte BULK = 0;
byte ABSORPTION = 1;
byte FLOAT = 2;
byte mode = 0;
float bat_voltage = 0;
int pwm_value = 3;
float solar_current = 0;
float current_factor = 0.100;
float solar_voltage = 0;
float solar_power = 0.0;
String load_status = "OFF";
int pwm_percentage = 0;
unsigned int before_millis = 0;
unsigned int now_millis = 0;
String mode_str = "BULK";
float adc_voltage0 = 0.0;
float in_voltage0 = 0.0;
float adc_voltage1 = 0.0;
float in_voltage1 = 0.0;
float adc_voltage2 = 0.0;
float in_voltage2 = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float R3 = 30000.0;
float R4 = 7500.0;
float R5 = 30000.0;
float R6 = 7500.0;
float ref_voltage0 = 5.0;
float ref_voltage1 = 5.0;
float ref_voltage2 = 5.0;
int adc_value0 = 0;
int adc_value1 = 0;
int adc_value2 = 0;
unsigned long tiempolecturas;
struct Bateria {
  int sensor;
  float adc_voltage;
  float in_voltage;
  float ref_voltage;
  float max, min;
  int rele;
  int R1, R2;
};
Bateria bateria[3] = {
  {A5, 0.0, 0.0, 5.0, 16.10, 15.80,  rele9, R1, R2},
  {A4, 0.0, 0.0, 5.0, 12.70, 12.40, rele10, R3, R4},
  {A3, 0.0, 0.0, 5.0,  8.90,  8.20, rele11, R5, R6}
};
void leoBateria(int id) {
  bateria[id].adc_voltage  = (analogRead(bateria[id].sensor) * bateria[id].ref_voltage) / 1024.0;
  bateria[id].in_voltage = bateria[id].adc_voltage / (bateria[id].R2 / (bateria[id].R1 + bateria[id].R2));
  if (bateria[id].in_voltage > bateria[id].max) {
    digitalWrite(bateria[id].rele, HIGH);
  }
  if (bateria[id].in_voltage < bateria[id].min) {
    digitalWrite(bateria[id].rele, LOW);
  }
}
float get_solar_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)   {
    voltage += (analogRead(solar_voltage_in) * (5.0 / 1023.0) * 4.860);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_battery_voltage(int n_samples) {
  float voltage = 0;
  for (int i = 0; i < n_samples; i++)  {
    voltage += (analogRead(battery_voltage_in) * (5.0 / 1023.0) * 4.757);
  }
  voltage = voltage / n_samples;
  if (voltage < 0) {
    voltage = 0;
  }
  return (voltage);
}
float get_solar_current(int n_samples) {
  float Sensor_voltage;
  float current = 0;
  for (int i = 0; i < n_samples; i++)   {
    Sensor_voltage = analogRead(solar_current_in) * (5.0 / 1023.0);
    current = current + (Sensor_voltage - 2.51503) / current_factor;
  }
  current = current / n_samples;
  if (current < 0) {
    current = 0;
  }
  return (current);
}
float in_voltage(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void setup() {
  Serial.begin(9600);
  pinMode(rele8, OUTPUT);
  pinMode(rele9, OUTPUT);
  pinMode(rele10, OUTPUT);
  pinMode(rele11, OUTPUT);
  pinMode(solar_voltage_in, INPUT);
  pinMode(solar_current_in, INPUT);
  pinMode(battery_voltage_in, INPUT);
  pinMode(PWM_out, OUTPUT);
  digitalWrite(PWM_out, LOW);
  pinMode(load_enable, OUTPUT);
  digitalWrite(load_enable, LOW);
  Serial.begin(9600);
  before_millis = millis();
}
void loop() {
  if (millis() - tiempolecturas > 3000UL) {
    if (Current > 0.100) {
      digitalWrite(rele8, HIGH);
    }
    if (Current < 0.300) {
      digitalWrite(rele8, LOW);
    }
    solar_voltage = get_solar_voltage(15);
    bat_voltage   = get_battery_voltage(15);
    solar_current = get_solar_current(15);
    solar_power = bat_voltage * solar_current;
    pwm_percentage = map(pwm_value, 0, 255, 0, 100);
    now_millis = millis();
    if (now_millis - before_millis > LCD_refresh_rate)  {
      before_millis = now_millis;
      Serial.println("Volt. Fuente");
      Serial.println(solar_voltage, 3);
      Serial.println("Volt. Bateria");
      Serial.println(bat_voltage, 3);
      Serial.println("pwm");
      Serial.println(pwm_percentage);
      Serial.println("Bat. AMP");
      Serial.println(solar_current, 3);
      Serial.println(load_status);
    }
    if (bat_voltage < battery_min_voltage) {
      digitalWrite(load_enable, LOW);
      load_status  = "OFF";
    }
    else {
      digitalWrite(load_enable, HIGH);
      load_status  = "ON";
    }
    // BATERIA 1
    leoBateria(0);
    // BATERIA 2
    leoBateria(1);
    // BATERIA 3
    leoBateria(2);

    /////   FLOAT       /////////
    if (mode == FLOAT) {
      if (bat_voltage < float_voltage_min) {
        mode = BULK;
        mode_str = "BULK";
      }
      else {
        if (solar_current > float_max_current) {
          mode = BULK;
          mode_str = "BULK";
        }
        else {
          if (bat_voltage > float_voltage) {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
        }
        analogWrite(PWM_out, pwm_value);
      }
    }
    else {
      if (bat_voltage < bulk_voltage_min) {
        mode = BULK;
        mode_str = "BULK";
      }
      else if (bat_voltage > bulk_voltage_max) {
        mode_str = "ABSORPTION";
        mode = ABSORPTION;
      }

      /////////   BULK    ////////////
      if (mode == BULK) {
        if (solar_current > charging_current) {
          pwm_value--;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        else {
          pwm_value++;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        analogWrite(PWM_out, pwm_value);
      }
      ////////  ABSORPTION  ///////
      if (mode == ABSORPTION) {
        if (solar_current > absorption_max_current) {
          pwm_value--;
          pwm_value = constrain(pwm_value, 0, 255);
        }
        else {
          if (bat_voltage > absorption_voltage) {
            pwm_value++;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          else {
            pwm_value--;
            pwm_value = constrain(pwm_value, 0, 255);
          }
          if (solar_current < absorption_min_current) {
            mode = FLOAT;
            mode_str = "FLOAT";
          }
        }
        analogWrite(PWM_out, pwm_value);
      }
    }
    for (int i = 0; i < 3; i++) {
      Serial.println("sensor " + String(i) + " ");
   // Serial.print(bateria[i].adc_voltage, 3);
      Serial.print(bateria[i].in_voltage,  3);
      Serial.println(" V");
    }
    tiempolecturas = millis();
  }
}

Saludos.