{"id":1594,"date":"2015-02-28T13:48:30","date_gmt":"2015-02-28T12:48:30","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=1594"},"modified":"2015-02-28T13:48:30","modified_gmt":"2015-02-28T12:48:30","slug":"water-impulse-counter-and-arduino-part-4-last","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=1594","title":{"rendered":"Water impulse counter and Arduino : Part 4 (Last)"},"content":{"rendered":"<p>This is the last article about my water impulse counter project.<br \/>\n3 previous articles can be found <a href=\"https:\/\/labalec.fr\/erwan\/?s=water+impulse+counter&#038;searchsubmit=\" target=\"_blank\">here <\/a>. <\/p>\n<p>The last issue I encountered was about electro magnetic disturbances (probably my gaz heater nearby).<br \/>\nI initially planned to detect FALLING impulses (high to low, low meaning the reed switch is closed).<br \/>\nBut about 4 times per hour, i detected a falling impulse, and this even the water circuit closed !<\/p>\n<p>I therefore decided to review my code in the interrupt function now based on a CHANGE event (no more FALLING).<\/p>\n<p><code><br \/>\nvoid IntChange() {<br \/>\n if (digitalRead(SWITCHPIN)==LOW) {<br \/>\n  start=millis();<br \/>\n  change=false;<br \/>\n} else {<br \/>\n  if (start>0) {<br \/>\n    pulse=millis()-start;<br \/>\n    start=0;<br \/>\n    change=true;<br \/>\n  } else {<br \/>\n    start=0;<br \/>\n    change=false;<br \/>\n  }\/\/if (start>0)<br \/>\n} \/\/if (digitalRead(SWITCHPIN)==LOW) {<br \/>\n}<br \/>\n<\/code><\/p>\n<p>And this proves to work perfectly now \ud83d\ude42<br \/>\nSee graph below.<br \/>\n<a href=\"http:\/\/imgur.com\/MXdpuLH\"><img decoding=\"async\" src=\"http:\/\/i.imgur.com\/MXdpuLH.png\" title=\"source: imgur.com\" \/><\/a><\/p>\n<p>The whole code can be found <a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2015\/02\/attachinterrupt_0.txt\" target=\"_blank\">here<\/a>.<br \/>\nit includes a web server (for my domotic box to query), a sd card reader (to store the counter value between power off), an interrupt handler.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the last article about my water impulse counter project. 3 previous articles can be found here . The last issue I encountered was about electro magnetic disturbances (probably my gaz heater nearby). I initially planned to detect FALLING impulses (high to low, low meaning the reed switch is closed). But about 4 times <a href='https:\/\/labalec.fr\/erwan\/?p=1594' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[72],"class_list":["post-1594","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-water-impulse-counter","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1594"}],"version-history":[{"count":1,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1594\/revisions"}],"predecessor-version":[{"id":1596,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1594\/revisions\/1596"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}