start an event on sundays at noon

hello all

I would like to do a water change on my aquarium system on Sundays at noon.

This event would have to turn off 3 pumps and allow time for the display tanks to drain down into my sump/filtration tank after pumps are off.

this part can be accomplished by using a timer or with input from float switches or ultrasonic sensors i have in place

Once the system has finished draining start a pump to drain out water to the house sewage system until a float switch is activated,at which point turning off the drain pump and turning on the refill pump.

When the water is back to the needed level

IE the level the water is at when the display pumps are turned off and the water drains from them to the sump tank

at which point turn off the refill pump and turn the display pumps back on.

I have found this code

unsigned long currentMillis;
unsigned long previousMillis;
unsigned long elapsedTime;
unsigned long duration = 3600000UL; // one hour
relayControl = 2; 

void setup(){
// whatever
pinMode (relayControl, OUTPUT);
digitalWrite (relayControl, LOW); // assume a HIGH will drive NPN base to pull relay coil low

previousMillis = millis();
}

void loop(){
currentTime = millis();  // capture current "time"
elapsedTime = currentTime - previousTime;  // how much has gone by?
if (elapsedTime >=duration){  // if more than 1 hour
previousTime = previousTime + duration;  // set up for next hour
hourCount = hourCount +1;  // increment hour count
if (hourCount == 120){  // days = hours 0-23, 24-47, 48-71, 72-95, 96-119
hourCount = 0;  // reset after 5 days
}
if ( (hourCount >=0) &  (hourCount <3) ){   // turn on relay for hours 0,1,2
digitalWrite(relayControl, HIGH);
}
else {
digitalWrite (relayControl, LOW);
}

} // end time interval check

} // end loop

which i think is what i need to use to accomplish this but do not understand how to make it work were the event will happen on a Sunday at noon

if someone could explain how to do that or suggest a more appropriate way of doing this i would be extremely thankful
James

if someone could explain how to do that

How does your Arduino know what time it is? How does it know what date it is?

The usual three ways are:
Get the date and time from a PC. This requires code running on the PC that can talk to the Arduino.
Get the date and time from an NTP server. This requires an Ethernet shield.
Get the date and time from an RTC (real time clock) - that's external hardware.

for using a rtc imho cheapest and easiest solution if you dont have a tethered pc or web enabled board/shield
have a look at this rtc example

the internal count of seconds has some error and after multiple 7 day periods will be significant.

hello all

I am using a DS1307 for an RTC and a Mega2560 for the controller on my aquarium

I am using a DS1307 for an RTC and a Mega2560 for the controller on my aquarium

So, what's the problem? Can you get time from the RTC? If so, can you figure out how to determine the day of the week?

sounds like you want to stitch the code from the first post with a RTC example sketch,a buttons example sketch, and a lcd example sketch, and switch your 6 relays,

Have a go, and when you hit a stonewall post the problem, you can switch 6 relays with a single GPIO Pin so, if you get the code working switching on a led,you will have broken the projects back and to complete all you need is to add the appropriate h/w circuit to the led pin.