Note: If you are using a DS1307 or DS3231 module (which have 4 pins: SDA, SCL, VCC, GND), this library will NOT work. You need the Wire.h library or Adafruit RTCLib for those.
| Library Constructor Argument ( myRTC(CLK, DAT, RST) ) | DS1302 Module Pin | | :---------------------------------------------------- | :---------------- | | CLK_PIN | SCLK | | DAT_PIN | I/O | | RST_PIN | CE (RST) |
Before you can use the library, you'll need to physically connect your DS1302 RTC module to your Arduino board. The DS1302 uses three signal lines—typically labeled (Clock), DAT (Data), and RST (Reset)—and two power lines ( VCC and GND ). Connect your DS1302 module to your Arduino as follows:
#include <virtuabotixRTC.h> virtuabotixRTC myRTC(2, 3, 4); const int relayPin = 7;
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. virtuabotixrtc.h arduino library
library was created to act as the ultimate bridge. Before it arrived, programmers had to manually toggle pins and calculate binary codes just to find out if it was Tuesday. But with this library, everything changed. All a maker had to do was call its name at the start of their code: #include Setting the Clock's Heartbeat
The library manages time by updating specific object variables. It does not require complex data structures to read or write time values. Core Variables myRTC.seconds — Tracks current seconds (0-59) myRTC.minutes — Tracks current minutes (0-59) myRTC.hours — Tracks current hours (0-23) myRTC.dayofWeek — Tracks day numerical value (1-7) myRTC.dayofMonth — Tracks calendar day (1-31) myRTC.month — Tracks current month (1-12) myRTC.year — Tracks four-digit calendar year Essential Methods
You only need to set the RTC once. This function sets the current date and time in your sketch's setup() function. Its format is: myRTC.setDS1302Time(seconds, minutes, hours, day_of_week, day_of_month, month, year); .
Once you call myRTC.updateTime(); , the library populates the following public variables that you can use in your code: Note: If you are using a DS1307 or
Manages seconds, minutes, hours, day of the week, day of the month, month, and year. Static RAM Access:
virtuabotixRTC myRTC(6, 7, 8);
: Essential for loop operations; it refreshes the library's internal variables with the latest time from the chip. Typical Implementation
void setup() Serial.begin(9600);
The library is an Arduino software library specifically designed to interface with DS1302 Real-Time Clock chips. (Note: Despite the ambiguous name, it is primarily intended for the DS1302, though it is often adapted for DS1307 clones). It was written and released by the Virtuabotix team to abstract away the tedious bit-banging and shift-register logic required to talk to these chips.
The library is highly optimized, leaving plenty of room for the rest of your project code.
The DS1302 chip, which this library primarily supports, counts seconds, minutes, hours, date of the month, month, day of the week, and year with leap-year compensation valid up to the year 2100. It communicates via a simple 3-wire serial interface: I/O (Data Line) SCLK (Serial Clock) How to Install the virtuabotixRTC Library