Relay Timer, Voltage Display, Feasible??

I have an idea for a use of the Arduino but before i get to buying parts i was wondering if this is feasible...

Currently i have an Arduino UNO running a 20x4 LCD display and i have been using that to learn things on it as well as make one useful project but now i have a real good design need i want to try to meet.

Here is the setup... I have a deep cycle marine battery thats used as a DC backup supply for radio equipment, the battery is directly connected to a Iota DLS-55 power supply with the IQ4 smart charger module. It maintains the battery, runs it through charging cycles to check the battery etc. But i want to go one step further. I would like to be able to have a timer set to do a weekly battery test. For example i would set it to 168 hours and count down, that would be every seven days, when the timer hits zero it shuts off a relay output, i read through the good info on controlling a relay with the Arduino and thats easy enough to build, i just don't know how to implement the countdown timer to provide this function, but wait there is more!

On top of that i want it to also monitor the battery voltage, this is where it gets complicated.... I want it to monitor the voltage, and when it hits a preset voltage, lets say 11.9v, it then turns the relay back on reconnecting the power supply to charge the battery and supply power to everything. And if possible i would like to keep the LCD display and have it display the voltage its reading at all times and also show the countdown time remaining.

Now... Is all this possible??

It would make my life simpler, the Arduino would cycle the battery weekly and i wouldn't have to go flip a switch and then continue to monitor the voltage, it can take anywhere from 8-10 hours depending on how much stuff i left on for the battery to drop down to the point i set to have it reconnected, so it needs to leave it disconnected until that set point is reached. Seems like a lot but there is controllers that can do this, although beyond my budget.

The Arduino has an internal counter that counts in milliseconds, so your weekly timer would look something like this:

void setup{
startTime = millis(); //set startTime to time NOW
}

void loop{
if (millis() - startTime >= (168 * 60 * 60 * 1000){
  //week ended, do something
  startTime = millis(); //reset start for next week
}

To display time remaining at any time:

remainder = (168 * 60 * 60 * 1000) - (millis() - startTime);
serial.print ("Time remaining in seconds = ");
serial.println (remainder/1000);

If you want it in hours/mins/seconds, you do the maths. :)

Thank you i will start playing around with that its a good start!

if (millis() - startTime >= (168 * 60 * 60 * 1000){

168 * 60 * 60 * 1000 will be computed using int arithmetic, since all values are ints. The result will overflow an int. On the other hand, with

if (millis() - startTime >= (168 * 60 * 60 * 1000UL){

168 * 60 * 60 * 1000UL will be computed using long arithmetic, since at least one of the values is a long. The result will not overflow an unsigned long.

Just something to keep in mind...

If you used 168 hours count down for a weekly battery test, I suggest you use a RTC like DS1307. This will more foolproof, for example if running 6 days and you have power failure to your Arduino and after restart, your test will happen another 7 days later.

PaulS: if (millis() - startTime >= (168 * 60 * 60 * 1000){

168 * 60 * 60 * 1000 will be computed using int arithmetic, since all values are ints. The result will overflow an int. On the other hand, with

if (millis() - startTime >= (168 * 60 * 60 * 1000UL){

168 * 60 * 60 * 1000UL will be computed using long arithmetic, since at least one of the values is a long. The result will not overflow an unsigned long.

Just something to keep in mind...

Or he could declare 'week' as a const unsigned long = (168 * 60 * 60 * 1000) and use week in his calculations. That way, it would only have to be calculated once.