Help with the Delay() function

I need a Delay that can last for 20 minutes
is it possible for arduino to make a 20 minute delay
ps: i don't want to use blink without delay I don't need anything to happen during the 20 minutes
i just want to know if i can write delay(1200000) ;

So do that. Nothing will top you to do that :slight_smile:

i just want to know if i can write delay(1200000) ;

It would take a maximum of about 20 minutes to test that

Read these:
delay() delay() - Arduino Reference

unsigned long unsigned long - Arduino Reference

MohamedAmr:
i just want to know if i can write delay(1200000) ;

The answer about whether it will works as you expect is: "It depends".
Naked constants like that are integers. The number of bits used to represent integers can vary depending on the processor.
On an AVR they are 16 bits
On nearly all the other Arduino processors they are 32 bits.

16 bits can not represent a number that large so it would not work as expected "as is" on an AVR based Arduino but would work on say an esp8266 or chipkit pic32 based boards.

You could change it to include a qualifier suffix like:

delay(1200000UL) ;

which would tell the compiler to treat this as an unsigned long which is large enough to hold that value on all the processors.

--- bill

You could also do this:

const int oneSecond = 1000;
const int oneMinute = oneSecond * 60;


delay(oneMinute * 20);

For someone with the name Unsigned_Arduino, you're not really in the habit of using them :wink:

Ha... :slight_smile:

const int oneSecond = 1000;
const unsigned int  oneMinute = oneSecond * 60;
const long twentyMin = oneMinute * 20;


delay(twentyMin);

Unsigned_Arduino:
Ha... :slight_smile:

const int oneSecond = 1000;

const unsigned int  oneMinute = oneSecond * 60;
const long twentyMin = oneMinute * 20;

delay(twentyMin);

Don't be surprised if your delay lasts a bit more than 20 seconds. :slight_smile:

unsigned long time = 1000 * 60 * 20;

delay(time);

Back to square one... or #5.

Unsigned_Arduino:

unsigned long time = 1000 * 60 * 20;

delay(time);

I think what you're missing is that all calculations will be done as int (signed 16-bit values), and then the value will be promoted to long after it has already overflowed what an int can hold. You have to calculate a "big" number using long values in the calculation.

Than...

unsigned long twentyMinutes = 1200000;

delay (twentyMinutes);
unsigned long twentyMinutes = 1200000;

Yep, that will work. Because "1200000" is "obviously bigger than an int.)
If you don't want to worry about it, you can just do:

#define ONESEC 1000UL
#define ONEMIN (60*ONESEC)
#define ONEHOUR (60*ONEMIN)

  delay(20*ONEMIN);
  delay(ONEHOUR/2);
  delay(10*ONESEC);

MohamedAmr:
I need a Delay that can last for 20 minutes
is it possible for arduino to make a 20 minute delay
ps: i don't want to use blink without delay I don't need anything to happen during the 20 minutes
i just want to know if i can write delay(1200000) ;

I have no idea at all why the OP is coming to the forum to ask this. I'm lost - why didn't he just try it and see? I mean it in complete seriousness: Mohammed, dude, why did you not simply try it and find out if it would work? Why not do this? Because I just don't understand why someone wouldn't. I could suggest a few reasons, but they would all sound insulting and that's against forum rules.

It's a strange epistemology, this idea that the only place to get facts from is from some external authority. You have an arduino? You have the IDE? You have a clock? Why wouldn't you just try it out?

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1200000);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {}

Delta_G:
What's even stranger is the amount of authority they ascribe to us. We've got people on the forum asking about the medical effects on the human body of things that they want to do with their Arduino. Or about whether something they want to do is legal or not. Like if the question involves the Arduino in even the remotest of ways that someone here would be the final authority on the subject.

I think it has just been lost on kids these days, the sense God gave the Goose.

I was insulted by a Millennial the other day: "You Baby Boomers just use your work ethic to get all the good jobs."