You should use code tags (</> on the toolbar), it makes reading the code much easier.
How do you think the serial port is the issue? i.e what are your symptoms? Does the relay still go on an off as expected?
} while (((V1HON) != (myRTC.hours)) && (V1MON) != ((myRTC.minutes)));
if (((V1HON) == (myRTC.hours)) && (V1MON) == ((myRTC.minutes))) {
In the above tests, you require exact matches. Is it possible the variables could be off by one count.
i.e. if ( i ==10)....... is not as tolerant of conditions as
if (i >=10 ) this will be true at 10 and an number above.
What is your goal and is the RTC really needed? The milli's function is good for 49 days.
Perhaps you could start each day as a function of the RTC then use millis for on/off timing. This way the RTC will make sure the cycle is the same time every day but the millis will determine the on / off times.
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC(12, 13, 7);
int V1HON = 16;
int V1MON = 22;
int V1HOFF = 16;
int V1MOFF = 23;
int relay1 = 2;
void Relay1();
void setup() {
Serial.begin(9600);
pinMode(relay1, OUTPUT);
//myRTC.setDS1302Time (40, 59, 23, 7, 28, 8, 2021);
// put your setup code here, to run once:
}
void loop() {
myRTC.updateTime();
Serial.print("Data Atual / Hora Local: ");
Serial.print(myRTC.dayofmonth); //You can switch between day and month if you're using American system
Serial.print("/");
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" ");
if (myRTC.hours < 10) Serial.print("0");
Serial.print(myRTC.hours);
Serial.print(":");
if (myRTC.minutes < 10) Serial.print("0");
Serial.print(myRTC.minutes);
Serial.print(":");
if (myRTC.seconds < 10) Serial.print("0");
Serial.println(myRTC.seconds);
delay(1000);
do {
digitalWrite(relay1, HIGH);
} while (((V1HON) != (myRTC.hours)) && (V1MON) != ((myRTC.minutes)));
if (((V1HON) == (myRTC.hours)) && (V1MON) == ((myRTC.minutes))) {
Relay1();
}
}
void Relay1() {
digitalWrite(relay1, LOW);
}