{"id":261,"date":"2015-12-07T21:18:45","date_gmt":"2015-12-07T21:18:45","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=261"},"modified":"2020-10-12T16:22:15","modified_gmt":"2020-10-12T16:22:15","slug":"arduino-use-ds3231-clocks-alarm-to-activate-any-infrared-controllable-devise","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=261","title":{"rendered":"ARDUINO use DS3231 clock&#8217;s Alarm to activate any infrared controllable devise"},"content":{"rendered":"<h6><\/h6>\n<p>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.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_266\" style=\"width: 834px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/img_5193.jpg\" rel=\"attachment wp-att-266\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-266\" class=\"wp-image-266\" style=\"border: 5px solid #000000;\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/img_5193.jpg?w=300\" alt=\"IMG_5193\" width=\"824\" height=\"549\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/img_5193.jpg 5184w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/img_5193-300x200.jpg 300w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/img_5193-768x512.jpg 768w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/img_5193-1024x683.jpg 1024w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/a><p id=\"caption-attachment-266\" class=\"wp-caption-text\">ARDUINO use DS3231 clock&#8217;s Alarm to activate any infrared controllable devise<\/p><\/div>\n<p>To start with you will need to download and install the following library&#8217;s if you do not already have them:<\/p>\n<p>DS3231 library &#8211; \u00a0<a href=\"https:\/\/github.com\/rodan\/ds3231\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/rodan\/ds3231<\/a><\/p>\n<p>IRremote library &#8211; <a href=\"https:\/\/github.com\/z3t0\/Arduino-IRremote\/releases\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/z3t0\/Arduino-IRremote\/releases<\/a><\/p>\n<p>&nbsp;<\/p>\n<h1>Building the Circuit.<\/h1>\n<h2>Parts List:<\/h2>\n<p>#affiliate links#<\/p>\n<p><a href=\"http:\/\/www.dx.com\/p\/diy-transistor-components-pack-black-18-x-10pcs-362992?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">2N2222 transistor.<\/a><\/p>\n<p><a href=\"http:\/\/www.dx.com\/s\/ds3231?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">DS3231 RTC.<\/a><\/p>\n<p><a href=\"http:\/\/www.dx.com\/p\/5mm-ir-led-emitters-20-pack-2399?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">IR transmitter LED.<\/a><\/p>\n<p><a href=\"http:\/\/www.dx.com\/p\/universal-ir-infrared-receiver-module-black-20-pcs-169048?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">IR receiver.<\/a><\/p>\n<p><a href=\"http:\/\/www.dx.com\/s\/resistor?category=410&amp;Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">Resistor for IR receiver (if needed).<\/a><\/p>\n<p><a href=\"http:\/\/www.dx.com\/s\/arduino?category=472&amp;Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">ARDUINO board.<\/a><\/p>\n<p><a href=\"http:\/\/www.dx.com\/s\/bread board?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">Bread board.<\/a><\/p>\n<p><a href=\"http:\/\/www.dx.com\/s\/jumper wires?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires.<\/a><\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_269\" style=\"width: 831px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irclock.jpg\" rel=\"attachment wp-att-269\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-269\" class=\"wp-image-269\" style=\"border: 5px solid #000000;\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irclock.jpg?w=300\" alt=\"IRclock\" width=\"821\" height=\"561\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irclock.jpg 1308w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irclock-300x205.jpg 300w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irclock-768x525.jpg 768w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irclock-1024x700.jpg 1024w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/a><p id=\"caption-attachment-269\" class=\"wp-caption-text\">ARDUINO use DS3231 clock&#8217;s Alarm to activate any infrared controllable devise<\/p><\/div>\n<p>After you have mapped your remote for the buttons you want to use you can remove the IR (infrared receiver).<\/p>\n<h1>MAPPING THE REMOTE.<\/h1>\n<p>To map your remote open up the IRrecvDump under IRremote in examples.<\/p>\n<p>As you can see in the picture below I tried 3 different remots\u00a0(\u00a0RC5, NEC and a sony).\u00a0 For maping your remote we will only need the HEX number, bits and remote type.\u00a0 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).<\/p>\n<p>After you have finished you can move onto the next step&#8230;<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_271\" style=\"width: 815px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irdump.png\" rel=\"attachment wp-att-271\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-271\" class=\"wp-image-271\" style=\"border: 5px solid #000000;\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irdump.png?w=300\" alt=\"IRdump\" width=\"805\" height=\"483\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irdump.png 1280w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irdump-300x180.png 300w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irdump-768x461.png 768w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/12\/irdump-1024x614.png 1024w\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" \/><\/a><p id=\"caption-attachment-271\" class=\"wp-caption-text\">ARDUINO use DS3231 clock&#8217;s Alarm to activate any infrared controllable devise<\/p><\/div>\n<h1>THE CODE.<\/h1>\n<p>Below is the code you will want to use, just change the HEX numbers, bits and remote type.\u00a0 For the HEX number rember to add a 0x to the beginning of your decoded number to make it a HEX #.\u00a0 For the remote type just change\u00a0NEC in these lines to your type \u00a0\u00a0 irsend.sendNEC(0x482C609F , 32);\u00a0 then change the last # to your bits.\u00a0 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\u00a0but you can add as many as you want..<\/p>\n<p>\/\/ ARDUINO use DS3231 clock&#8217;s Alarm to activate any infrared controllable devise<\/p>\n<p>\/\/ during an alarm the INT pin of the RTC is pulled low<br \/>\n\/\/<br \/>\n\/\/ this is handy for minimizing power consumption for sensor-like devices,<br \/>\n\/\/ since they can be started up by this pin on given time intervals.<\/p>\n<p>#include &lt;Wire.h&gt;<br \/>\n#include &#8220;ds3231.h&#8221;<br \/>\n#define BUFF_MAX 256<br \/>\n#include &lt;IRremote.h&gt;<br \/>\nIRsend irsend;<br \/>\n\/\/ time when to wake up<br \/>\nuint8_t wake_HOUR = 14;\u00a0 \/\/set the hour you want for the alarm<br \/>\nuint8_t wake_MINUTE = 19; \/\/set the minute you want for the alarm<br \/>\nuint8_t wake_SECOND = 0;<\/p>\n<p>void set_alarm(void)<br \/>\n{<\/p>\n<p>\/\/ flags define what calendar component to be checked against the current time in order<br \/>\n\/\/ to trigger the alarm &#8211; see datasheet<br \/>\n\/\/ A1M1 (seconds) (0 to enable, 1 to disable)<br \/>\n\/\/ A1M2 (minutes) (0 to enable, 1 to disable)<br \/>\n\/\/ A1M3 (hour)\u00a0\u00a0\u00a0 (0 to enable, 1 to disable)<br \/>\n\/\/ A1M4 (day)\u00a0\u00a0\u00a0\u00a0 (0 to enable, 1 to disable)<br \/>\n\/\/ DY\/DT\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (dayofweek == 1\/dayofmonth == 0)<br \/>\nuint8_t flags[5] = { 0, 0, 0, 1, 1 };<\/p>\n<p>\/\/ set Alarm1<br \/>\nDS3231_set_a1(wake_SECOND, wake_MINUTE, wake_HOUR, 0, flags);<\/p>\n<p>\/\/ activate Alarm1<br \/>\nDS3231_set_creg(DS3231_INTCN | DS3231_A1IE);<br \/>\n}<\/p>\n<p>void setup()<br \/>\n{<br \/>\n\/\/Serial.begin(9600);<br \/>\nWire.begin();<br \/>\nDS3231_init(DS3231_INTCN);<br \/>\nDS3231_clear_a1f();<br \/>\nset_alarm();<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\ndelay(1000);<br \/>\nchar buff[BUFF_MAX];<br \/>\nunsigned long now = millis();<br \/>\nstruct ts t;<br \/>\nDS3231_get(&amp;t);<br \/>\n\/\/ display current time if serial is turned on<br \/>\nsnprintf(buff, BUFF_MAX, &#8221; %02d:%02d:%02d&#8221;,<br \/>\nt.hour, t.min, t.sec);<br \/>\n\/\/ Serial.println(buff);\u00a0 \/\/serial print time<br \/>\n\/\/send when alarm goes off\/\/<br \/>\nif (DS3231_triggered_a1()) {<br \/>\n\/\/ INT has been pulled low<br \/>\n\/\/disable this for loop if you only want to send the code 1 time\/\/<br \/>\nfor (int x = 0; x &lt; 20; x++)<br \/>\n{<br \/>\nirsend.sendNEC(0x482CE01F , 32); \/\/ the ir code you want to send<br \/>\ndelay(200);<br \/>\n}<br \/>\ndelay(5000);<br \/>\nfor (int x = 0; x &lt; 20; x++)<br \/>\n{<br \/>\nirsend.sendNEC(0x482C609F , 32);<br \/>\ndelay(200);<br \/>\n}<br \/>\nDS3231_clear_a1f();<\/p>\n<p>}<br \/>\n}<\/p>\n<h6>ARDUINO use DS3231 clock&#8217;s Alarm to activate any infrared controllable devise<\/h6>\n","protected":false},"excerpt":{"rendered":"<p>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. &nbsp; To start with you will need to download and &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=261\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":10,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-261","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=261"}],"version-history":[{"count":1,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/261\/revisions"}],"predecessor-version":[{"id":1586,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/261\/revisions\/1586"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/10"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}