void loop() // 1. Read the current time from the chip myRTC.updateTime();
VirtuabotixRTC myRTC(0, 1); // Pin 0 = SDA, Pin 1 = SCL
into your module. This ensures that even if your Arduino loses power, the RTC keeps ticking, so you don't have to reset the time every time you reboot. DS1302 vs. DS3231: virtuabotixrtch arduino library
The is a popular software tool designed to simplify interfacing between an Arduino microcontroller and a DS1302 Real-Time Clock (RTC) module. It acts as a wrapper for the low-level serial communication required by the DS1302, allowing developers to manage time and date with high-level functions. Key Features and Capabilities
void setup() // Initialize the RTC module myRTC.begin(); void loop() // 1
// Wait 1 second before reading again delay(1000);
If you are a beginner, the Adafruit library is excellent but can feel overwhelming due to its DateTime objects. The Virtuabotix library feels more like “pure Arduino” – you set variables as int and read them as int . No classes, no pointers, just straightforward reads and writes. DS1302 vs
// COMMENT THIS LINE AFTER FIRST USE // Only uncomment to set the time to when this sketch is compiled // myRTC.setTime(0, 15, 10, 4, 17, 10, 24);
// 4. Access the individual time components and print them to the Serial Monitor Serial.print("Current Date / Time: "); Serial.print(myRTC.dayofmonth); Serial.print("/"); Serial.print(myRTC.month); Serial.print("/"); Serial.print(myRTC.year); Serial.print(" "); Serial.print(myRTC.hours); Serial.print(":"); Serial.print(myRTC.minutes); Serial.print(":"); Serial.println(myRTC.seconds);
Users sometimes encounter problems when using the VirtuabotixRTC library. Here are a few common ones and how to approach them.