run a code once every 24 hrs

i am new to Arduino programming and I need help

I have to run a code once every 24 hrs, that is 86400000 milliseconds..
I also have 5 second delays, 2.5 second delays and one second delays which I think will affect the accuracy of the milliseconds

how should I solve this problem??

Let's see some code. Are you using millis() for timing or delay() ?

I use delay() for timing

actually, no. I tried a lot of methods . . none of them worked . so I deleted some of that code and asked for help..... I did not know how to delay hours or days....

Time to switch to millis() I think.

Look at the BlinkWithoutDelay example to see how to do it.

What happened to

UKHeliBob:
Let's see some code.

??

Keep in mind, the clock of the Arduino isn't mega stable. For timing a couple of minutes not a problem. Even for a single 24h not a big deal. But it can have seconds of tens of seconds error per 24h which will accumulate over the days.

thank you, the Blink without Delay example code really helped .

The BWOD example has only one "delay" period and one event triggered when the period is up. You can, of course, have many periods each with their own start time and it is often convenient to hold this data in arrays and iterate through the arrays to determine if a timing period has ended rather than writing code to check each one individually.

I hope that it goes without saying that the events triggered at the end of the timing periods must themselves be non blocking and allow loop() to run freely.

Sometimes delay() is all you need.

delay(1) ;
count = count +1 ;

if ( count >= 86400000 ) {
count = 0 ;
// do that thing you want to do
}

the problem is that every processor and loop delay in your program adds up and I would bet dollars to donuts that you would be way off over that long of a period.

but as a simple count the 1ms delay is not a concern for a short program.

I have a button and a relay, press the button once and the lights come on for 30 minutes in the warehouse. twice and they are on for an hour. each button press adds 30 minutes. press and hold = 3 minutes. No one will ever use a watch to see how accurate that is and the unit does nothing else.

blink without delay is much preferred due to the accuracy and that simple fact that even delay(1) runs your high speed processor at a crawl.

Sometimes delay() is all you need.

Except when you want to do some other timing during the 24 hour period, which is what the OP implies, but we are short of details.

An array of 4 start times, an array of 4 periods and a little bit of BWOD sounds like it would do what the OP wants. I await with interest more details of what happens at the end of each timing period.

Use of the delay() function will not affect BWOD timing, except that if one coincides with a BWOD event, it will postpone the BWOD event. In other words, it would be safe to use many short delay()'s in a loop() function, because they won't affect the accuracy of a long term BWOD event. In that case, the delay()'s do not add up. The worst case error is the possibility of a delay() beginning just prior to a BWOD event and the error will be no longer than the delay().

dave-in-nj:
Sometimes delay() is all you need.

delay(1) ;
count = count +1 ;

millis() does exactly the same thing as your counter, only without any of the errors you suggested. Why re-invent the triangular wheel? "One less bump than square wheels!"

MorganS:
millis() does exactly the same thing as your counter, only without any of the errors you suggested. Why re-invent the triangular wheel? "One less bump than square wheels!"

you use that word 'exactly' I am thinking that it does not mean what you think it means...... (horrible mimic of Inigo Montoya from A Princess Bride)
yes they are similar,
I submit that if accuracy is not key, you can use delay() for simplicity in writing and reading on simple programs. just another tool in the box.
I will offer that just because you can do a thing, does not mean that you should do a thing.