Solar panel and wind turbine connected to battery with arduino volatge read

Hi

I am hoping someone can give me some advice on an issue I am having, there is a solar panel and a wind turbine connected to a charging circuit to a battery, which works fine. The issue I am having is I created an Arduino circuit to read the voltage which is also connected to the battery. this Arduino will turn a device on that requires 12v 1.5A, so far it will turn the device off when it gets to voltage below 10.2V then turn back on if it reaches 13.4V. The problem is the Arduino won’t turn the device on or will turn off after a while, then won’t come back on (kind of like it has frozen). The Arduino has a voltage divider a 10K resistor and a 100K.

Below is my code. I am hoping someone can help me with this issue may it be my code or the fact that a solar panel and wind turbine connected to a battery then to measure it, is the issue

below i also have an attachment to my circuit diagram.

wiring : solar panel and wind turbine >> charging unit >> battery >> connected to my arduino

code:

int led_output = 13;
int analogInput = 0;
int VoltageOut  = 5;

////////////////////////////first//////////////////////////
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!
int value = 0;
int batteryflag;

//10.2 off
//13.4 on
////////////////////////////end first//////////////////////

unsigned long previousMillis = 0;
unsigned long interval = (unsigned long) 1000 * 60 * 60 * 1;

void setup() {
  Serial.begin(9600);
  pinMode(analogInput, INPUT);
  pinMode(led_output, OUTPUT);
  pinMode(VoltageOut, OUTPUT);
  digitalWrite(led_output, HIGH);
digitalWrite(VoltageOut, HIGH);
}

void softReset() {
  asm volatile ("  jmp 0");

}


void loop() {



  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
      digitalWrite(led_output, HIGH);
    delay(1000);
    Serial.println("RESET");
    delay(1000);
    softReset();
  }

  else{

digitalWrite(led_output, LOW);
  value = analogRead(analogInput);
  vout = (value * 5.0) / 1024.0; // see text
  vin = vout / (R2 / (R1 + R2));
  if (vin < 0.09) {
    vin = 0.0; //statement to quash undesired reading !
  }
  delay(500);



  if (vin <= 10.22) {
    
    digitalWrite(VoltageOut, LOW);
  }



  if (vin >= 13.04) {
  
     digitalWrite(VoltageOut, HIGH);

  }

  Serial.println(vin);
  }
}

Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks for using code tags... Tom... :slight_smile:

TomGeorge:
Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks for using code tags... Tom... :slight_smile:

Hi Tom as requested i have attached an image of my circuit diagram

Hi,
Thanks.OPs circuit;


Tom.. :slight_smile:

What does the Serial.print show You?

Hi,
Can you post a complete circuit diagram, including your batteries, wind turbine and solar panels as well as any charge controllers that may be in the system.

Have you got a variable power supply to test your controller response ?

You should be measuring your Vin as the first line in your loop, not inside a conditional statement.
In other words you need to take a snapshot of your inputs FIRST then act apon them.

What is "softreset"?

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,
Can you post a complete circuit diagram, including your batteries, wind turbine and solar panels as well as any charge controllers that may be in the system.

Have you got a variable power supply to test your controller response ?

You should be measuring your Vin as the first line in your loop, not inside a conditional statement.
In other words you need to take a snapshot of your inputs FIRST then act apon them.

What is "softreset"?

Thanks.. Tom.. :slight_smile:

Hi Tom
I can’t post a complete circuit, as I am not the one that installed it. I do know there is a solar panel and a wind turbine connected to a charger which controls the load to the device at the same time it charges them, which then is connect to a 12v battery. The whole set up already has a voltage monitoring device which I made however that one isn’t working, so I am designing a new one which would. The device is far away and has a 3G router in it which we can ping, the thing is the first one I made which is already in there isn’t powering the device up, so I believe that it isn’t working, as I cannot ping it.

I have been using a bench power supply and adjusting the voltage up and down to match the required threshold to turn the device on and off. Again when I first made it and tested it, it was working perfectly with the bench power supply, and then when it was installed it stopped working.

Oh the softreset is to rest the Arduino as I thought maybe the issue with the first one is that it is frozen and unresponsive, so I thought resetting it every hour might help fix that bug.

I saw your comment on using a op amp and was wondering if this one would be ideal to use MCP6041/2/4

I have also added to the code to do the avarges which i will paste below

Thank you

code :

int led_output = 13;
int analogInput = 0;
int VoltageOut  = 5;

////////////////////////////first//////////////////////////
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!
int value = 0;
int batteryflag;

//10.2 off
//13.4 on
////////////////////////////end first//////////////////////


//////////////////////////averages///////////////////////
const int numReadings = 64;

double readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
double total = 0;                  // the running total
double average = 0;                // the average

////////////////////////end averages/////////////////////

unsigned long previousMillis = 0;
unsigned long interval = (unsigned long) 1000 * 60 * 60 * 1;

void setup() {
  Serial.begin(9600);
  pinMode(analogInput, INPUT);
  pinMode(led_output, OUTPUT);
  pinMode(VoltageOut, OUTPUT);
  digitalWrite(led_output, HIGH);
digitalWrite(VoltageOut, HIGH);

////////////////////////////////////////////////////////
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }

///////////////////////////////////////////////////////
}

void softReset() {
  asm volatile ("  jmp 0");

}


void loop() {



  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
      digitalWrite(led_output, HIGH);
    delay(1000);
    Serial.println("RESET");
    delay(1000);
    softReset();
  }

  else{

digitalWrite(led_output, LOW);

 ///////////////////////////////////////////////////
 

  total = total - readings[readIndex];

///////////////////////////////////////////////////////


  value = analogRead(analogInput);
  vout = (value * 5.0) / 1024.0; // see text
  vin = vout / (R2 / (R1 + R2));
  if (vin < 0.09) {
    vin = 0.0; //statement to quash undesired reading !
  }
  // delay(500);

  
  ///////////////////////////////////////////////////
 
 readings[readIndex] = vin;
  total = total + readings[readIndex];
   readIndex = readIndex + 1;

  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }

   average = total / numReadings;

   Serial.println(average);


if (vin <= 10.58) {
    
    digitalWrite(VoltageOut, LOW);
  }


  if (vin >= 13.04) {
  
     digitalWrite(VoltageOut, HIGH);

  }

   
   delay(1);
///////////////////////////////////////////////////////





  //if (vin <= 10.43) {
    
   // digitalWrite(VoltageOut, LOW);
  //}



  //if (vin >= 13.04) {
  
    // digitalWrite(VoltageOut, HIGH);

  //}

  //Serial.println(vin);
  }
}

Serial Output:

Starts out at 12.03 - 12.04V then 
after a few mintues it changes to 12.40 - 12.30V
which i believe is just the device powering up

Hi,
If you are powering the control circuit off the LM7805, what is the input voltage to the LM7805?

Is the LM7805 bolted to a heatsink?
Can you measure the 5V output when your controller goes into fault mode?

Have you got ALL the gnd connections, including the potential divider and power supply ALL connected to one point?

Can you program and fit to your controller a blinking LED, use this as the heartbeat of the controller so you know if it has locked up or not.
Just the "Blink without delay" at the start of your loop will do the job.

Can you post a picture of your controller and/or your PCB layout?

Tom.... :slight_smile: