| DS1302 Module Pin | Connect to Arduino Pin | | :--- | :--- | | | 5V | | GND | GND | | CLK | Digital Pin 6 | | DAT | Digital Pin 7 | | RST | Digital Pin 8 |
Simplifies complex I2C/SPI communication into easy-to-use methods like updateTime() and setDS1302Time() .
/* * Basic example for the VirtuabotixRTC Library * This sketch sets the time on the RTC and then prints the current time * to the Serial Monitor once per second. */ virtuabotixrtch arduino library
Download the VirtuabotixRTC library source files (usually a .zip folder from GitHub or a project repository). Open your Arduino IDE.
This is the most common error. It appears as fatal error: virtuabotixRTC.h: No such file or directory . It almost always means either you forgot to install the library, or you installed it incorrectly. | DS1302 Module Pin | Connect to Arduino
// --- SETTING THE TIME (Do this only once) --- // The function: myRTC.setDS1302Time(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, year) // Note: The year is a full 4-digit integer (e.g., 2026). // This line sets the time to January 1, 2026, 12:00:00 on a Thursday. myRTC.setDS1302Time(00, 00, 12, 5, 1, 1, 2026);
: This is the main function to set the initial time on your RTC module. It writes the provided date and time to the DS1302 chip. The parameters are: Open your Arduino IDE
First, include the library header and create an instance of the virtuabotixRTC class, passing the pins you used for CLK, DAT, and RST:
Wiring the DS1302 to your Arduino is straightforward. The library is flexible and allows you to choose any digital pins you wish. The table below shows a common wiring example:
In the Arduino IDE, go to .
delay(1000);