Hi,
I hope you have a great day
It is possible to give 3 months delay using ''Delay( )'' function
e.g Delay(466560000000)
delay() takes an unsigned long for the parameter. What do you think the largest number an unsigned long can hold is?
Of course there's nothing stopping you doing one delay() followed by another and so on. But why?
Steve
Moinh:
Hi,
I hope you have a great day
It is possible to give 3 months delay using ''Delay( )'' function
e.g Delay(466560000000)
delay() takes an unsigned long int as its parameter so the mixumum possible delay() is just over 49 days. However, it would be unusual to use such a long period and using a Real Time Clock (RTC) would be more normal
What is the application ?
Precision aside, whilst the max delay is ~49 days, nothing prevents you from doing multiple delays in a row
const unsigned long thirtyDays = 30ul * 24ul * 60ul * 60ul * 1000ul;
...
delay(thirtyDays); // wait for 30 days
delay(thirtyDays); // wait for 30 days
delay(thirtyDays); // wait for 30 days
// here we waited for 90 days (roughly - Arduino's clock precision dependant)
...
EDIT: Ooops, that was already suggested by @slipstick
Moinh:
e.g Delay(466560000000)
You seem to have an extra ×60 there; that is 5400 days, almost 15 years.
Either with delay() or with millis(), it is possible to count the days.
// With delay()
const unsigned long oneDay = 1000UL * 60UL * 60UL * 24UL;
void setup()
{
Serial.begin( 9600);
Serial.println( "See you again in 100 days");
waitDays( 100);
Serial.println( "Hello");
}
void loop()
{
}
void waitDays( unsigned int days)
{
for( unsigned int d=0; d<days; d++)
{
delay( oneDay);
}
}
// With millis()
const unsigned long oneDay = 1000UL * 60UL * 60UL * 24UL;
unsigned long previousMillis = 0;
unsigned int dayCounter = 0;
void setup()
{
Serial.begin( 9600);
Serial.println( "I will say hello every 100 days");
}
void loop()
{
unsigned long currentMillis = millis();
if( currentMillis - previousMillis >= oneDay)
{
previousMillis = currentMillis;
dayCounter++;
if( dayCounter == 100)
{
Serial.println( "Hello");
dayCounter = 0;
}
}
}
I have seen this question before recently (here). A RTC (Real Time Clock) is better. With a RTC it is possible to do something every first day of the month, or only in the summer.
UKHeliBob:
delay() takes an unsigned long int as its parameter so the mixumum possible delay() is just over 49 days. However, it would be unusual to use such a long period and using a Real Time Clock (RTC) would be more normalWhat is the application ?
UKHeliBob:
delay() takes an unsigned long int as its parameter so the mixumum possible delay() is just over 49 days. However, it would be unusual to use such a long period and using a Real Time Clock (RTC) would be more normalWhat is the application ?
I have to design a system which alerts me after 3 months to service that system.
If you lose power sometime in that three months, the Arduino will start counting again from zero. Better to use a clock module and store the start time in EEPROM.
Don’t you have a smartphone - create a reminder...
Use any on line or local agenda for your service operations on your computer....
Not sure you need an arduino for this...
Is the Arduino doing anything else in the system ?
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.