Alarm Clock

ABOUT THIS PROJECT

After designing the "Clock Set Date Time" and hearing the suggestion of ArduPic, I thought it would be a good idea and also useful, add a "wake-up alarm." A small change to the code and adding a few components: Here's "the Alarm Clock".
Compared to the previous project, I added a buzzer Piezzo, a diode LED, a resistor of 220 ohms, a button and as said before, I listened to the suggestion of "ArduPic" and I removed the resistance to "pull down."

PHOTO



 Testing 








After uploading the code, LCD will show a Wrong date and time. It means you need to set the Date and time. also remind to Turn OFF or Set the alarm. if not, It will ring at an unexpected time! You can use UP, OK, DOWN push buttons to navigate trough each menu and set date, time and alarm. once you set the alarm, it will save on the EEPROM of your Arduino. Therefore It never lost if you power off your Alarm Clock.









Code

//Prateek
#include
#include
#include
#include

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
RTC_DS1307 RTC;
int temp, inc, hours1, minut, add = 11;

int next = 10;
int INC = 11;
int set_mad = 12;

#define buzzer 13

int HOUR, MINUT, SECOND;


void setup()
{
  Wire.begin();
  RTC.begin();
  lcd.begin(16, 2);
  pinMode(INC, INPUT);
  pinMode(next, INPUT);
  pinMode(set_mad, INPUT);
  pinMode(buzzer, OUTPUT);
  digitalWrite(next, HIGH);
  digitalWrite(set_mad, HIGH);
  digitalWrite(INC, HIGH);
  digitalWrite(buzzer, LOW);
  lcd.setCursor(0, 0);
  lcd.print("ARNAV,AYUSH,PANDAY");
  delay(2000);

  //PRATEEK KUMAR SINGH

  if (!RTC.isrunning())
  {
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop()
{
  int temp = 0, val = 1, temp4;
  DateTime now = RTC.now();
  if (digitalRead(set_mad) == 0)
  {
    lcd.setCursor(0, 0);
    lcd.print("  Set Alarm  ");
    delay(2000);
    defualt();
    time();
    delay(1000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Alarm time ");
    lcd.setCursor(0, 1);
    lcd.print(" has been set  ");
    delay(2000);
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Time:");
  lcd.setCursor(6, 0);
  lcd.print(HOUR = now.hour(), DEC);
  lcd.print(":");
  lcd.print(MINUT = now.minute(), DEC);
  lcd.print(":");
  lcd.print(SECOND = now.second(), DEC);
  lcd.setCursor(0, 1);
  lcd.print("Date: ");
  lcd.print(now.day(), DEC);
  lcd.print("/");
  lcd.print(now.month(), DEC);
  lcd.print("/");
  lcd.print(now.year(), DEC);
  match();
  delay(200);

  //PRATEEK KUMAR SINGH
}

void defualt()
{
  lcd.setCursor(0, 1);
  lcd.print(HOUR);
  lcd.print(":");
  lcd.print(MINUT);
  lcd.print(":");
  lcd.print(SECOND);
}

void time()
{
  int temp = 1, minuts = 0, hours = 0, seconds = 0;
  while (temp == 1)
  {
    if (digitalRead(INC) == 0)
    {
      HOUR++;
      if (HOUR == 24)
      {
        HOUR = 0;
      }
      while (digitalRead(INC) == 0);
    }
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Set Alarm Time ");
    //lcd.print(x);
    lcd.setCursor(0, 1);
    lcd.print(HOUR);
    lcd.print(":");
    lcd.print(MINUT);
    lcd.print(":");
    lcd.print(SECOND);
    delay(100);
    if (digitalRead(next) == 0)
    {
      hours1 = HOUR;
      EEPROM.write(add++, hours1);
      temp = 2;
      while (digitalRead(next) == 0);
    }
  }

  while (temp == 2)
  {
    if (digitalRead(INC) == 0)
    {
      MINUT++;
      if (MINUT == 60)
      {
        MINUT = 0;
      }
      while (digitalRead(INC) == 0);
    }
    // lcd.clear();

    //PRATEEK KUAMR SINGH
    
    lcd.setCursor(0, 1);
    lcd.print(HOUR);
    lcd.print(":");
    lcd.print(MINUT);
    lcd.print(":");
    lcd.print(SECOND);
    delay(100);
    if (digitalRead(next) == 0)
    {
      minut = MINUT;
      EEPROM.write(add++, minut);
      temp = 0;
      while (digitalRead(next) == 0);
    }
  }
  delay(1000);
}

void match()
{
  int tem[17];
  for (int i = 11; i < 17; i++)
  {
    tem[i] = EEPROM.read(i);
  }
  if (HOUR == tem[11] && MINUT == tem[12])
  {
    beep();
    beep();
    beep();
    beep();
    lcd.clear();
    lcd.print("Next Lecture is Esmp");
    lcd.setCursor(0, 1);
    lcd.print("Next Lecture is Esmp");
    beep();
    beep();
    beep();
    beep();
  }

}
void beep()
{
  digitalWrite(buzzer, HIGH);
  delay(500);
  digitalWrite(buzzer, LOW);
  delay(500);

}

COMPONENT

1.ARDUINO
2.RTC
3.PUSH SWITCH (3)
4.RED LED
5.BUZZER

0 Comments