It is a low voltage disconnect but has an interesting feature that requires the "cutoff" and "reconnect" voltages to be reached for 10 seconds before the connection is actually cut/re-connected to prevent premature status changes from voltage spikes/sags (Such as starting a car, or a motor with high start draw)
I need some example code that handles the timer portion. I can handle the "if this voltage is reached, disconnect the relay" (or transistor in the link I provided) part.
I need help making it "If this voltage has reached XX for 10 seconds then -do something-"
I need some example code that handles the timer portion. I can handle the "if this voltage is reached, disconnect the relay" (or transistor in the link I provided) part.
If you can handle the "if this voltage is reached, disconnect the relay" part, you could also handle the "if this voltage is reached, record when that happened, using millis()" part.
Is it necessary for the voltage to be at that level for 10 seconds? What is to happen if the voltage drops below that level in the 10 second window after it first exceeds the threshold?
Let's say we want to disconnect at 11 volts. Your battery is at 12 volts. Everything is fine. You have a large motor that you start on your circuit that takes 1 or 2 seconds to get going. This is a high current draw and will likely lower the voltage to below 11 volts triggering the device... But after the motor is running, the voltage will return to a normal level, above 11 volts.
So the idea is that the voltage needs to be below 11 volts for 10 seconds before it shuts off.
So the idea is that the voltage needs to be below 11 volts for 10 seconds before it shuts off.
So, you can determine that this reading is above, or below, the threshold. You can determine whether the previous reading is above, or below, the threshold. If this reading is above and the previous read is above, no change occurred. If the current reading is below and the previous reading is below, no changed occurred.
If the current reading is above and the previous reading is below, the voltage is increasing, which is good (right?). So, clear the voltage dropped below the threshold time.
If the current reading is below and the previous reading is above, the voltage is dropping, and you need to record when that happens.
Separately, you need to compare the current value to the threshold, and the current time to the voltage dropped below the threshold time. If the voltage is below the threshold, and the interval between now and then is greater than the allowable time, panic. Run in circles, scream and shout. Or something like that.