VirtuabotixRTC.h Arduino library — Concise overview

The VirtuabotixRTC.h library is a lightweight Arduino library that provides a simple interface for interacting with DS1307 and compatible I²C real-time clock (RTC) modules. It abstracts low-level I²C communication and offers straightforward functions to read and set date/time and perform basic RTC operations.

Step 1: Installing the VirtuabotixRTC.h Library

You cannot find this library by default in the Arduino IDE Library Manager (as of recent updates). You have to install it manually.

Standard Wiring Diagram (Arduino Uno)

| DS1302 Module | Arduino Uno | | :--- | :--- | | VCC | 5V | | GND | GND | | CLK | Digital Pin 7 | | DAT | Digital Pin 6 | | RST | Digital Pin 5 |

Note: You can change pins 5,6,7 in the software later.

Final Project: Internet-Free Alarm Clock

Let's tie everything together with a practical project. This code will turn on an LED (or relay) at a specific time.

#include <virtuabotixRTC.h>

virtuabotixRTC myRTC(7, 6, 5); int alarmPin = 13; // Built-in LED bool alarmTriggered = false;

int alarmHour = 7; int alarmMinute = 0;

void setup() pinMode(alarmPin, OUTPUT); digitalWrite(alarmPin, LOW); Serial.begin(9600);

void loop() myRTC.updateTime();

// Check if current time matches alarm time if (!alarmTriggered && myRTC.hours == alarmHour && myRTC.minutes == alarmMinute && myRTC.seconds == 0)

digitalWrite(alarmPin, HIGH);
alarmTriggered = true;
Serial.println("ALARM! Time to wake up!");

// Reset alarm at midnight (optional) if (myRTC.hours == 0 && myRTC.minutes == 0 && myRTC.seconds == 0) alarmTriggered = false; digitalWrite(alarmPin, LOW);

delay(500);


The DS1302 Module (Most Common)

This tiny board usually has 5 pins:

Behind these pins lies the DS1302 chip, a 32.768 kHz crystal, and a small battery (usually a CR2032). This battery keeps the clock running when the main Arduino power is off.

5. Available Variables

Once myRTC.updateTime() is called, you can access the following public variables:

Expert knowledge from Mr. Hanf

As Europe's largest cannabis seed store with over 20 years of owner expertise, we have been sharing our knowledge with over 20,000 customers since 2016.

Market leader Europe 20+ years of experience 20,000+ customers 100% legal in Germany