how can i write a timer to switch thing on?

i have a DS1307 chip with my arduino. and three led blue, yellow and red.

i would like to do something like this

12:00 turn on red 17:00 turn on yellow 20:00 turn on blue

i know i have to turn the ds1307 now.hour * 60 + now.minute to current_time_by_minutes to compare the specify time to turn on which LED.

can someone tell me what should in the if statement to compare the current_time_by_minutes and let the program know which time to turn on which led ?

can someone tell me what should in the if statement to compare the current_time_by_minutes and let
the program know which time to turn on which led ?

12:00 is either 0 minutes after midnight or 720 minutes after. The other times being greater than 12:00, I’ll assume that you mean midnight.

if(current_time_by_minutes == 0)
{
   // Use digitalWrite() to turn on a pin
}
else if(current_time_by_minutes == 17*60UL)
{
   // Turn on a different pin
}
else if(current_time_by_minutes == 20*60UL)
{
   // Turn on the third pin
}

I have no idea which pins you have which LED connected to, or when you want to turn them off, so you’ll need to add that code.

hi Paul, thank for your help.

but i don’t think it is suit for my situation.

actually there is another menu in the program to set which time should turn on which thing.

User might set something like 23:00 to 1:00 and turn on something .Also my program have more than
three stage of time setting.

for example

12:30 turn on yellow led (from 12:30 to 17:29 yellow led on)
17:30 turn on red led (from 17:30 to 21:59 red led on)
22:00 turn on green led (from 22:00 to 12:29 green led on)

so what should i put in the if statement to make this work?

so what should i put in the if statement to make this work?

If this is correct:

12:30 turn on yellow led (from 12:30 to 17:29 yellow led on)

Then:

if(current_time_by_minutes >= (12*60UL + 30UL) && current_time_by_minutes < (17*60UL + 30UL))
{
   digitalWrite(yellowPin, HIGH);
}
else
{
   digitalWrite(yellowPin, LOW);
}

Have another if/else statement, with different times and pin number for the red LED and another one for the green LED.

What about user set something like 23:00 to 1:00 ?

it seem the if statement not working with something like this

Also what is UL ?

Unsigned Long. To force the compiler to use large enough intermediate values during calculation.

Personally, I'd keep hours and minutes separate, and not use current_time_by_minutes.

  current_time_by_minutes = (now.hour() * 60) + now.minute();

  if (stage_time_hour[1] * 60 + stage_time_min[1] >= current_time_by_minutes && stage_time_hour[2] * 60 + stage_time_min[2] < current_time_by_minutes) {
    current_stage = 1;
  }
  if (stage_time_hour[2] * 60 + stage_time_min[2] >= current_time_by_minutes && stage_time_hour[3] * 60 + stage_time_min[3] < current_time_by_minutes) {
    current_stage = 2;
  }
  if (stage_time_hour[3] * 60 + stage_time_min[3] >= current_time_by_minutes && stage_time_hour[4] * 60 + stage_time_min[4] < current_time_by_minutes) {
    current_stage = 3;
  }
  if (stage_time_hour[4] * 60 + stage_time_min[4] >= current_time_by_minutes && stage_time_hour[5] * 60 + stage_time_min[5] < current_time_by_minutes) {
    current_stage = 4;
  }
  if (stage_time_hour[5] * 60 + stage_time_min[5] >= current_time_by_minutes && stage_time_hour[6] * 60 + stage_time_min[6] < current_time_by_minutes) {
    current_stage = 5;
  }
  if (stage_time_hour[6] * 60 + stage_time_min[6] >= current_time_by_minutes && stage_time_hour[1] * 60 + stage_time_min[1] < current_time_by_minutes) {
    current_stage = 6;
  }

I have something like this and it doen’t work

I have something like this and it doen't work

It does something. You want it to do something. What either of those things is is a complete mystery, though. Can't help you with so little information.

if(current_time_by_minutes >= (12*60UL + 30UL) && current_time_by_minutes < (17*60UL + 30UL))
{
   digitalWrite(yellowPin, HIGH);
}
else
{
   digitalWrite(yellowPin, LOW);
}

Have another if/else statement, with different times and pin number for the red LED and another one for the green LED.
[/quote]

i try this one it is seem working but if the time is between 23:00 to 0:00 or 23:00 to 1:00.
it doesn’t work properly

but if the time is between 23:00 to 0:00 or 23:00 to 1:00. it doesn't work properly

Because the end time is a different day. When the end time is not on the same day, you need to add 24 to the end hour value when determining the minutes since midnight.

thank you everyone.i did it.

just make a if statement to determine if the end time is less than begin time, then +1440 to end time.

and use the begin time and end time to compare is it in between them.