We are using a MEGA2560 to control some farming equipment and a 400lb Linear actuator that is driven via 12V switching relays. The entire unit is powered by a 12V battery, where the A1 Port is measuring the voltage via a voltage divider (510KOhm and 1.1MOhm), and converting it to a "battery remaining" time in hours. Anything less than 11.5V is considered "dead" because it won't have enough juice to drive the rest of the system. The linear actuator is controlled by two 12VDC Relays that control "on/off" and "fwd/rev", and the actuator has an encoder system that is fed back to the Arduino to calculate the distance that the actuator is extended. The actuator is controlled by a potentiometer. The issue that is popping up is that even when both relays are "off", the ADC read of the battery goes to "0 hours remaining". If the system is in idle, it prints the battery correctly. I wrote some pseudocode because the real code for this is astronomically long:
void loop() {
if(run_switch is OFF){ //IDLE mode
retract linear actuator if it is extended;
read battery ADC;
Print to LCD;
other stuff;
}
else{ //RUN mode
while(potentiometer is moving){
calculate distance setting of linear actuator;
//We'll refer to this as "setting" (3 inchs, 5 inches, etc)
}
read linear actuator distace;
//we'll call this "distance" (3 inchs, 5 inches, etc)
if(distance > setting + hysteresis){ //retract
fwd/rev relay = ON;
on/off relay = OFF;
}
else if(distance > setting - hysteresis){ //extend
fwd/rev relay = ON;
on/off relay = ON;
}
else{ //off and read battery
fwd/rev relay = OFF;
on/off relay = OFF;
read battery ADC; //this is where it reads 0 hrs remaining
Print to LCD;
other stuff;
}
}
}
Any Idea as to why the second half of the code keeps reading a low battery voltage? Any help would be appreciated.