delay(1000); // Update every second
int currentHour = myRTC.hours;
void setup() Serial.begin(9600);
Open the Serial Monitor (9600 baud) and watch the live clock. This is where the RTC shines. Let’s turn an LED on at 8:00 AM and off at 8:00 PM.
In this post, we’ll dive deep into what makes this library special, how to install it, and walk through practical examples to get your Real Time Clock (RTC) running in minutes. The VirtuabotixRTC library is designed specifically for the DS1302 real-time clock chip. Unlike the more common DS1307 or DS3231 (which use I2C), the DS1302 communicates via a 3-wire interface (CLK, DAT, RST). This makes it incredibly simple to wire up and frees your I2C pins for other sensors. virtuabotixrtc.h arduino library
// Print the date Serial.print("Date: "); Serial.print(myRTC.dayofmonth); Serial.print("/"); Serial.print(myRTC.month); Serial.print("/20"); Serial.print(myRTC.year);
// Turn LED on between 8:00 and 19:59 (8 AM to 7:59 PM) if (currentHour >= 8 && currentHour < 20) digitalWrite(ledPin, HIGH); if (currentHour == 8 && myRTC.minutes == 0 && myRTC.seconds < 5) Serial.println("Good morning! LED is ON."); delay(1000); // Update every second int currentHour =
else digitalWrite(ledPin, LOW); if (currentHour == 20 && myRTC.minutes == 0 && myRTC.seconds < 5) Serial.println("Evening – LED is OFF.");
| DS1302 Pin | Arduino Pin | |------------|--------------| | VCC | 5V | | GND | GND | | CLK | 6 | | DAT | 7 | | RST | 8 | In this post, we’ll dive deep into what