Virtuabotixrtc.h Arduino Library _top_ ✨ ⭐
void setup() Serial.begin(9600);
void setup() // Format: setDS1302Time(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, year) // For example, to set the time to 3:28:15 PM on Tuesday, May 19th, 2026: myRTC.setDS1302Time(15, 28, 15, 2, 19, 5, 2026);
If the RTC resets to its default time every time the Arduino loses power, the backup battery is likely not installed, dead, or incorrectly inserted. The DS1302 requires a valid CR2032 battery to maintain timekeeping when main power is removed. Check the battery and its holder.
The virtuabotixrtc.h library is purpose-built to communicate with specific legacy RTC chipsets. It utilizes a three-wire serial interface to manage time data.
An Arduino does not keep track of time (hours, minutes, seconds) accurately once powered off. A Real Time Clock module, powered by a small coin cell battery, keeps ticking even when the Arduino is turned off. This library allows the Arduino to: virtuabotixrtc.h arduino library
The DS1302 RTC module requires five connections to interface with an Arduino board. Three pins handle data communication, while the remaining two provide power. DS1302 Pin Description Arduino Pin (Example) Power Supply (3.3V - 5V) 5V or 3.3V GND CLK Serial Clock Digital Pin 6 DAT Serial Data Digital Pin 7 RST Reset / Chip Select Digital Pin 8
// CLK, DAT, RST pins VirtuabotixRTC myRTC(6, 7, 8);
You should comment out or remove this setDS1302Time line from your setup() after you have uploaded the sketch once. Otherwise, every time the Arduino boots, it will reset the time to the value you hardcoded, rather than letting the RTC keep its current time.
While the VirtuabotixRTC library excels at its core task, the Arduino ecosystem offers other robust options, particularly . void setup() Serial
: Sets the clock. It takes parameters in the order: seconds, minutes, hours, dayofweek, dayofmonth, month, year .
void loop() // Fetch the latest time from the DS1302 module myRTC.updateTime();
Download the library ZIP file from a trusted repository (such as GitHub). Open your Arduino IDE.
// 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 The virtuabotixrtc
The virtuabotixRTC.h library is an Arduino library designed specifically to make reading and writing time data from popular RTC modules—most notably the —incredibly easy. Unlike more complex libraries, virtuabotixRTC.h handles the heavy lifting of converting raw register data from the RTC chip into human-readable integers (seconds, minutes, hours, days, months, years) instantly. Why Choose This Library? Simplicity: Highly intuitive syntax for beginners.
: The DS1302 chip itself is known for significant time drift (up to 20 seconds/day) compared to modern alternatives. Modern Alternatives
Connecting your RTC module to an Arduino board requires five connections. You can use almost any digital pins on your Arduino for the data lines. RTC Module Pin Arduino Pin (Example) Description 5V or 3.3V Power supply GND Ground reference CLK (SCLK) Digital Pin 6 Serial Clock DAT (I/O) Digital Pin 7 Serial Data RST (CE) Digital Pin 8 Reset / Chip Enable 💻 Code Architecture
#include // Include the library // Format: virtuabotixRTC objectName(CLK_PIN, DAT_PIN, RST_PIN); virtuabotixRTC myRTC(6, 7, 8); Use code with caution. Copied to clipboard 2. Setting the Time