Programming RTC DS3234 to turn pin HIGH/LOW on Arduino at certain day and time

I am new in using RTC. I have Deadon RTC "(DS3234) and Arduino Uno . Would like to use DS3234 to turn Arduino pins High/Low at certain time of the year. I would like to be let we say turn pin High from 1st of April 2016 at 6:00:00 till 1st of June 2016 6:00:00. Any help or example of such a sample code?

Thanks

Hello,

The easiest way is to convert the current date to a unix time, then compare it to the unix times of the dates you want.

For example:

Unix time of 1st of April 2016 is 1459468800
Unix time of 1st of June 2016 is 1464739200

if ( now() >= 1459468800UL && now() < 1464739200UL ) // now is between 1st of April 2016 and 1st of June 2016

See the Time library

Thanks. But How to use that with RTC DS3234?

Try this library which contains a function get_unixtime (you have to enable it in config.h).

Or you can use the Time library, which also deals with Unix times.

Using Time library then I dont need RTC DS3234? I can do that with Arduino not using RTC DS3234?

astronaut71:
Using Time library then I dont need RTC DS3234? I can do that with Arduino not using RTC DS3234?

You should keep your RTC! :slight_smile:

Actually, I think you would have to use a DS3234 library also, since it's SPI if I recall correctly. You would have to register the 3234 as a sync provider. It can be done, but if you're not comfortable with that, just use the library that guix linked to and manipulate the times yourself.

Ok.Thanks. I will try the first way and see how is going

Sorry for my ignorance but is there any code exapmle how convert the current date to a unix time with RTC DS3234?

Using the library in my link:

struct ts t;
DS3234_get( SS, &t ); // SS is pin 10 on most Arduino boards, 53 on Mega 2560. This is where you should have connected the CS pin of DS3234. Change if needed.
uint32_t now = get_unixtime( t );
Serial.println( now );

I can't test as I don't have a DS3234, also this library is the first one I found on google, there may be others, possibly better, Arduino libraries for DS3234.

An RTC library that doesn't have Unix time functions, is a library to run away from.

I got the current time in Unix time stamp with the code suggested from guix but its not the good one. I got this time stamp: 1907255969 which correspond to GMT: Sun, 09 Jun 2030 17:19:29 GMT. How can I get exactly "today" time stamp in Unix time?

Maybe this function "get_unixtime" is wrong... Or maybe your code is wrong...

Try with function "makeTime" from the Time library.

astronaut71:
I got the current time in Unix time stamp with the code suggested from guix but its not the good one. I got this time stamp: 1907255969 which correspond to GMT: Sun, 09 Jun 2030 17:19:29 GMT. How can I get exactly "today" time stamp in Unix time?

How can you be sure that your RTC is set correctly?

Im not sure that RTC is set correctly. How can assure that? How top set RTC?