Virtuabotixrtch Arduino Library 〈2026 Edition〉
// print formatted Serial.print(hour); Serial.print(":"); if(minute < 10) Serial.print("0"); Serial.print(minute); Serial.print(":"); if(second < 10) Serial.print("0"); Serial.print(second); Serial.print(" "); Serial.print(month); Serial.print("/"); Serial.print(day); Serial.print("/"); Serial.println(year);
In the Arduino IDE, go to .
While setTime() works for both chips, the library includes specific functions to account for different register structures. It is safe to use setTime() universally, but for advanced users: virtuabotixrtch arduino library
The DS1302 module has 5 main pins that must connect to your Arduino. Unlike I2C devices which restrict you to specific hardware pins (A4 and A5 on the Arduino Uno), the VirtuabotixRTC library allows you to use almost any digital pins for the 3-wire interface. Standard Wiring Table DS1302 Pin Description Recommended Arduino Uno Pin Primary Power (2.0V - 5.5V) 5V or 3.3V GND CLK / SCLK Serial Clock Digital Pin 6 DAT / IO Serial Data input/output Digital Pin 7 RST / CE Reset / Chip Enable Digital Pin 8
delay(1000);
virtuabotixRTC library is a popular choice for interfacing Arduino boards with the DS1302 Real-Time Clock (RTC)
If your Arduino resets and the time goes back to a default date (like 2000), the coin cell battery (CR2032) on the RTC module is likely dead or missing. Replace the battery to ensure the module keeps time while the Arduino is powered off. // print formatted Serial
It supports a wide array of popular RTC chips (DS1302, DS1307, and DS3231).