Virtuabotixrtch Arduino Library Official

void setup() Serial.begin(9600); lcd.init(); lcd.backlight();

The VirtuabotixRTC library, originally created by the hardware manufacturer Virtuabotix, is a lightweight, simple-to-use library designed specifically for the DS1307 and DS3231 RTC chips over I2C communication. Whether you are building a data logger, an automated garden irrigation system, or a digital clock, this library provides the essential functions without the bloat of more complex timestamp libraries. virtuabotixrtch arduino library

// 3. Print to LCD lcd.setCursor(0, 0); lcd.print("Time: "); if(myRTC.hours < 10) lcd.print("0"); lcd.print(myRTC.hours); lcd.print(":"); if(myRTC.minutes < 10) lcd.print("0"); lcd.print(myRTC.minutes); void setup() Serial

Even with a simple library, problems arise. Here are the most common fixes for VirtuabotixRTC: Issue 1: The time reads 165:85:85 or similar gibberish. Cause: The RTC chip has lost power (dead battery) or was never set. The registers contain random values. Fix: Replace the CR2032 battery. Then, uncomment the setTime() line in setup() , upload the code, wait 5 seconds, then re-upload after commenting it out again. Issue 2: The time resets every time I unplug USB. Cause: Your RTC module’s battery is not connected, or the module does not have a battery holder. Fix: Most cheap modules have a diode that prevents charging. Ensure a 3V coin cell is installed. Issue 3: Compilation error – VirtuabotixRTC.h: No such file Cause: Library not installed correctly. Fix: Reinstall via Library Manager. Restart Arduino IDE. Issue 4: The year shows 24 but I want 2024 . Fix: The library stores years as two-digit (0 to 99). You must manually add 2000 in your print statement: Print to LCD lcd

void setup() // Wake up Wire.begin(); myRTC.updateTime(); Serial.println(myRTC.minutes); // Enter deep sleep for 1 minute ESP.deepSleep(60e6);

If you need absolute seconds since 1970, you can extend the library:

Introduction In the world of embedded electronics and DIY projects, keeping accurate time is a surprisingly difficult challenge. The Arduino’s internal clock (millis() or delay()) is notoriously inaccurate for long-term projects, drifting by several seconds per day. To solve this, makers turn to Real-Time Clock (RTC) modules. Among the most popular and affordable of these is the DS1307 or DS3231 chip, typically found on a breakout board with a coin cell battery. However, navigating the code to interface with these chips can be tricky. That’s where the VirtuabotixRTC Arduino Library comes in.