If your module has separate DS and SCLK pins (common on old DS1302 modules), do not use VirtuabotixRTC. That library is for I2C modules only (DS1307/3231). For DS1302, you need the DS1302 library.
void setup() // Wake up Wire.begin(); myRTC.updateTime(); Serial.println(myRTC.minutes); // Enter deep sleep for 1 minute ESP.deepSleep(60e6);
To use the library, you must first create an object. The constructor takes two arguments: the SDA pin and the SCL pin. For standard boards, we use A4 and A5 even though they are analog pins (they double as digital I2C). virtuabotixrtch arduino library
In the world of Arduino prototyping, accurately tracking time is a foundational requirement for projects ranging from simple digital clocks to sophisticated data loggers and automated irrigation systems. While there are many libraries available for managing Real Time Clock (RTC) modules, the stands out for its simplicity, ease of use, and specialized support for the popular, budget-friendly DS1302 RTC module.
Ensure the pins defined in the code VirtuabotixRTC myRTC(6, 7, 8) match the physical connections on your Arduino. The order is strictly Clock, Data, Reset (CE) . If your module has separate DS and SCLK
When logging sensor data every second, you don’t want to parse objects. This code is lean and fast:
The DS1302 module is a low-power clock/calendar chip, commonly found as a small breakout board with five pins: VCC, GND, CLK, DAT, and RST. This is the module that the VirtuabotixRTC library is designed to communicate with, and mixing it with other RTC chips (like a DS1307) will not work. void setup() // Wake up Wire
If your Arduino resets and the time goes back to a default date (like 2000), the coin cell battery (CR2032) on the RTC module is likely dead or missing. Replace the battery to ensure the module keeps time while the Arduino is powered off.
Specifically optimized to handle the 3-wire serial interface of the DS1302.
#include <VirtuabotixRTC.h>