-
Notifications
You must be signed in to change notification settings - Fork 0
/
DS1307_3_0.ino
53 lines (43 loc) · 1.22 KB
/
DS1307_3_0.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
const int relay = A3;
bool on = LOW;
bool off = HIGH;
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC. Check your connections!");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is not running, setting the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
pinMode(relay, OUTPUT);
digitalWrite(relay, off);
}
void loop() {
DateTime now = rtc.now();
int currentHour = now.hour();
int currentMinute = now.minute();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
//Specify the desired timing for your preference. #Configure the activation time for the relay.
if ((currentHour == 17 && currentMinute >= 40) || (currentHour >= 18 && currentHour < 24) || (currentHour >= 0 && currentHour < 6)) {
digitalWrite(relay, on);
} else {
digitalWrite(relay, off);
}
delay(1000);
}