Want to make a daily alarm with different timings

Greetings,

I am trying to make an alarm clock that triggers different event on different day for same time each ‘day’ with 3 alarms per day, i have a DS1307 RTC connected to a NANO WITH a DFplayer , but I am getting trouble comparing the day string to set alarm.

Basically i want something like this for example:

At 06;30 on day 1 perform function (PLAY TRACK NO. 1)
At 06;30 on day 2 perform function (PLAY TRACK NO. 2)
At 06;30 on day 3 perform function (PLAY TRACK NO. 3)
At 06;30 on day 4 perform function (PLAY TRACK NO. 4)
At 06;30 on day 5 perform function (PLAY TRACK NO. 5)
At 06;30 on day 6 perform function (PLAY TRACK NO. 6)
At 06;30 on day 7 perform function (PLAY TRACK NO. 7)
end

Any help would be greatly appreciated.

thanks

using the RTClib (GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library)

you could build the number of seconds since midnight and compare that to your alarm time (in seconds since midnight) and use the day of week to not trigger twice the same day.

something like this (typed here, fully untested)

#include <RTClib.h> // https://github.com/adafruit/RTClib
RTC_DS1307 rtc;

const uint8_t alarmHour = 6;
const uint8_t alarmMinute = 30;
const uint8_t alarmSecond = 0;

const uint32_t alarmTime = (3600ul * alarmHour) + (60ul * alarmMinute) + alarmSecond; // number of seconds after midnight when to ring the alarm. here at 6:30:00

byte alarmDay;

void setup () {
  Serial.begin(115200);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (true) yield();
  }

  // following line sets the RTC to the date & time this sketch was compiled (if needed)
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  DateTime now = rtc.now();
  uint32_t nowSec = (3600ul * now.hour()) + (60ul * now.minute()) + now.second();
  alarmDay = now.dayOfTheWeek();
  if (nowSec > alarmTime) alarmDay = (alarmDay + 1) % 7; // set the alarm for tomorrow if today is past due time
}

void loop () {
  DateTime now = rtc.now();
  uint32_t nowSec = (3600ul * now.hour()) + (60ul * now.minute()) + now.second();
  if ((now.dayOfTheWeek() == alarmDay) && (nowSec == alarmTime)) { // if this is the right day and it's time
    Serial.println(F("ALARM !!!")); // you can use alarmDay+1 (1 to 7) to decide what to play
    alarmDay = (alarmDay + 1) % 7; // set the alarm for tomorrow
  }
}

when the alarm sounds, you can use alarmDay+1 (which will vary from 1 to 7) to decide what to play

PS

You can do

if ((now.dayOfTheWeek() == alarmDay) && (nowSec >= alarmTime)) { // if this is the right day and it's time

If the loop does other things and you think you might miss the exact second,

1 Like

I am using ds3232 rtc library if any code sample to compare day and time for alarm activating.
And also i want to play df player a sequence of track daily
As on monday play track no 1 to 5
On tuesday play track no 6 to 10
And so on...
Plz help

Show your attempt

I gave you an example on how to compare the time in the code I proposed. Study that

I had solved my problem by using this code.
If (t.dow = 1 && hrs = 6 && min = 30 && sec = 00)

This is working with ds3231 rtc library

I also added date wise alarm with this code.
If ( t.date = 20, 1, Year && hrs = 6 && min = 30 && sec = 00)
This will repeat alarm on special day like birthday and anniversary every year.

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