187Views5Replies

Author Options:

RTC Alarm using serial monitor Answered

Hi,

I have an arduino UNO and RTC DS1307. I want to make an alarm that just displays on the serial monitor of arduino UNO. I can make the RTC show the right time on the serial monitor, however I want an alarm to go off on the serial monitor. Also, is there any way that I can change the alarm time on the serial monitor? Like I can type from my keyboard and the time changes?

One more question, How can I make arduino do multitasks using RTC. Like when the alarm goes off, it can run a small DC motor and also a Pizep Buzzer. 

Please help me with this, as I desperately need a help :((

5 Replies

user
lewisb42 (author)2013-03-02

Both Serial.read() and Serial.readBytes() will read keyboard input when the UNO is connected to PC via USB. Each key press is equal to a single byte, e.g., Serial.read() can read a single keyboard character at a time. Arduino isn't a multitasking environment per se but you can accomplish most things with a variant on this:

void loop()
{
   doFirstTask();
   doSecondTask();
   doThirdTask();
}

In your case it'd probably do something like:

void loop()
{
   updateDisplay(); // assuming you have some sort of clock display you're running...
   checkForAlarm();
}

where checkForAlarm() compares the RTC time against your alarm setting and, if it is alarm time, starts PWM to control the motor (and maybe another PWM to run the buzzer? I've never set one of those up before...)

Select as Best AnswerUndo Best Answer

user
Bam Boy (author)lewisb422013-03-02

hmmm I get the concept of setting the alarm. However how would u store the alarm or like where would you store the alarm? Like if I want the alarm to be turned off at a particular time, how would I do that and like where would I store it?

Select as Best AnswerUndo Best Answer

user
lewisb42 (author)Bam Boy2013-03-02

You could store the alarm in a regular variable (probably of type long, I'm guessing that's what the RTC uses to measure time). Easy, but the alarm won't be "remembered" if you turn the system off. If you need it remembered when off, you'll need to save it to EEPROM: http://arduino.cc/en/Reference/EEPROM

Select as Best AnswerUndo Best Answer

user
Bam Boy (author)lewisb422013-03-02

Sorry one more thing :S How should I use the Serial.read() and Serial.readBytes() commands? like how should I include that in my sketch? will it be possible if you show me in some example please :S

Select as Best AnswerUndo Best Answer

user
Bam Boy (author)lewisb422013-03-02

So basically what I do is to store the alarm values in the EEPROM memory and then compare it to the RTC time and whn they both become equal, then I can call the buzzer and motor functions? Is that the right concept?

Select as Best AnswerUndo Best Answer