{"id":8309,"date":"2013-02-18T22:37:23","date_gmt":"2013-02-19T03:37:23","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=8309"},"modified":"2013-02-18T22:37:23","modified_gmt":"2013-02-19T03:37:23","slug":"usb-fart-detector-unfortunately","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2013\/02\/18\/usb-fart-detector-unfortunately\/","title":{"rendered":"USB Fart Detector (unfortunately)"},"content":{"rendered":"<p>It is a truth universally acknowledged, that an engineer in possession of a solid-state flammable gas detector, will shortly make a fart detector with it. I&#8217;m sorry, but call it childishness, simple-minded curiosity, or the results of a diet high in polysaccharides, but this is something I have to get out of my system. (It&#8217;s okay; I&#8217;ll waft the door.)<\/p>\n<p>This all started when our carbon monoxide detector decided it was past its best, and started to emit an ear-splitting shriek. Thinking there might be some cool parts inside, I took it apart. Inside, in amongst the other stuff, I found this:<\/p>\n<p><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2013\/02\/gas_sensor.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8310\" alt=\"gas sensor board\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2013\/02\/gas_sensor.jpg\" width=\"300\" height=\"279\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2013\/02\/gas_sensor.jpg 300w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2013\/02\/gas_sensor-160x148.jpg 160w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>Thankfully, David Cook of <a href=\"http:\/\/www.robotroom.com\/\">Robot Room<\/a> had once had the same idea as me (well, minus the puerile bits), and he documented the sensor board very well: <a href=\"http:\/\/www.robotroom.com\/Inside-Carbon-Monoxide-Detector-2.html\">Explosive Gas Detector Board<\/a>. Here are the four pins that you really need to get the thing going:<\/p>\n<pre> Pin # (from left)    Function\r\n===================  ==========\r\n       1              Vcc\r\n       2              \/Enable\r\n       3              \/Gas\r\n       5              Gnd<\/pre>\n<p>Pins 2 and 3 are <a href=\"https:\/\/en.wikipedia.org\/wiki\/Logic_level#Active_state\">active low<\/a> signals. To be typographically correct, I&#8217;d write them as <span style=\"text-decoration: overline;\">Enable<\/span> and <span style=\"text-decoration: overline;\">Gas<\/span>, but that&#8217;s hard to do in fixed-pitch ASCII. I can understand why the Gas signal should be active low (think about it; if the <a href=\"www.figarosensor.com\/products\/2611pdf.pdf\">Figaro TGS 2611<\/a> sensor fails or shorts, it will likely fail to an alarm state, so you&#8217;ll still be alive to curse the bloody noise that woke you at 03h00), but the Enable being active low? Dunno.<\/p>\n<p>I was hoping to have presented a little sketch for the <a href=\"http:\/\/digistump.com\/#digispark\">Digispark<\/a> that would have typed something unhelpful every time that gas was detected, but it was not to be. It seems that Macs and Digispark keyboard emulation is a thing of great wobbliness, so I had to resort to an Arduino and a serial connection.<\/p>\n<p>Here&#8217;s the code:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/*\r\n gas_detector - uses board scavenged from CO detector\r\n \r\n scruss - 2013-02-18 (unfortunately)\r\n *\/\r\n\r\nint gas     = 2;               \/\/ \/Gas line on pin 2\r\nint val     = 0;\r\nint lastval = 0;\r\n\r\nvoid setup() {                \r\n  pinMode(gas, INPUT);\r\n  Serial.begin(115200);\r\n}\r\n\r\nvoid loop() {\r\n  val = digitalRead(gas);\r\n  if (val != lastval) {\r\n    if (val == LOW) {          \/\/ LOW means gas detected\r\n      Serial.println(&quot;gas&quot;);\r\n      Serial.println();\r\n      delay(1000);             \/\/ wait 1s for air to clear\r\n    }\r\n  }\r\n  lastval = val;\r\n}\r\n<\/pre>\n<p>Before you ask, I tested the circuit by briefly hitting the button on a gas lighter. Honest.<\/p>\n<p>I&#8217;ll keep working on the Digispark; it&#8217;s such a nifty little device, and this is <em>such<\/em> a worthy project &#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is a truth universally acknowledged, that an engineer in possession of a solid-state flammable gas detector, will shortly make a fart detector with it. I&#8217;m sorry, but call it childishness, simple-minded curiosity, or the results of a diet high in polysaccharides, but this is something I have to get out of my system. (It&#8217;s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[2207,2625,109,2624,2626,229],"class_list":["post-8309","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-arduino","tag-digispark","tag-fart","tag-methane","tag-puerile","tag-usb"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-2a1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/8309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=8309"}],"version-history":[{"count":8,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/8309\/revisions"}],"predecessor-version":[{"id":8321,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/8309\/revisions\/8321"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=8309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=8309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=8309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}