I need help for a coding

I found an interesting topic for my 1st arduino project.
http://mertarduinotutorial.blogspot.com/2017/09/arduino-turn-on-off-anything-at.html?m=1

Get the Code
#include <DS3231.h>

int Relay = 4;

DS3231 rtc(SDA, SCL);
Time t;

const int OnHour = 12;
const int OnMin = 24;
const int OffHour = 12;
const int OffMin = 25;

void setup() {
Serial.begin(115200);
rtc.begin();
pinMode(Relay, OUTPUT);
digitalWrite(Relay, LOW);
}

void loop() {
t = rtc.getTime();
Serial.print(t.hour);
Serial.print(" hour(s), “);
Serial.print(t.min);
Serial.print(” minute(s)");
Serial.println(" ");
delay (1000);

if(t.hour == OnHour && t.min == OnMin){
digitalWrite(Relay,HIGH);
Serial.println(“LIGHT ON”);
}

else if(t.hour == OffHour && t.min == OffMin){
digitalWrite(Relay,LOW);
Serial.println(“LIGHT OFF”);
}
}/td]

Using rct
But i want to change the code, on for 5-10min every hour. Start from 8am to 5pm then turnoff arduino at 5.10pm-7.59am well turnoff, delay, or stanby is ok.

Sorry i’m suck at programing and english

(deleted)

Using arduino, rct and relay, i want to turn on relay and off relay at spesifict time with power saving at idle time. Is it possible for this project?

Sorry it's my 1st project, i don't know how to coding, and i'll learning latter, need some times for study c++ programing, wihout programing background...

No time to start like now.
You have made a good start to learning by finding a similar project, now dissect it and study ‘why’ it does what it does.
There’s no shortcut.

Also - to help others help you, please read the sticky posts, and use

 tags when posting code.

Programming - and this forum - are unforgiving!

Ok. I think i can make the code with if else statment

As you become more proficient - it won’t change the way the existing code runs, but consider that your on and off cycles will run multiple times at the on ‘minute’ and off ‘minute’.
If you add more functionality in the future, this could become a problem, so when the time comes (no pun!): check out the ability to set your on and off state in a controlled manner so they only fire once at the scheduled times.

const int OnHour = 8;
const int OffHour = 17;

const int OnMin = 0;
const int OffMin = 10;


if (t.hour >= OnHour && t.hour < OffHour && t.min >= OnMin && t < OffMin)
{
  if (digitalRead(Relay) == LOW)  // To keep from flooding the output
  {
    digitalWrite(Relay, HIGH);
    Serial.println("LIGHT ON");
  }
}
else
{
  if (digitalRead(Relay) == HIGH)  // To keep from flooding the output
  {
    digitalWrite(Relay, LOW);
    Serial.println("LIGHT OFF");
  }
}

Wow thanks man, this code help me a lot

JapNanang:
Wow thanks man, this code help me a lot

Be aware that the if statement will be true for one full minute at a time. Depending on what you do in the body of the if statement, and what happens between evaluations of the if statement, that may, or may not, be a problem.

PaulS:
Be aware that the if statement will be true for one full minute at a time. Depending on what you do in the body of the if statement, and what happens between evaluations of the if statement, that may, or may not, be a problem.

The outer 'if' statement will be true for TEN minutes at a time and false for many hours at a time (5pm to 8 am). That is why I put in the inner 'if' statements, so it only acts on the state if it has changed.