One of the most subtle aspects of VirtuabotixRTC.h is its handling of BCD vs. binary. The DS1302 stores time natively in BCD: for example, 42 seconds is stored as 0x42 (binary 01000010), not 0x2A (binary 00101010).
Once upon a time in the digital world of Arduino, there was a tiny, ticking heartbeat known as the DS1302 Real-Time Clock virtuabotixrtc.h arduino library
void setup() Serial.begin(9600);
virtuabotixRTC myRTC(2, 3, 4); File dataFile; const int chipSelect = 10; // SD Card CS pin One of the most subtle aspects of VirtuabotixRTC
Here is the standard wiring diagram:
// Format: myRTC.setDS1302Time(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, year); myRTC.setDS1302Time(00, 30, 14, 1, 27, 4, 2026); Use code with caution. Copied to clipboard Once upon a time in the digital world
#include // // Declare the RTC object hooked up to pins 6, 7, and 8 virtuabotixRTC myRTC(6, 7, 8); void setup() Serial.begin(9600); // Start serial communication // IMPORTANT: Set the initial time here. // Seconds, Minutes, Hours, Day of the week, Day of the month, Month, Year // Day of week: 1 = Sunday, 2 = Monday, etc. myRTC.setDS1302Time(00, 15, 20, 1, 27, 4, 2026); // Example: April 27, 2026 at 8:15 PM // Note: After running this once, comment out the line above and re-upload! void loop() // Update the variables with data from the RTC chip myRTC.updateTime(); // Print the date Serial.print("Date: "); Serial.print(myRTC.dayofmonth); Serial.print("/"); Serial.print(myRTC.month); Serial.print("/"); Serial.print(myRTC.year); Serial.print(" Use code with caution. Copied to clipboard 🛠 Troubleshooting & Errors