
- Home page
- Languages
- My account
- Notepad Your notepad is empty.
- Shopping cart Your shopping cart is empty.
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.
You cannot find this library by default in the Arduino IDE Library Manager (as of recent updates). You have to install it manually.
| 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.
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);
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.
Once myRTC.updateTime() is called, you can access the following public variables:
myRTC.secondsmyRTC.minutesmyRTC.hours (Usually in 24-hour format depending on chip settings)myRTC.dayofweek (Returns integer: 1 for Sunday, 2 for Monday, etc.)myRTC.dayofmonthmyRTC.monthmyRTC.yearAs 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.