-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca7a72b
commit a9f9de4
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#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"); | ||
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(); | ||
int currentSecond = now.second(); | ||
|
||
Serial.print("Current time: "); | ||
Serial.println(now.timestamp()); | ||
|
||
if (currentHour == 17 && currentMinute == 40 && currentSecond == 0) { | ||
digitalWrite(relay, on); | ||
delay(1000); // Delay to ensure the relay is toggled only once | ||
} | ||
if (currentHour == 6 && currentMinute == 0 && currentSecond == 0) { | ||
digitalWrite(relay, off); | ||
delay(1000); // Delay to ensure the relay is toggled only once | ||
} | ||
|
||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <Wire.h> | ||
#include <RTClib.h> | ||
|
||
RTC_DS3231 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"); | ||
while (1); | ||
} | ||
|
||
if (rtc.lostPower()) { | ||
Serial.println("RTC lost power, 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(); | ||
int currentSecond = now.second(); | ||
|
||
Serial.print("Current time: "); | ||
Serial.println(now.timestamp()); | ||
|
||
if (currentHour == 17 && currentMinute == 40 && currentSecond == 0) { | ||
digitalWrite(relay, on); | ||
delay(1000); // Delay to ensure the relay is toggled only once | ||
} | ||
if (currentHour == 6 && currentMinute == 0 && currentSecond == 0) { | ||
digitalWrite(relay, off); | ||
delay(1000); // Delay to ensure the relay is toggled only once | ||
} | ||
|
||
delay(1000); | ||
} |