Arduino alarm clock issue

good evening all,
i have an issue with my alarm clock arduino......
i have built a project with an alarm clock with arduino ..... i am using ds1307 with arduino and an 1602 display ...... and also a buzzer
what i encounter is tha the clock is working and i get an alarm at 10 minutes but not at 15 minutes, and at 18 minutes.....
ty in advance
here is my code

// arduino clock reminder
// 25-04-2024

#include "Arduino.h"
#include "uRTCLib.h"

#include <SPI.h>
#include <LiquidCrystal.h>


// uRTCLib rtc;
uRTCLib rtc(0x68);
const int rs = 7, en = 8, d4 = 2, d5 = 3, d6 = 4, d7 = 5;
const int buzzer=6;
int alarm;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
  pinMode(buzzer,OUTPUT);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Arduino");
  lcd.setCursor(0,1);
  lcd.print("clock");
 for (int i=1;i<=10;i++)
  {
  for (int g=1;g<=50;g++){
  digitalWrite(buzzer,HIGH);
  delay(1);
  digitalWrite(buzzer,LOW);
  delay(1);  
  }
  
  }
  
delay(2000);
lcd.clear();  
 
  // set time for first time
//  rtc.set(0, 22, 1, 6, 25, 4, 24);
//  RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
}

void loop() {
rtc.refresh();
lcd.setCursor(0,0);
lcd.print(rtc.hour());
lcd.print(":");
lcd.print(rtc.minute());
lcd.print(":");
lcd.print(rtc.second());
lcd.setCursor(0,1);
lcd.print(rtc.day());
lcd.print("/");
lcd.print(rtc.month());
lcd.print("/");
lcd.print(rtc.year());
lcd.setCursor(10,0);
lcd.print(alarm);
lcd.setCursor(9,1);
lcd.print("MINUTES");
if (rtc.second()==59) 
{
  alarm=alarm+1;
  lcd.setCursor(10,0);
  lcd.print(alarm);
  lcd.setCursor(9,1);
  lcd.print("MINUTES");
}

// alarms


if (alarm==10) 
{
   for (int i=1;i<=10;i++)
  {
  for (int g=1;g<=60;g++){
  digitalWrite(buzzer,HIGH);
  delay(1);
  digitalWrite(buzzer,LOW);
  delay(1);  
  }
  
  }
}
if (alarm==15)
{
  for (int i=1;i<=10;i++)
  {
    for (int g=1;g<=30;g++)
    {
     digitalWrite(buzzer,HIGH);
     delay(1);
     digitalWrite(buzzer,HIGH);
     delay(1);
      
    }
  }
}
if (alarm==18)
{
  for (int i=1;i<=10;i++)
  {
    for (int g=1;g<=10;g++)
    {
     digitalWrite(buzzer,HIGH);
     delay(1);
     digitalWrite(buzzer,HIGH);
     delay(1);
      
    }
  }
}

delay(1000);

}

Sorry your question does not give me enough information. Can you post your schematic and try to explain to an old timer what you are asking?

Should the second digitalWrite be LOW?

Also in 18?

2 Likes

Do you see the lcd print for 10, 15, and 18?

1 Like

yes i will ... i need some time to draw it
ty

1 Like

yes it should be low ......
i will try it now
ty in advance

i see the 10 minutes only alarm
not the other .....
looks like if statement for 15 and 18 minutes is not working
ty

The delay(1000) coupled with incrementing alarm when seconds is exactly 59 makes me think you are missing some increments.

Try printing the value of alarm and see if it does ever get to 15 and 18.

Also I don't see where you reset alarm to zero.

A reliable way to do something every minute:

  static int lastMinute;
  if (rtc.minute() != lastMinute) {

// do whatever because the minute just changed
    alarm++;

// remember we did this minute already
    lastMinute = rtc.minute();
  }

HTH

a7

good evening.....
i dont reset alarm to zero because i dont need it too...... i use the alarm to count only to infinitive
minutes...... i use it only to see the time and i manually close power to reset it
for example if i use it to count time for some reason i manually power it off
also..... another issue is

if i change rtc.second to 60

then i never get inside the if statement to increase the alarm variable
i dont know why thats why i changed it to 59
also.......

if (rtc.second()==60)
{
alarm=alarm+1;
lcd.setCursor(10,10);
lcd.print(alarm);
lcd.setCursor(9,1);
lcd.print("minutes");
}

your code here u reset the counter every minute ?
can u explain it again?
ty in advance......

static int lastMinute;
if (rtc.minute() != lastMinute) {

// do whatever because the minute just changed
alarm++;

## // remember we did this minute already
lastMinute = rtc.minute();
}

Did you ever do this?

if i change rtc.second to 60

then i never get inside the if statement to increase the alarm variable
i dont know why thats why i changed it to 59

I believe that the seconds run from 0 to 59 before rollover, and there is no 60 second value from the rtc.

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