Alarm

make sure the Time library is in your libraries folder, perhaps.

error: 'Alarm' does not name a type In function 'void setup()':

I tried to add an object like this:
but I am still getting an error

Alarm noisydarnClock;

void setup()
{ 
  
  pinMode(midnightPin, INPUT);
  pinMode(timerPin, OUTPUT);
  
  noisydarnClock.alarmRepeat(0,00,10,MeetingOne); 
  noisydarnClock.alarmRepeat(0,00,30,MeetingTwo); 
  noisydarnClock.alarmRepeat(0,00,40,MeetingThree);
  noisydarnClock.alarmRepeat(0,00,59,MeetingFour);
  noisydarnClock.alarmRepeat(9,30,0,MeetingFive);
  noisydarnClock.alarmRepeat(10,00,0,MeetingSix);
  noisydarnClock.alarmRepeat(10,30,0,MeetingSeven);
  noisydarnClock.alarmRepeat(11,00,0,MeetingEight);
  noisydarnClock.alarmRepeat(15,00,0,MeetingNine);
  
}

What about :

#include <Time.h>
#include <TimeAlarms.h>

?

Or contact user "mem".
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1262783962/0

I assumed Alarm is an instance defined in TimeAlarms.h

A correct assumption, verified by this line in TimeAlarms.h extern TimeAlarmsClass Alarm;  // make an instance for the user
The alarm library creates the Alarm object for the user (in the same way the serial library creates the Serial object), which is why there is no mention of objects in the documentation.

The Arduino convention of pre-creating objects that can only have a single instance can be surprising to experienced programmers at first, but as there always must be one and only one Alarm object in a sketch that uses this library, its a convenience for novices to have this ready to use.

BTW, there was an earlier version of the library that had a user created instance for each alarm but feedback indicated that the current version that has a single pre-created instance handling multiple alarms was easier for most Arduino users.

cne, the sketch you posted at the start of this thread compiles ok for me. Perhaps download and install the libraries again and see if it compiles for you.

The FAQ supplied with the library says that up to six alarms can be created but
after you have it compiling ok, you can change a define in TimeAlarms.h to set the maximum number of alarms to 8
#define dtNBR_ALARMS 8 // this is 6 in the distributed library

#include <Time.h>

#include <TimeAlarms.h>

const int ledPin =  13;      // the number of the LED pin
const int onPin = 5;

void setup()
{
  
  setTime(8,29,40,1,1,10); // set time to 8:29:40am Jan 1 2010 

  Alarm.alarmRepeat(8,30,0,morningAlarm);  // 8:30am every day
  Alarm.alarmRepeat(8,30,10,otherAlarm);  
  
  pinMode(ledPin, OUTPUT); 
  pinMode(onPin, OUTPUT); 
 
}
void morningAlarm()
{
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
}

void otherAlarm()
{
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);          
}

void  loop()
{  
  digitalWrite(onPin, HIGH);
}

I made a program to test out the alarm. The alarms should both go off in less than a miniute from start up, but they don't. Am I doing something wrong?

You need to call the Alarm.delay funtion from within loop.

The following is from the FAQ included in the readme file supplied with the library:

Task scheduling is handled in the Alarm.delay function.
Tasks are monitored and triggered from within the Alarm.delay call so Alarm.delay should be called
whenever a delay is required in your sketch.
If your sketch waits on an external event (for example, a sensor change),
make sure you repeatedly call Alarm.delay while checking the sensor.
You can call Alarm.delay(0) if you need to service the scheduler without a delay.

try the following:

void  loop()
{  
  digitalWrite(onPin, HIGH);
  Alarm.delay(1);
}

I have updated my main code, but when I turn it on, the alarm goes three times about 10s apart. When I turn pin 2 high, it sounds the alarm 6 times very fast. After this the program seems to stop.

//This program recieves a 1 second pulse at midnight for syncronization
//Alarms are referenced off that event
//The alarms sound a buzzer for one second on pin 13
//The circuit recieves a pulse on pin 2

#include "Time.h"
#include "TimeAlarms.h"

const int midnightPin= 2;
const int timerPin= 13;
const int buzzerPin= 4;


int midnightState=0;

void setup()
{ 
  pinMode(midnightPin, INPUT);
  pinMode(timerPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  
  Alarm.alarmRepeat(0,00,10,MeetingOne); 
  Alarm.alarmRepeat(0,00,20,MeetingTwo); 
  Alarm.alarmRepeat(0,00,40,MeetingThree);
  Alarm.alarmRepeat(0,00,59,MeetingFour);
  Alarm.alarmRepeat(9,30,0,MeetingFive);
  Alarm.alarmRepeat(10,00,0,MeetingSix);
  Alarm.alarmRepeat(10,30,0,MeetingSeven);
  Alarm.alarmRepeat(11,00,0,MeetingEight);
  Alarm.alarmRepeat(15,00,0,MeetingNine);
  
}

void MeetingOne()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingTwo()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingThree()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingFour()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingFive()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingSix()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingSeven()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingEight()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void MeetingNine()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
 
}

void  loop()
{ 
 midnightState = digitalRead(midnightPin);  //reads the pulse
  if (midnightState == HIGH) {  
    setTime(23,59,0,1,1,10);  //sets time to one second before midnight
    Alarm.delay(0);
  }
  
}

why did you put the Alarm.delay call in the if statement?

alarms are only services when Alarm.Delay is called, but you only call this within the brief period of your midnight pulse.

Think of Alarm.delay as an enhanced version of the standard Arduino delay that while it is delaying also checks to see if an alarm has triggered.

//This program recieves a 1 second pulse at midnight for syncronization
//Alarms are referenced off that event
//The alarms sound a buzzer for one second on pin 13
//The circuit recieves a pulse on pin 2

#include "Time.h"
#include "TimeAlarms.h"

const int midnightPin= 2;
const int timerPin= 13;
const int buzzerPin= 4;


int midnightState=0;

void setup()
{
  pinMode(midnightPin, INPUT);
  pinMode(timerPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);

  Alarm.alarmRepeat(0,00,10,MeetingOne);
  Alarm.alarmRepeat(0,00,20,MeetingTwo);
  Alarm.alarmRepeat(0,00,40,MeetingThree);
  Alarm.alarmRepeat(0,00,59,MeetingFour);
  Alarm.alarmRepeat(9,30,0,MeetingFive);
  Alarm.alarmRepeat(10,00,0,MeetingSix);
  Alarm.alarmRepeat(10,30,0,MeetingSeven);
  Alarm.alarmRepeat(11,00,0,MeetingEight);
  Alarm.alarmRepeat(15,00,0,MeetingNine);

}

void MeetingOne()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingTwo()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingThree()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingFour()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingFive()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingSix()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingSeven()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingEight()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void MeetingNine()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH);
  Alarm.delay(90);
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);

}

void  loop()
{
 midnightState = digitalRead(midnightPin);  //reads the pulse
  if (midnightState == HIGH) {
    setTime(23,59,0,1,1,10);  //sets time to one second before midnight
    
  }
Alarm.delay(0);
}

I updated the code, but it is still acting funny.

but it is still acting funny.

Do you mean to say that it has exactly the same symptoms as before you made the change in loop?

If not, what are the symptoms?

edit: it would help you if you added some serial print statements in the alarm code to see which alarm was being triggered. You could also print the minute and second to show the time the alarm function was called.

When I turn it on, it cycles through all of the alarms correctly, but after I turn pin 2 high, it sounds the alarm about 6 times really fast.

The alarm logic does not expect time to run backwards and when you reset the clock back to the start of the previous day the scheduler can get confused.

If you want to adjust for drift, you could use the adjustTime function. This moves the clock forwards or backwards by a given number of seconds but does not disrupt the day and date.

Here is an untested fragment of code you could use when you get your sync pulse. To try this you should run it in real time- the drift calculation will not be realistic if you feed it sync pulses much more frequently than every 24 hours.

  long  drift = elapsedSecsToday(now()); 
  // if the elapsed time since previous midnight is a big number,
  // then its not quite reached midnight so the clock is slow
  // as small positive number means it running fast
  if(drift > 3600)  
    drift = drift - SECS_PER_DAY ;   // clock slow - this will be a negative number 
  // a positive number indicates that the clock has passed midnight so its fast 
  Serial.print("the drift in seconds is ");
  Serial.println(drift);
  adjustTime(-drift); // compensate by adding  seconds if slow, subtract if fast

BTW, where are your sync pulses coming from?

I used your suggestion on the serial.
The program works great, except for the fact that when the midnight pulse is recieved, the program cyles through all the alarms quickly. Is there a way to prevent this?
Also, when the power is turned on, the time is set to 0:00:00 automaticly. Is there a way to prevent this?

Here is the serial monitor:

Power Up:
0:00:00
0:00:01
0:00:02
0:00:03
..........


MIDNIGHT PULSE RECIEVED
MEETING ONE CALLED
MEETING TWO CALLED
MEETING THREE CALLED
MEETING FOUR CALLED
MEETING FIVE CALLED
MEETING SIX CALLED
1:00:05
1:00:06
1:00:07
.........

I am building a meeting alarm that will be tied in with an existing clock system. All the clocks are syncronised at midnight via 1 second DC pulse. Using this reference point I can make sure all the meetings are correctly timed compared to the clocks.

when the midnight pulse is recieved, the program cyles through all the alarms quickly.

Did you try the suggestions in my previous post.
also:

To try this you should run it in real time- the drift calculation will not be realistic if you feed it sync pulses much more frequently than every 24 hours.

when the power is turned on, the time is set to 0:00:00 automaticly. Is there a way to prevent this?

You can set the time in setup before you set the alarms

If only six of the nine alarms are triggering, read through the earlier posts in this thread that explained how to increase the number of alarms.

I used your suggestion. It works to set the time to 0:00:00, but the alarms do not trigger after the midnight reset. I also changed the number of alarms.

Here is the serial report...

0:00:00
0:00:01
0:00:02
0:00:03
0:00:04
0:00:05
0:00:06
0:00:07
0:00:08
0:00:09
MEETING CALL
MEETING ONE CALLED
0:00:11
0:00:12
0:00:13
0:00:14
0:00:15
0:00:16
0:00:17
0:00:18
0:00:19
MEETING CALL
MEETING TWO CALLED
0:00:21
0:00:22
0:00:23
0:00:24
0:00:25
0:00:26
0:00:27
0:00:28
0:00:29
MEETING CALL
MEETING THREE CALLED
0:00:31
0:00:32
0:00:33
0:00:34
0:00:35
0:00:36
0:00:37
0:00:38
0:00:39
MEETING CALL
MEETING FOUR CALLED
0:00:41
0:00:42
0:00:43
0:00:44
0:00:45
0:00:46
0:00:47
0:00:48
0:00:49
MEETING CALL
MEETING FIVE CALLED
0:00:51
0:00:52
0:00:53
0:00:54
0:00:55
0:00:56
0:00:57
0:00:58
MEETING CALL
MEETING SIX CALLED
0:01:00
0:01:01
0:01:02
0:01:03
0:01:04
0:01:05
0:01:06
0:01:07
0:01:08
0:01:09
MEETING CALL
MEETING SEVEN CALLED
0:01:11
0:01:12
0:01:13
0:01:14
0:01:15
0:01:16
0:01:17
0:01:18
0:01:19
MEETING CALL
MEETING EIGHT CALLED
0:01:21
0:01:22
0:01:23
0:01:24
0:01:25
0:01:26
0:01:27
0:01:28
0:01:29
MEETING CALL
MEETING NINE CALLED
0:01:31
0:01:32
0:01:33
0:01:34
0:01:35
0:01:36
0:01:37
0:01:38
0:01:39
the drift in seconds is 100
MIDNIGHT PULSE RECIEVED
0:00:00
0:00:01
0:00:02
0:00:03
0:00:04
0:00:05
0:00:06
0:00:07
0:00:08
0:00:09
0:00:10 //Meeting One is suppoused to go off here
0:00:11
0:00:12
0:00:13
0:00:14
0:00:15
0:00:16
0:00:17

Lets have a look, can you post the sketch

Here it is...

#include "Time.h"
#include "TimeAlarms.h"

const int midnightPin= 2;
const int timerPin= 13;
const int buzzerPin= 4;



int midnightState=0;

void setup()
{ 
  pinMode(midnightPin, INPUT);
  pinMode(timerPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  
  Alarm.alarmRepeat(0,00,10,MeetingOne); 
  Alarm.alarmRepeat(0,00,20,MeetingTwo); 
  Alarm.alarmRepeat(0,00,30,MeetingThree);
  Alarm.alarmRepeat(0,00,40,MeetingFour);
  Alarm.alarmRepeat(0,00,50,MeetingFive);
  Alarm.alarmRepeat(0,00,59,MeetingSix);
  Alarm.alarmRepeat(0,01,10,MeetingSeven);
  Alarm.alarmRepeat(0,01,20,MeetingEight);
  Alarm.alarmRepeat(0,01,30,MeetingNine);
  
  Serial.begin(9600);    
  
}

void MeetingOne()
{
  MeetingCall(); 
  Serial.println("MEETING ONE CALLED");    
}

void MeetingTwo()
{
  MeetingCall(); 
  Serial.println("MEETING TWO CALLED"); 
}

void MeetingThree()
{
  MeetingCall(); 
  Serial.println("MEETING THREE CALLED"); 
}

void MeetingFour()
{
  MeetingCall();
  Serial.println("MEETING FOUR CALLED");  
}

void MeetingFive()
{
  MeetingCall(); 
  Serial.println("MEETING FIVE CALLED"); 
}

void MeetingSix()
{
  MeetingCall();
  Serial.println("MEETING SIX CALLED");  
}

void MeetingSeven()
{
  MeetingCall(); 
  Serial.println("MEETING SEVEN CALLED"); 
}


void MeetingEight()
{
  MeetingCall(); 
  Serial.println("MEETING EIGHT CALLED"); 
}

void MeetingNine()
{
  MeetingCall(); 
  Serial.println("MEETING NINE CALLED"); 
}

void MeetingCall()
{
  digitalWrite(timerPin, HIGH);
  digitalWrite(buzzerPin, HIGH); 
  Alarm.delay(90);  
  digitalWrite(timerPin, LOW);
  Alarm.delay(910);
  digitalWrite(buzzerPin, LOW);
  Serial.println("MEETING CALL"); 
}

void  loop()
{ 
 midnightState = digitalRead(midnightPin);  //reads the pulse
  if (midnightState == HIGH) {  
    long  drift = elapsedSecsToday(now());
  // if the elapsed time since previous midnight is a big number,
  // then its not quite reached midnight so the clock is slow
  // as small positive number means it running fast
  if(drift > 3600)  
    drift = drift - SECS_PER_DAY ;   // clock slow - this will be a negative number
  // a positive number indicates that the clock has passed midnight so its fast
  Serial.print("the drift in seconds is ");
  Serial.println(drift);
  adjustTime(-drift); // compensate by adding  seconds if slow, subtract if fast   

    Serial.println("MIDNIGHT PULSE RECIEVED"); 
    
  }
 digitalClockDisplay();
 Alarm.delay(1000); // wait one second between clock display
}

void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  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);
}

The code looks ok.

Try it with the alarms set to a few minutes after midnight. Your drft is almost two minutes but the alarms are supposed to go off within a minute.

I wonder why you have so much drift. For a timekeeping application a board with a crystal would be more suitable because the drift would only be couple of seconds per day. What board are you using?