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);
}
}