#include <Wire.h>
#include <Wire.h>
#include <DS3231.h> //Libraries ของ DS3231 โมดูลนาฬิกา
DS3231 rtc(SDA, SCL);
Time t;
int Relay1 = 3;
const int TimeOnHour = 8;
const int TimeOnMin = 29;
const int TimeOffHour = 8;
const int TimeOffMin = 30;
void setup()
{
Serial.begin(115200);
rtc.begin();
pinMode(Relay1, OUTPUT);
}
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 == TimeOnHour && t.min == TimeOnMin)
{
digitalWrite(Relay1,HIGH);
Serial.println("Light ON");
}
else if(t.hour == TimeOffHour && t.min == TimeOffMin)
{
digitalWrite(Relay1,LOW);
Serial.println("Light OFF");
}
}