0% found this document useful (0 votes)
7 views2 pages

Arduino RTC Alarm Clock Code

This document is an Arduino sketch for a digital clock with an alarm feature using an RTC module and an LCD display. It initializes the RTC and LCD, displays the current time and date, and triggers an alarm at a specified time with a buzzer. The code includes functions for displaying time, checking the alarm, and handling the alarm trigger.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Arduino RTC Alarm Clock Code

This document is an Arduino sketch for a digital clock with an alarm feature using an RTC module and an LCD display. It initializes the RTC and LCD, displays the current time and date, and triggers an alarm at a specified time with a buzzer. The code includes functions for displaying time, checking the alarm, and handling the alarm trigger.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <Wire.

h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>

RTC_DS3231 rtc;
DateTime now;
LiquidCrystal_I2C LCD(0x27, 16, 2); // Use 0x3F if 0x27 doesn't work

#define buzzer 11

// 🕒 Set your alarm time here (24-hour format)


int alarmHour = 0;
int alarmMinute = 20;

void setup() {
pinMode(buzzer, OUTPUT);

[Link]();
[Link]();
[Link]();

[Link](9600);
if (![Link]()) {
[Link](0, 0);
[Link]("RTC not found!");
while (1);
}

if ([Link]()) {
[Link](DateTime(F(__DATE__), F(__TIME__))); // Set RTC to compile time
}

[Link](0, 0);
[Link]("Welcome to");
delay(1000);
[Link](0, 1);
[Link]("LearnElectronics");
delay(2000);
[Link]();
}

void loop() {
now = [Link](); // Get current time

displayTimeAndDate();

// 🔔 Check if alarm time matches


if ([Link]() == alarmHour && [Link]() == alarmMinute) {
triggerAlarm();
delay(8000); // Wait 1 min to avoid repeating alarm
}

void displayTimeAndDate() {
[Link](0, 0);
[Link]("Time = ");
if ([Link]() < 10) [Link]("0");
[Link]([Link]());
[Link](":");
if ([Link]() < 10) [Link]("0");
[Link]([Link]());
[Link](":");
if ([Link]() < 10) [Link]("0");
[Link]([Link]());

[Link](0, 1);
[Link]("Date = ");
[Link]([Link]());
[Link]("/");
[Link]([Link]());
[Link]("/");
[Link]([Link]());
}

void triggerAlarm() {
[Link]();
[Link](0, 0);
[Link](" WAKE UP !!! ");
[Link](0, 1);
[Link](" ALARM TIME ");
for (int i = 0; i < 10; i++) { // Beep 10 times
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
delay(300);
}
[Link]();
}

You might also like