delay(1000); // Update every second
This sketch initializes the clock, sets an initial baseline time, and outputs the updated time to the Serial Monitor every second.
An Arduino does not keep track of time (hours, minutes, seconds) accurately once powered off. A Real Time Clock module, powered by a small coin cell battery, keeps ticking even when the Arduino is turned off. This library allows the Arduino to: virtuabotixrtc.h arduino library
Before diving into code, it's crucial to know the key distinction:
Before you can use the library, you'll need to physically connect your DS1302 RTC module to your Arduino board. The DS1302 uses three signal lines—typically labeled (Clock), DAT (Data), and RST (Reset)—and two power lines ( VCC and GND ). Connect your DS1302 module to your Arduino as follows: delay(1000); // Update every second This sketch initializes
virtuabotixRTC myRTC(7, 6, 5); int tempPin = A0; File dataFile;
: When paired with a backup battery (like a CR2032), the RTC keeps time independently of the Arduino's power state. This library allows the Arduino to: Before diving
This is the most frequently used function. Calling updateTime() inside your loop() refreshes the library's internal variables with the current time from the DS1302 chip. After calling it, you can access the time components.
Unlike I2C-based RTCs (like the DS3231), the DS1302 requires manual pin definition. This library makes that setup easy with a single constructor line: virtuabotixRTC myRTC(CLK, IO, CE) Low Overhead:
Note: You can use almost any digital pins on your Arduino for CLK, DAT, and RST. You just need to specify them in your code. Library Installation Steps
For other RTC chips, like the DS1307 or DS3231, the de facto standard is Adafruit’s . That library is superior in features and active maintenance, but it cannot be used with the DS1302 without a software I2C emulation layer. Thus, VirtuabotixRTC remains relevant specifically for the DS1302 ecosystem.