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 ..

SDsolar
1,1753 gold badges11 silver badges35 bronze badges
asked Apr 25, 2017 at 16:06
1

2 Answers 2

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

answered Apr 26, 2017 at 3:29
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
 }
 }
}
answered Apr 25, 2017 at 16:40
1
  • Thanks for the quick reply .. I will try this and give you update , Thank you :D Commented Apr 25, 2017 at 16:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.