Go Down

Topic: Timed action help (Read 842 times) previous topic - next topic


Hey guys,

I'm new to the Arduino scene, is this a correct way to create a long delay or is there a better way?

I need to run this code 10 hours from now so in my void setup() I have delay(36000000); 

is this ok way to do this or is this bad for my arduino?

Jack Christensen

That is OK, it will not harm anything. There are other ways. The downside to using delay() is that while delay is doing its thing, nothing else can happen. So if there is nothing else to do, then delay is ok. For another way, see File > Examples > 02.Digital > BlinkWithoutDelay. Also search the forum for "BlinkWithoutDelay" and you'll probably find more discussion on the topic than you can enjoy! ;)


ok perfect, yeah in this case nothing else needs to happen during the delay.

I will check out those links for the future!




Delay() will work, but you will be wasting a lot of power whilst your device is waiting to do it's task. That may mean a flat battery if battery powered. You could put your Arduino to sleep for much of the waiting time and save power.

See http://arduino.cc/playground/Learning/ArduinoSleepCode

and Nick Gammon's page http://www.gammon.com.au/forum/?id=11497

I managed to get current  down to a few uA in sleep using these techniques.


Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)


If you need accurate timing the sleep-mode watchdog timer isn't going to be good enough.  But a real-time clock module can give you that and the ability to remember the time across power cycles too.  For instance you could sleep for a minute or so at a time, wake up and check the RTC then either go back to sleep or perform the action.

There's probably something about this at the JeeLabs blog http://jeelabs.org/ (search box at bottom of page!)
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up