I want to create a 30 minutes delay in my program (Arduino).

which is better millis() or timer for this purpose?

please give me an example to clarify my doubt ...



1 Answer 1


It depends on your need:

1. No other activities / main power

If during those 30 minutes (I guess), the MCU does not have to do anything else (except maybe handling some short interrupts), than you can use a delay. You can use this if your power source is an adapter, but you waste a lot.

  • Advantage: Easy to program
  • Disadvantage: Power will continue to be used.

2. No other activities / battery

If you have the same conditions as above, but using a battery, than as Juraj mention, use the sleep functionality of the Arduino. You need an (external) real time clock or other circuitry to activate the wakeup signal after 30 minutes.

  • Advantage: Very less power used during the 30 minute delay
  • Disadvantage: Slightly more programming

3. Other activities

If you want to do now (or later) other code to be executed during the 30 minute wait, use millis(). For example, when you want to extend your project using other libraries that needs a faster than 30 minute response.

  • Advantage: You can do other tasks meanwhile
  • Disadvantage: More power usage, slightly more programming
  • 2
    2) esp8266 has built-in RTC with deep sleep wake-up option
    – Juraj
    Jul 19, 2019 at 12:31
  • 1
    3) for example blink a LED to show that it is alive
    – Juraj
    Jul 19, 2019 at 12:32
  • 1
    1) interrupts to keep the WiFi connected
    – Juraj
    Jul 19, 2019 at 12:33
  • @Juraj thanks for the extra comments .. offtopic:. btw congratulations with your 10K reputation. I removed my other answer so you don't need to downvote it anymore). Jul 19, 2019 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.