Skip to content

Instantly share code, notes, and snippets.

@nalakawula
Created October 23, 2016 11:11
Show Gist options
  • Save nalakawula/4a8c6bc8ff5b132abe5e478cf3f01506 to your computer and use it in GitHub Desktop.
Save nalakawula/4a8c6bc8ff5b132abe5e478cf3f01506 to your computer and use it in GitHub Desktop.
Program percobaan penggunaan RTC untuk trigger relay
/*
Bismilla, percobaan RTC dan relay untuk my students.
*/
#include <DS3231.h>
//init rtc
DS3231 rtc(SDA, SCL);
// Init struktur Time-data
Time t;
//definisi pin I/O yang dibutuhkan
const int led_1 = 13;
const int relay_1 = 7;
void setup()
{
Serial.begin(115200);
rtc.begin();
pinMode(led_1, OUTPUT);
digitalWrite(led_1, LOW);
pinMode(relay_1, OUTPUT);
digitalWrite(relay_1, LOW);
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
}
void loop()
{
//data dari DS3231
t = rtc.getTime();
//untuk memonitor jam dari serial (boleh di disable)
Serial.print(t.hour, DEC);
Serial.print(":");
Serial.print(t.min, DEC);
Serial.print(":");
Serial.print(t.sec, DEC);
Serial.println("");
//variabel waktu
int jam = t.hour;
int menit = t.min;
int detik = t.sec;
//sesuaikan jam, menit, dan detik dengan kebutuhan
if (jam == 18 && menit == 10 && detik == 00) {
digitalWrite(relay_1, HIGH);
digitalWrite(led_1, HIGH);
delay(2000); //relay dan led indikator menyala selama 2 detik, silakan disesuaikan
digitalWrite(relay_1, LOW);
digitalWrite(led_1, LOW);
}
else
{
digitalWrite(relay_1, LOW);
digitalWrite(led_1, LOW);
}
delay (1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment