RTC Alarm with DS331 Arduino Uno Sofrware Problem

//This is a project for a real time clock alarm with the use of the Arduino Uno.

//The project will be implemented using the following materials:

//1. Arduino Uno
//2. LCD Display 20x4
//3. DS3231
//4. Buzzer
//5. 4 Buttons

//Its function will be as follows:

//It will initially display the date, time and current day on the LCD screen.
//By using the buttons the user will be able to set his own alarm clock
//in which when the current time is equal to the time he has set
//then the buzzer will sound.

//Also with the use of the Button "+" , Button "-" and Set Button
//the user is able to change the Time , Date and Day of the Week as he likes.

#include<Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"
//#include<DS3231.h>
//#include <RTC.h>
//#include <Time.h>
//#include <TimeLib.h>
//#include<hd44780.h>

RTC_DS3231 rtc;

// for the 16x2 LCD

#define rs 9
#define en 8
#define d4 7
#define d5 6
#define d6 5
#define d7 4

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//Month Name - Table
const char* MName[10][12] = { "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" ,"December" };

//Day of the Week - Table
const char* DOW[7][12] = { "Sunday" , "Monday" , "Tuesday" , "Wendnesday" , "Thursday" , "Firday" , "Saturday" };

int notes[] = {262};

int Day;
String Month;
int Year;
int Seconds;
int Minutes;
int Hours;

String daysOfTheWeek; //DOW

String Date; // D/M/Y or Day-Month-Year
String Time; // H/M/S or Hours-Minutes-Seconds

int ATHour; //Alarm Time Hour
int ATMinute; //Alarm Time Minutes

bool AlarmOn = false; //State of the Alarm : On

int S1 = 1; //Switch Alarm Pin
int S2 = 2; //Switch Button + Pin
int S3 = 3; //Switch Button - Pin
int S4 = 4; //Switch Set Button Pin

int Buzzer = 5; //Alarm Buzzer

int SS1 = 0; //Switch State Alarm
int SS2 = 0; //Switch State Button +
int SS3 = 0; //Switch State Button -
int SS4 = 0; //Switch State Set

void setup()
{
Serial.begin(9600);

//Set Inputs and Outputs for the Arduino Uno
pinMode(S1,INPUT);
pinMode(S2,INPUT);
pinMode(S3,INPUT);
pinMode(S4,INPUT);
pinMode(Buzzer,OUTPUT);
}

void loop()
{
DateTime now = rtc.now();

SS1 = digitalRead(S1);
SS2 = digitalRead(S2);
SS3 = digitalRead(S2);
SS4 = digitalRead(S4);

Day = now.day();
//Error1 Month = MName[now.MName()];
Year = now.year();
Seconds = now.second();
Hours = now.hour();
Minutes = now.minute();
//Error2 daysOfTheWeek = DOW[now.DOW()];

//Change the State of the Alarm with the help of the Alarm Button S1
if(SS1 == HIGH)
{
if(AlarmOn == false)
{
AlarmOn = true;
}

else if(AlarmOn == true)
{
  AlarmOn = false;
}  

}

//If the AlarmTime for Hour and Minute match with the curent Time for Hour and Minute then turn on the Buzzer
if(ATHour == now.hour() && ATMinute == now.minute())
{

//Sound loop for 10 seconds
if(now.second() <= 10)
{

  if(AlarmOn == true)
  {
    tone(5,notes[0]); //Sound of the Buzzer
  }
  
}

//No Sound
else
{
noTone(5);
}
}

//No Sound
else
{
noTone(5);
}

//If Switch State 2 is On then increase the hourly value by one unit
if(SS2 == HIGH)
{
ATHour = ATHour + 1;
lcd.clear();
lcd.setCursor(0,3);
lcd.print(ATHour);
lcd.print(":");
lcd.print(ATMinute);

//if the time is at 24 hours then turn it into 0 hours
if(ATHour == 24)
{
ATHour = 0;
}
}

//If Switch State 3 is On then increase the minute value by one unit
if(SS3 == HIGH)
{
ATMinute = ATMinute + 1;
lcd.clear();
lcd.setCursor(0,3);
lcd.print(ATHour);
lcd.print(":");
lcd.print(ATMinute);

//if the time is at 60 seconds then turn it into 0 seconds
if(ATMinute == 60)
{
ATMinute = 0;
}
}

//Main part of the loop
//Prints the Time (H/M/S) , the Date (D/M/Y) and the DOW (Day of the Week) into the LCD

//Reset the display
lcd.clear();

Time = Time + Hours +":"+ Minutes +":" + Seconds ;
Date = Date + " "+ Day + " " + Month + " " + Year ;
//Error3 daysOfTheWeek = DOW ;

//Send to serial monitor
//Error3 Serial.println(DaysoftheWeek);
Serial.println(Date);
Serial.println(Time);

//Set the cursor of the LCD Screen to the First Line
lcd.setCursor(0,0);
lcd.print(Time);

//Set the cursor of the LCD Screen to the Second Line
lcd.setCursor(0,1);
lcd.print(Date);

//Set the cursor of the LCD Screen to the Fith Line
lcd.setCursor(0,2);
lcd.print(daysOfTheWeek);

Date = "";
Time = "";

//Set the cursor of the LCD Screen to the Fourth Line
lcd.setCursor(0,3);

//Prints the Alarm Time: (Alarm Time Hour && Alarm Time Minute)
lcd.print("Alarm: ");
lcd.print(ATHour);
lcd.print(":");
lcd.print(ATMinute);

delay(1000); //Delay 1 second or 1.000 miliseconds
}

Welcome to the forum

Your topic was MOVED to its current forum category as it is more suitable than the original as it does not relate specifically to IDE version 2.0

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

I see that you did not read the advice on getting the best out of this forum that you were directed to when you joined

Do you have a question or a problem ?

OP has an unspecified problem with his alarm system and been announced in the title of the thread,

You are using Pin 5 for both the LCD and the buzzer. That is a pin conflict.

You should have inluded the following code in the setup() fuunction:

lcd.begin(16, 2);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.