Arduino timer controlled outlet

Folks,

My next little project is to create an Arduino-based time-controlled outlet. It’ll be a simple circuit - that I can handle. Currently, the code is written to just use hours to set the on and off times. However, I’d like to incorporate minutes as well but I’m finding this much more difficult. My skill level is novice I’d say. First off, do you think it’s possible for someone of my skill level to accomplish this task? Secondly, if you do think it’s possible, please give me some pointers for getting started.

My code thus far. The LED is a proxy for a relay or SSR.

#include <Wire.h> 
#include "DS3231.h" 

RTClib RTC;                                    

const int ledPin = 3;
const int timeonhour = 6;
//const int timeonminute = 45;
const int timeoffhour = 21;
//const int timeoffminute = 30;

void setup () {
    Serial.begin(9600);                  
    Wire.begin();                               
    pinMode(ledPin, OUTPUT);
}

void loop () {
 
    DateTime now = RTC.now();

    if (now.hour() >= timeonhour && now.hour() <= timeoffhour) {
      digitalWrite (ledPin, HIGH);
    }
        
    else {
      digitalWrite (ledPin,LOW);
    }

}

Happy holidays.

Best,

Tony

Calculate minutes past midnight and use that.

@aarg Thank you. I think it’s working. Let me know if you spot anything wonky. Sending Karma.

#include <Wire.h> 
#include "DS3231.h" 

RTClib RTC;                                    

const int ledPin = 3;
const int timeonhour = 9;
const int timeonminute = 3;
int timeOnMinutesSinceMidnight;
const int timeoffhour = 9;
const int timeoffminute = 6;
int timeOffMinutesSinceMidnight;
int minutesAfterMidnight;

void setup () {
    Serial.begin(9600);                  
    Wire.begin();                               
    pinMode(ledPin, OUTPUT);

    timeOnMinutesSinceMidnight = (timeonhour * 60) + timeonminute;
    timeOffMinutesSinceMidnight = (timeoffhour * 60) + timeoffminute;
}

void loop () {
 
    DateTime now = RTC.now();

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

    if (minutesAfterMidnight >= timeOnMinutesSinceMidnight && minutesAfterMidnight <= timeOffMinutesSinceMidnight) {
      digitalWrite (ledPin, HIGH);
    }
        
    else {
      digitalWrite (ledPin,LOW);
    }
}

Happy Holidays.

Best,

Tony