How to randomly hold for 5-30 minutes?

I want an LED to blink once but at random intervals of time that are between 5 and 30 minutes long.

For example: LED blinks, wait 18 minutes, LED blinks, wait 29 minutes, LED blinks, wait 7 minutes, etc.

What would be the best way to write this sketch on an Arduino Uno?

Appreciate any help or advice you can offer!

unsigned long millis_between_blinks = 60UL*random(5,31)*1000;

1 Like

Fingers work really well. Just kidding. Have you tried the Blink sketch yet? You can modify it to do what you ask.

1 Like

For a more random randomness, prefix the above line with the following line (copied from the link)...

  // if analog input pin 0 is unconnected, random analog
  // noise will cause the call to randomSeed() to generate
  // different seed numbers each time the sketch runs.
  // randomSeed() will then shuffle the random function.
  randomSeed(analogRead(0));

The randomSeed() function should be called only once in a program, since it merely defines the start point of the (fixed) pseudorandom sequence of numbers produced by random().

1 Like

YES! this is great

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.