2

I'm working on my system and I have to make arduino repeat such action or block of code if its the set time .. I'm using DS3231 module to track date and time .Example If I set the time in 6:00 AM and when the arduino reads the module and it turns out that its already 6:00 AM the arduino will now execute some action or the block of code .. sorry for my english ..

1

Check out how the DS3231 Alarm functions work. They will interrupt even a delay() statement. At the appointed time the specified function is called.

This same question was answered here:

How to set Alarms on the DS3231 easily?

For another way to see how to set this up, let me refer you to this article:

Build Programmable Time-based Switches Using a Real Time Clock

The code can be downloaded Here

| improve this answer | |
0

This example shows a simple way of conditionally processing an event at a given time of day, once per day. The example allows 59 seconds of accuracy but in reality if the Arduino is free to read the time this will happen almost exactly at 6.00am.

You need to declare and populate currentTime and currentDate by reading the DS3231. This example assumes the currentTime is in millis.

unsigned long action1_LastDoneDate;
unsigned long TIME_600AM = 21600000; // millis 6.00 am = 6*60*60*1000
unsigned long TIME_601AM = 21660000; // millis 6.01 am


void setup()
{
 action1_LastDoneDate=0L;
}

void loop()
{
 //make sure we have not processed today
 if (action1_LastDoneDate != currentDate)  
 { 
   //make sure the time is within range
   if (currentTime>=TIME_600AM && currentTime<TIME_601AM)
   {
     //save off the current date so we don't try do process this alarm again
     action1LastDoneDate = currentDate;
     //now do the 6am stuff
   }
 }
}
| improve this answer | |
  • Thanks for the quick reply .. I will try this and give you update , Thank you :D – kaisar Great Apr 25 '17 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.