I am trying to using millis() function to turn on/off relay after a certain amount of hours/mins to automate my hydro system.
Currently, it is not switching the relay at the correct time. Attached is the code, any suggestion on how to modify the code or a new method would be much appreciated.
wildbill:
Can you post the example with the hours delays in it?
unsigned long presentmillis = 0;
while(millis() - presentmillis != 86400000) //wait for 24 hrs = 24x60x60x1000 ms //you can wait for 49 days
{
; //you can do some other job during this waiting period
}
presentmillis = millis(); //update present time variable
Thank you all for the insight on both forum and the references for correcting the code. I will read over your reference and make the changes to the code and see if that solves the solution.. sounds like it will. I will keep the thread posted.
I would recommend you to use the DS3231 Real Time Clock which is very accurate. It works with an independent battery and has the option to create two alarms.
Which I recommend is to get the arduino into an sleep mode (you will save battery), with a previously set up alarm on the RTC. When the alarm fires the arduino will wake up and you could do your staff.