Virtuabotixrtc.h Arduino Library Here
| DS1302 Pin | Arduino Pin | Description | | :--- | :--- | :--- | | | 5V | Power | | GND | GND | Ground | | CE / RST | Digital Pin 2 | Chip Enable / Reset | | I/O / DAT | Digital Pin 3 | Data Input/Output | | SCLK | Digital Pin 4 | Serial Clock |
Once updated, you can access the time through the following integer variables: myRTC.seconds myRTC.minutes myRTC.hours myRTC.dayofweek myRTC.dayofmonth myRTC.month myRTC.year 📜 Complete Example Sketch
: Connect to 3.3V or 5V (depending on the specific module version). GND : Connect to Arduino GND. CLK (Clock) : Serial clock input. DAT (Data) : Bi-directional data line (often labeled I/O). RST (Reset) : Chip enable/reset pin (often labeled CE). Key Library Functions
// Define your pins: (CLK, DAT, RST) // Using pins 7, 6, 5 as wired above virtuabotixRTC myRTC(7, 6, 5); virtuabotixrtc.h arduino library
// Check if current time matches alarm time if (!alarmTriggered && myRTC.hours == alarmHour && myRTC.minutes == alarmMinute && myRTC.seconds == 0)
void printDigits(int digits) if(digits < 10) Serial.print("0"); Serial.print(digits);
The virtuabotixRTC.h library is a widely used Arduino library specifically designed to interface with the . It provides a simple, high-level wrapper around the DS1302’s complex three-wire serial communication protocols. Core Functionality | DS1302 Pin | Arduino Pin | Description
: Uses a CR2032 or CR1220 coin cell to retain time when Arduino loses power. ⚙️ Pin Mapping and Wiring
This straightforward API allows a novice to get an RTC working within minutes. A typical usage pattern involves calling updateTime() in every iteration of loop() , then reading the public variables for display or logic decisions.
To use the library, you must first install it (often manually via a ZIP from GitHub ) and then include it in your sketch. Problem with code for Arduino using an RTC - Programming DAT (Data) : Bi-directional data line (often labeled I/O)
To initialize the library, you must create an object instance and define the pins connected to the module:
This sketch initializes the clock, sets an initial baseline time, and outputs the updated time to the Serial Monitor every second.
Once upon a time in the digital world of Arduino, there was a tiny, ticking heartbeat known as the DS1302 Real-Time Clock
Works on any digital, PWM, or analog pin mapping on the Arduino.

