ARDUINO use DS3231 clock’s Alarm to activate any infrared controllable devise

This tutorial will show you how to use a DS3231 real time clock with your ARDUINO to activate IR (infrared) functions of electronic devises when the clocks alarm is triggered.

 

IMG_5193

ARDUINO use DS3231 clock’s Alarm to activate any infrared controllable devise

To start with you will need to download and install the following library’s if you do not already have them:

DS3231 library –  https://github.com/rodan/ds3231

IRremote library – https://github.com/z3t0/Arduino-IRremote/releases

 

Building the Circuit.

Parts List:

2N2222 transistor.

DS3231 RTC.

IR transmitter LED.

IR receiver.

Resistor for IR receiver (if needed).

ARDUINO board.

Bread board.

Jumper wires.

 

IRclock

ARDUINO use DS3231 clock’s Alarm to activate any infrared controllable devise

After you have mapped your remote for the buttons you want to use you can remove the IR (infrared receiver).

MAPPING THE REMOTE.

To map your remote open up the IRrecvDump under IRremote in examples.

As you can see in the picture below I tried 3 different remots ( RC5, NEC and a sony).  For maping your remote we will only need the HEX number, bits and remote type.  Push each buton on your remote that you will want to use for this project and write down the results (you can also copy and past the info into notepad).

After you have finished you can move onto the next step…

 

IRdump

ARDUINO use DS3231 clock’s Alarm to activate any infrared controllable devise

THE CODE.

Below is the code you will want to use, just change the HEX numbers, bits and remote type.  For the HEX number rember to add a 0x to the beginning of your decoded number to make it a HEX #.  For the remote type just change NEC in these lines to your type    irsend.sendNEC(0x482C609F , 32);  then change the last # to your bits.  You will have to do this to all the send lines you are going to use, I have two IR send lines in this sketch but you can add as many as you want..

// ARDUINO use DS3231 clock’s Alarm to activate any infrared controllable devise

// during an alarm the INT pin of the RTC is pulled low
//
// this is handy for minimizing power consumption for sensor-like devices,
// since they can be started up by this pin on given time intervals.

#include <Wire.h>
#include “ds3231.h”
#define BUFF_MAX 256
#include <IRremote.h>
IRsend irsend;
// time when to wake up
uint8_t wake_HOUR = 14;  //set the hour you want for the alarm
uint8_t wake_MINUTE = 19; //set the minute you want for the alarm
uint8_t wake_SECOND = 0;

void set_alarm(void)
{

// flags define what calendar component to be checked against the current time in order
// to trigger the alarm – see datasheet
// A1M1 (seconds) (0 to enable, 1 to disable)
// A1M2 (minutes) (0 to enable, 1 to disable)
// A1M3 (hour)    (0 to enable, 1 to disable)
// A1M4 (day)     (0 to enable, 1 to disable)
// DY/DT          (dayofweek == 1/dayofmonth == 0)
uint8_t flags[5] = { 0, 0, 0, 1, 1 };

// set Alarm1
DS3231_set_a1(wake_SECOND, wake_MINUTE, wake_HOUR, 0, flags);

// activate Alarm1
DS3231_set_creg(DS3231_INTCN | DS3231_A1IE);
}

void setup()
{
//Serial.begin(9600);
Wire.begin();
DS3231_init(DS3231_INTCN);
DS3231_clear_a1f();
set_alarm();
}

void loop()
{
delay(1000);
char buff[BUFF_MAX];
unsigned long now = millis();
struct ts t;
DS3231_get(&t);
// display current time if serial is turned on
snprintf(buff, BUFF_MAX, ” %02d:%02d:%02d”,
t.hour, t.min, t.sec);
// Serial.println(buff);  //serial print time
//send when alarm goes off//
if (DS3231_triggered_a1()) {
// INT has been pulled low
//disable this for loop if you only want to send the code 1 time//
for (int x = 0; x < 20; x++)
{
irsend.sendNEC(0x482CE01F , 32); // the ir code you want to send
delay(200);
}
delay(5000);
for (int x = 0; x < 20; x++)
{
irsend.sendNEC(0x482C609F , 32);
delay(200);
}
DS3231_clear_a1f();

}
}

ARDUINO use DS3231 clock’s Alarm to activate any infrared controllable devise