#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Servo.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
DS3231 rtc(SDA, SCL);
Time t;
#define serLight 10
int Hor;
int Min;
int Sec;
void setup()
{
Wire.begin();
rtc.begin();
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("DIYHacking.com");
lcd.setCursor(0,1);
lcd.print("Arduino Alarm ");
// The following lines can be uncommented to set the date and time
rtc.setDOW(MONDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(18, 44, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(2, 10, 2020); // Set the date to January 1st, 2014
delay(2000);
serLight.write(90);
}
void loop()
{
t = rtc.getTime();
Hor = t.hour;
Min = t.min;
Sec = t.sec;
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
lcd.setCursor(0,1);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());
if( Hor == 4 && (Min == 30 || Min == 31)) //Comparing the current time with the Alarm time
{
Buzzer();
Buzzer();
lcd.clear();
lcd.print("Alarm ON");
lcd.setCursor(0,1);
lcd.print("Alarming");
Buzzer();
Buzzer();
}
delay(1000);
}
void Buzzer()
{
serLight.write(90);
delay(500);
//request for member 'write' in '10', which is of non-class type 'int' (Error message)
serLight.write(91);
delay(500);
}