Virtuabotixrtc.h Arduino Library Site
The best free Adobe Audition presets for podcast editing. Easily drag and drop files, edit podcasts like a pro in minutes. Get pro podcast sound fast.
The best free Adobe Audition presets for podcast editing. Easily drag and drop files, edit podcasts like a pro in minutes. Get pro podcast sound fast.
Choose VirtuabotixRTC when you want to keep I2C free or are using a DS1302 module you already own. The VirtuabotixRTC library is a reliable, lightweight way to add timekeeping to your Arduino projects. Its straightforward functions and flexible pin assignment make it perfect for beginners and pros alike. Whether you’re building an automatic plant waterer, a data logger, or a programmable timer, this library has you covered.
void setup() Serial.begin(9600);
If you’ve ever built an Arduino project that involves logging data, controlling lights on a schedule, or waking up a device at a specific time, you know that keeping accurate time is crucial. While the popular RTClib works great for DS3231 and DS1307 modules, there’s another powerful—and often overlooked—option: the VirtuabotixRTC.h library.
// Print the time Serial.print(" – Time: "); Serial.print(myRTC.hours); Serial.print(":"); Serial.print(myRTC.minutes); Serial.print(":"); Serial.println(myRTC.seconds); virtuabotixrtc.h arduino library
#include <VirtuabotixRTC.h> VirtuabotixRTC myRTC(6, 7, 8);
void setup() pinMode(ledPin, OUTPUT); Serial.begin(9600);
#include <VirtuabotixRTC.h> // Pin connections: CLK, DAT, RST VirtuabotixRTC myRTC(6, 7, 8); Choose VirtuabotixRTC when you want to keep I2C
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.
delay(1000); // Update every second
Open the Serial Monitor (9600 baud) and watch the live clock. This is where the RTC shines. Let’s turn an LED on at 8:00 AM and off at 8:00 PM. Whether you’re building an automatic plant waterer, a
// Print the date Serial.print("Date: "); Serial.print(myRTC.dayofmonth); Serial.print("/"); Serial.print(myRTC.month); Serial.print("/20"); Serial.print(myRTC.year);
delay(500);
// Turn LED on between 8:00 and 19:59 (8 AM to 7:59 PM) if (currentHour >= 8 && currentHour < 20) digitalWrite(ledPin, HIGH); if (currentHour == 8 && myRTC.minutes == 0 && myRTC.seconds < 5) Serial.println("Good morning! LED is ON.");
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.
void loop() // Nothing here – this is a one‑time setup
Join 30,000+ active members of the Music Radio Creative community.