void loop() // Nothing here – this is a one‑time setup
#include <VirtuabotixRTC.h> VirtuabotixRTC myRTC(6, 7, 8);
In this post, we’ll dive deep into what makes this library special, how to install it, and walk through practical examples to get your Real Time Clock (RTC) running in minutes. The VirtuabotixRTC library is designed specifically for the DS1302 real-time clock chip. Unlike the more common DS1307 or DS3231 (which use I2C), the DS1302 communicates via a 3-wire interface (CLK, DAT, RST). This makes it incredibly simple to wire up and frees your I2C pins for other sensors. virtuabotixrtc.h arduino library
#include <VirtuabotixRTC.h> // Pin connections: CLK, DAT, RST VirtuabotixRTC myRTC(6, 7, 8);
Serial.println("Time set on RTC.");
| DS1302 Pin | Arduino Pin | |------------|--------------| | VCC | 5V | | GND | GND | | CLK | 6 | | DAT | 7 | | RST | 8 |
// Print the time Serial.print(" – Time: "); Serial.print(myRTC.hours); Serial.print(":"); Serial.print(myRTC.minutes); Serial.print(":"); Serial.println(myRTC.seconds); void loop() // Nothing here – this is
After running this, comment out myRTC.setDS1302Time(...) or upload a new sketch that only reads time. Example 2: Reading the Current Time Here’s the most common use: continuously reading the RTC and printing to Serial Monitor.
#include <VirtuabotixRTC.h> VirtuabotixRTC myRTC(6, 7, 8); const int ledPin = 13; This makes it incredibly simple to wire up
void setup() Serial.begin(9600);