best method of switch on output for set time ?

Hey all

Just not sure what the best way to go about this ... I want to switch on a water pump and have it running for a 1 hour and then switch it off .

im fine with the control side , just not sure about the timing !

Is using "millis()" or is it better to use an external realtime clock circuit. It doesnt need to be exact roughly 1 hr give or take 10 mins .

also if i uses millis() how will i get over it reseting to 0 after 50days ect or wont this apply ?.

Any help would be great

cheers luke

also if i uses millis() how will i get over it reseting to 0 after 50days

This will wait for an hour even when millis overflows its unsigned long variable:

unsigned long time = millis() + 3600*1000;
do {} while (millis() != time);

This approach is fine, if you want the Arduino to do nothing for that one hour. If you want it to do other things, checking for equality as the means of moving on is not really a good idea.

Other processing in between calls to millis could cause it to return values like 1, 2, 3, 5, 6, 7, 9, etc., instead of 1, 2, 3, 4, 5, 6, 7. If you are looking for millis() to return some specific value, and that is one that it does not return, because that specific time occurred while the Arduino wasn't looking, you'd have to wait ~50 days for that time to occur again.

If you are expecting the Arduino to do nothing while waiting, you might as well call delay() to wait for that hour to go by.