Virtuabotixrtch Arduino Library -
Have you ever built an Arduino project that needed to know the exact time? Whether you're making a digital clock, a timed plant waterer, or a data logger, a standard Arduino can’t keep accurate time once the power goes out.
Ultimate Guide to the VirtuabotixRTC Arduino Library: Real-Time Clock Integration
In the Arduino IDE, go to Sketch > Include Library > Add .ZIP Library and select the downloaded file. 2. Wiring Diagram
To use the library, you must connect the DS1302 RTC module to your Arduino. The DS1302 uses a 3-wire serial interface (distinct from I2C or standard SPI). DS1302 Pin Description Arduino Pin (Example) Power Supply (2.0V - 5.5V) 5V or 3.3V GND CLK Serial Clock DAT Serial Data RST (or CE) Reset / Chip Enable
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. virtuabotixrtch arduino library
This example demonstrates how to set the time once and then read it continuously.
The DS1302 uses three digital pins plus power and ground. While you can use any digital pins, a common setup is: : 5V or 3.3V GND : Ground CLK (SCLK) : Digital Pin 6 DAT (I/O) : Digital Pin 7 RST (CE/Reset) : Digital Pin 8 💻 Core Functions
Note: Some modules label RST as "CE" (Chip Enable).
In the Arduino IDE, go to .
When choosing an RTC library, you often have to decide between this library and the more popular RTClib by Adafruit. The following table outlines the key differences to help you make an informed choice.
| Pin | Function | |------|-----------| | VCC | 5V / 3.3V | | GND | Ground | | CLK | Serial Clock (SCLK) | | DAT | Data (I/O) | | RST | Chip Enable (CE) |
The parameter ranges are as follows:
If you have a DS1302 module (often the one with the vertical pins), this library offers a few distinct advantages: Have you ever built an Arduino project that
After uploading, comment out or remove the setDS1302Time line and re-upload. Otherwise, it will reset the time every boot.
// 2. Create an RTC object // The order of the pins is (CLK pin, DAT pin, RST pin) // Here we are using pins 6, 7, and 8 as wired above. virtuabotixRTC myRTC(6, 7, 8);
// Define the connection pins: CLK, DAT, RST // MyRTC(ClockPin, DataPin, ResetPin) VirtuabotixRTC myRTC(6, 7, 8);