RTC DS1302 adalah modul untuk melacak waktu secara real-time. Dalam blog ini, kita akan membahas cara mudah menggunakan RTC DS1302 dengan Arduino untuk proyek yang membutuhkan fungsi waktu. Let’s go!

untuk codenya kalian bisa gunakan code dibawah ini :
#include <Arduino.h>
#include <DS3232RTC.h>
tmElements_t waktu_rtc_ds3232;
int jam_rtc_ds3232;
int menit_rtc_ds3232;
int detik_rtc_ds3232;
int bulan_rtc_ds3232;
int tahun_rtc_ds3232;
int minggu_rtc_ds3232;
bool sync_rtc_ds3232() {
time_t t = RTC.get();
if (t != 0) {
RTC.read(waktu_rtc_ds3232);
return true;
}
return false;
}
String baca_rtc_ds3232(String format) {
String hasil;
if (sync_rtc_ds3232()) {
RTC.read(waktu_rtc_ds3232);
jam_rtc_ds3232 = waktu_rtc_ds3232.Hour;
menit_rtc_ds3232 = waktu_rtc_ds3232.Minute;
detik_rtc_ds3232 = waktu_rtc_ds3232.Second;
bulan_rtc_ds3232 = waktu_rtc_ds3232.Month;
tahun_rtc_ds3232 = waktu_rtc_ds3232.Year;
minggu_rtc_ds3232 = waktu_rtc_ds3232.Wday;
char buffer[20];
snprintf(buffer, sizeof(buffer), format.c_str(),
waktu_rtc_ds3232.Day, bulan_rtc_ds3232, tahun_rtc_ds3232,
jam_rtc_ds3232, menit_rtc_ds3232, detik_rtc_ds3232);
hasil = buffer;
}
return hasil;
}
void setup()
{
Serial.begin(9600);
setSyncProvider(RTC.get);
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
}
void loop(){
Serial.println("Waktu : " + baca_rtc_ds3232("d-m-Y H:i:s"));
}
Untuk skematik, kamu bisa ikuti skematick di bawah ini

Kabel Hitam : GND
Kabel Merah : VCC
Kabel Kuning : CLK
Kabel Oren : RST
Kabel Hijau : DAT
selamat mencoba, salam labrobotika
Jika anda berminat menggunakan jasa labrobotika, silahkan hubungi admin: WHATSAPP


