Trouble getting alarms to trigger.

So the main idea of the project is for an automatic hay feeder which works by having 24 trap doors with hay placed on them ahead of time and a servo as a latch so when you move the servo the door releases and the hay falls to where the horses can get it. It will be arranged so that each servo will be between two doors so each servo will open two doors, so a total of 12 servos will be used. One servo will move in the morning and one in the afternoon, Monday through Saturday. Sunday will be when the doors are reset and refilled with hay. I know this can be done with one Arduino but for redundancy I’ll have two separate Arduinos, one will move the morning servos and another will move the afternoon servos.

I don’t actually have the servos yet so for proof of concept I’ve just been trying to turn relays on and off at a specific day of the week and time and that’s where I’ve run into trouble. I’m new to this and have honestly spent over 7 hours trying different examples and pretty much splicing different codes together trying to get this to work but it seems as though nothing I do will get the alarms to work, either day of the week or just a time of day. I’m using a generic eBay version of an UNO and a DS3231 RTC.

I’ve attached a copy of my code, hopefully someone can point me in the right direction. It would be much appreciated.

HAY_FEEDER_W_RTC.ino (2.59 KB)

You are not calling the Alarm.delay() function in your program so the alarms will not trigger. Did you look at the TimeAlarms example and readme file ?

Read them multiple times but I guess I can be a bit dense. I changed my sketch but the alarms still will not trigger.

HAY_FEEDER_W_RTC_2.ino (2.67 KB)

Please post your code, in code tags.

FlightRisk:
Read them multiple times but I guess I can be a bit dense. I changed my sketch but the alarms still will not trigger.

Does the TimeAlarms example work ?

UKHeliBob:
Does the TimeAlarms example work ?

Yes

AWOL:
Please post your code, in code tags.

#include <TimeLib.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>
#include <Wire.h>
#define DS3231_I2C_ADDRESS 0x68

AlarmId id;



void setup()

    



{  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
    setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");  






  // create the alarms, to trigger at specific times
  //setTime(5,21,0,18,7,17);// set time to Tues 5:21:00am JUL 18 2017
  Alarm.alarmRepeat(dowMonday, 7, 30, 30, MondayAlarm); // 7:30:30 every Monday
  Alarm.alarmRepeat(dowTuesday, 7, 30, 30, TuesdayAlarm); // 7:30:30 every Tuesday
  Alarm.alarmRepeat(dowWednesday, 7, 30, 30, WednesdayAlarm); // 7:30:30 every Wednesday
  Alarm.alarmRepeat(dowThursday, 7, 30, 30, ThursdayAlarm); // 7:30:30 every Thursday
  Alarm.alarmRepeat(dowFriday, 7, 30, 30, FridayAlarm); // 7:30:30 every Friday
  Alarm.alarmRepeat(dowSaturday, 7, 30, 30, SaturdayAlarm); // 7:30:30 every Saturday


  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

}



void loop()
{
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
  } else {
    Serial.println("The time has not been set.  Please run the Time");
    Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
    Serial.println();
    Alarm.delay(4000);
  }
  Alarm.delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}


void MondayAlarm() {
  digitalWrite(2, HIGH);
  Alarm.delay(4000);
  digitalWrite(2, LOW);
  Alarm.delay(1000);
}

void TuesdayAlarm() {
  digitalWrite(3, HIGH);
  Alarm.delay(4000);
  digitalWrite(3, LOW);
  Alarm.delay(1000);
}

void WednesdayAlarm() {
  digitalWrite(4, HIGH);
  Alarm.delay(4000);
  digitalWrite(4, LOW);
  Alarm.delay(1000);
}

void ThursdayAlarm() {
  digitalWrite(5, HIGH);
  Alarm.delay(4000);
  digitalWrite(5, LOW);
  Alarm.delay(1000);
}

void FridayAlarm() {
  digitalWrite(6, HIGH);
  Alarm.delay(4000);
  digitalWrite(6, LOW);
  Alarm.delay(1000);
}

void SaturdayAlarm() {
  digitalWrite(7, HIGH);
  Alarm.delay(4000);
  digitalWrite(7, LOW);
  Alarm.delay(1000);
}