{"id":1126,"date":"2019-02-24T16:27:52","date_gmt":"2019-02-24T16:27:52","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=1126"},"modified":"2019-10-20T18:25:21","modified_gmt":"2019-10-20T18:25:21","slug":"arduino-countdown-timer-with-alarm-kitchen-timer","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=1126","title":{"rendered":"ARDUINO Countdown Timer with alarm (kitchen timer)"},"content":{"rendered":"<h1>Today I&#8217;ll show you how you can put together a countdown timer using an ARDUINO NANO microcontroller. Works great as a kitchen timer.<\/h1>\n<p><iframe loading=\"lazy\" title=\"ARDUINO Countdown Timer with alarm (kitchen timer)\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/rzxisoU9D6c?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h1 class=\"entry-title\"><a href=\"https:\/\/zhutarduino.wordpress.com\/arduino-projects\/how-to-set-up-and-use-a-1602-i2c-serial-lcd-with-your-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to set up and use a 1602 I2C serial LCD with your\u00a0ARDUINO.<\/a><\/h1>\n<h2>Parts List:<\/h2>\n<p>affiliate links:<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/product\/B0711WLVP9\/ref=as_li_qf_asin_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0711WLVP9&amp;linkId=da2da76b2b4c65c76df944c8cdb18612\" target=\"_blank\" rel=\"noopener noreferrer\">1602 I2C LCD<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=arduino nano&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=198a9eeff71d2adc3637ba0e0e26df79\" target=\"_blank\" rel=\"noopener noreferrer\">ARDUINO NANO<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=ARDUINO Nano Terminal adapter board&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=f8b5718d6b1aa33f28b0f42d19479094\" target=\"_blank\" rel=\"noopener noreferrer\">ARDUINO Nano Terminal adapter board<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=Rotary Encoder&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=9c1e0d16e8cc068a399737383493c546\" target=\"_blank\" rel=\"noopener noreferrer\">Rotary Encoder<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=Push Button&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=05c83bd62aab3d95255a38a16757fa15\" target=\"_blank\" rel=\"noopener noreferrer\">Push Button<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=Piezo&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=733c42a849c27f3c084b695cb092b22d\" target=\"_blank\" rel=\"noopener noreferrer\">Piezo<\/a><\/p>\n<h1><a href=\"https:\/\/www.thingiverse.com\/thing:3434220\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download the files to 3D print the enclosure box&#8230;<\/a><\/h1>\n<h2>ARDUINO CODE:<\/h2>\n<p>#include &lt;Wire.h&gt;<br \/>\n#include &lt;LiquidCrystal_I2C.h&gt;<br \/>\nLiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); \/\/ Set the LCD I2C address<br \/>\n#define Start 4 \/\/ start stop button<br \/>\nint hours = 0;<br \/>\nint minutes = 0;<br \/>\nint seconds = 0;<br \/>\nboolean timeState = false;<br \/>\n#define encoderPinA 2 \/\/ right<br \/>\n#define encoderPinB 3 \/\/ left<br \/>\n#define encoderButton 5 \/\/ switch<br \/>\nint HMS = 1;<br \/>\nint encoderPos = 0; \/\/ a counter for the dial<br \/>\nunsigned int lastReportedPos = 1; \/\/ change management<br \/>\nstatic boolean rotating = false; \/\/ debounce management<br \/>\nboolean A_set = false;<br \/>\nboolean B_set = false;<\/p>\n<p>void setup() {<\/p>\n<p>pinMode(Start, INPUT_PULLUP);<br \/>\npinMode(encoderPinA, INPUT_PULLUP); \/\/enabling pullups<br \/>\npinMode(encoderPinB, INPUT_PULLUP);<br \/>\npinMode(encoderButton, INPUT_PULLUP);<br \/>\nattachInterrupt(0, doEncoderA, CHANGE); \/\/pin 2<br \/>\nattachInterrupt(1, doEncoderB, CHANGE); \/\/pin 3<br \/>\nSerial.begin(9600); \/\/ output<br \/>\nlcd.begin(16, 2); \/\/ initialize the lcd for 16 chars 2 lines, turn on backlight<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(0, 0);<br \/>\nlcd.print(&#8220;COUNT DOWN TIMER&#8221;);<br \/>\nlcd.setCursor(4, 1);<br \/>\nlcd.print(&#8220;00:00:00&#8221;);<\/p>\n<p>}<\/p>\n<p>void loop() {<\/p>\n<p>if (digitalRead(encoderButton) == LOW)<br \/>\n{<br \/>\nHMS = HMS + 1;<br \/>\nif (HMS == 4)<br \/>\n{<br \/>\nHMS = 1;<br \/>\n}<br \/>\ndelay(1000);<br \/>\n}<br \/>\nrotating = true; \/\/ reset the debouncer<br \/>\nencoderPos = constrain(encoderPos, -1, 1);<br \/>\nif (lastReportedPos != encoderPos) {<\/p>\n<p>if (HMS == 1) {<br \/>\nhours = hours + encoderPos;<br \/>\nhours = constrain(hours, 0, 48);<br \/>\n}<br \/>\nelse if (HMS == 2) {<br \/>\nminutes = minutes + encoderPos;<br \/>\nminutes = constrain(minutes, 0, 60);<br \/>\n}<br \/>\nelse if (HMS == 3) {<br \/>\nseconds = seconds + encoderPos;<br \/>\nseconds = constrain(seconds, 0, 60);<br \/>\n}<br \/>\n\/\/ Serial.println(encoderPos); \/\/ for testing<br \/>\n\/\/ Serial.print(&#8220;hours &#8220;);<br \/>\n\/\/ Serial.println(hours);<br \/>\n\/\/ Serial.print(&#8220;minutes &#8220;);<br \/>\n\/\/ Serial.println(minutes);<br \/>\n\/\/ Serial.print(&#8220;seconds &#8220;);<br \/>\n\/\/ Serial.println(seconds);<br \/>\n\/\/ Serial.println(&#8221; &#8220;);<br \/>\nlcd.setCursor(4, 1);<br \/>\nif (hours &lt;= 9)<br \/>\n{<br \/>\nlcd.print(&#8220;0&#8221;);<br \/>\n}<br \/>\nlcd.print(hours);<br \/>\nlcd.print(&#8220;:&#8221;);<br \/>\nif (minutes &lt;= 9)<br \/>\n{<br \/>\nlcd.print(&#8220;0&#8221;);<br \/>\n}<br \/>\nlcd.print(minutes);<br \/>\nlcd.print(&#8220;:&#8221;);<br \/>\nif (seconds &lt;= 9)<br \/>\n{<br \/>\nlcd.print(&#8220;0&#8221;);<br \/>\n}<br \/>\nlcd.print(seconds);<br \/>\nencoderPos = 0;<br \/>\nlastReportedPos = encoderPos;<\/p>\n<p>}<br \/>\nif (digitalRead(Start) == LOW) { \/\/start count down timer<br \/>\ntimeState = true;<br \/>\n\/\/delay(1000);<br \/>\nwhile (timeState == true) {<br \/>\nif (minutes == 0 &amp;&amp; hours &gt;= 1) {<br \/>\nminutes = 60;<br \/>\nhours = hours &#8211; 1;<br \/>\n}<br \/>\nif (seconds == 0 &amp;&amp; minutes &gt;= 1) {<br \/>\nseconds = 60;<br \/>\nminutes = minutes &#8211; 1;<br \/>\n}<br \/>\nelse if (minutes == 0 &amp;&amp; hours == 0 &amp;&amp; seconds == 0) { \/\/count down alarm<br \/>\nwhile (timeState == true) {<br \/>\ntone(11, 600, 250);<br \/>\ndelay(250);<br \/>\ntone(11, 800, 250);<br \/>\ndelay(250);<br \/>\nif (digitalRead(Start) == LOW) { \/\/ turn alarm off<br \/>\ntimeState = false;<br \/>\nseconds = 1; \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(0, 0);<br \/>\nlcd.print(&#8220;COUNT DOWN TIMER&#8221;);<br \/>\nlcd.setCursor(4, 1);<br \/>\nlcd.print(&#8220;00:00:00&#8221;);<\/p>\n<p>break;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\ndelay(992); \/\/ delay for keping time master setting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<br \/>\nseconds = seconds &#8211; 1;<br \/>\n\/\/Serial.print(&#8220;hours &#8220;); \/\/ for testing<br \/>\n\/\/Serial.println(hours);<br \/>\n\/\/Serial.print(&#8220;minutes &#8220;);<br \/>\n\/\/Serial.println(minutes);<br \/>\n\/\/Serial.print(&#8220;seconds &#8220;);<br \/>\n\/\/ Serial.println(seconds);<br \/>\n\/\/Serial.println(&#8221; &#8220;);<\/p>\n<p>lcd.setCursor(4, 1);<br \/>\nif (hours &lt;= 9)<br \/>\n{<br \/>\nlcd.print(&#8220;0&#8221;);<br \/>\n}<br \/>\nlcd.print(hours);<br \/>\nlcd.print(&#8220;:&#8221;);<br \/>\nif (minutes &lt;= 9)<br \/>\n{<br \/>\nlcd.print(&#8220;0&#8221;);<br \/>\n}<br \/>\nlcd.print(minutes);<br \/>\nlcd.print(&#8220;:&#8221;);<br \/>\nif (seconds &lt;= 9)<br \/>\n{<br \/>\nlcd.print(&#8220;0&#8221;);<br \/>\n}<br \/>\nlcd.print(seconds);<\/p>\n<p>if (digitalRead(Start) == LOW) {<br \/>\ndelay(1000);<br \/>\ntimeState = false;<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ Interrupt on A changing state<br \/>\nvoid doEncoderA() {<br \/>\n\/\/ debounce<br \/>\nif ( rotating ) delay (1); \/\/ wait a little until the bouncing is done<\/p>\n<p>\/\/ Test transition, did things really change?<br \/>\nif ( digitalRead(encoderPinA) != A_set ) { \/\/ debounce once more<br \/>\nA_set = !A_set;<\/p>\n<p>\/\/ adjust counter + if A leads B<br \/>\nif ( A_set &amp;&amp; !B_set )<br \/>\nencoderPos = 1;<\/p>\n<p>rotating = false; \/\/ no more debouncing until loop() hits again<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ Interrupt on B changing state<br \/>\nvoid doEncoderB() {<br \/>\nif ( rotating ) delay (1);<br \/>\nif ( digitalRead(encoderPinB) != B_set ) {<br \/>\nB_set = !B_set;<br \/>\n\/\/ adjust counter &#8211; 1 if B leads A<br \/>\nif ( B_set &amp;&amp; !A_set )<br \/>\nencoderPos = -1;<\/p>\n<p>rotating = false;<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I&#8217;ll show you how you can put together a countdown timer using an ARDUINO NANO microcontroller. Works great as a kitchen timer. How to set up and use a 1602 I2C serial LCD with your\u00a0ARDUINO. Parts List: affiliate links: &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=1126\">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-1126","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1126","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=1126"}],"version-history":[{"count":3,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1126\/revisions"}],"predecessor-version":[{"id":1490,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1126\/revisions\/1490"}],"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=1126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}