{"id":483,"date":"2010-04-17T10:39:54","date_gmt":"2010-04-17T14:39:54","guid":{"rendered":"http:\/\/nscadesign.ca\/mleblanc\/?p=483"},"modified":"2013-09-08T09:38:03","modified_gmt":"2013-09-08T12:38:03","slug":"testing-results-oil-level-fuel-gauge","status":"publish","type":"post","link":"https:\/\/blog.generaleccentric.net\/?p=483","title":{"rendered":"Testing Results: Oil Level Fuel Gauge"},"content":{"rendered":"<figure id=\"attachment_501\" aria-describedby=\"caption-attachment-501\" style=\"width: 100px\" class=\"wp-caption alignright\"><a href=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07513.jpg\" rel=\"lightbox[483]\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-501    \" title=\"DSC07513\" src=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07513-150x150.jpg\" alt=\"Reed Switch Sensor Array\" width=\"100\" height=\"100\" \/><\/a><figcaption id=\"caption-attachment-501\" class=\"wp-caption-text\">Reed Switch Sensor Array<\/figcaption><\/figure>\n<figure id=\"attachment_505\" aria-describedby=\"caption-attachment-505\" style=\"width: 100px\" class=\"wp-caption alignright\"><a href=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07522.jpg\" rel=\"lightbox[483]\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-505  \" title=\"DSC07522\" src=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07522-150x150.jpg\" alt=\"Testing the new sensor array\" width=\"100\" height=\"100\" \/><\/a><figcaption id=\"caption-attachment-505\" class=\"wp-caption-text\">Testing the new array<\/figcaption><\/figure>\n<p>In \u201c<a href=\"http:\/\/nscadesign.ca\/leblanc.blog\/?p=430\">Fun with Reed Switches<\/a>\u201d I mentioned that field testing of the Fuel Gauge system (as originally designed) was unsuccessful. I attributed the failure to the sensor array, which uses latching hall effect switches. I suspect that the hall effect does not work with extremely slow movements, such as that of the mechanical gauge on the oil tank.<\/p>\n<figure id=\"attachment_513\" aria-describedby=\"caption-attachment-513\" style=\"width: 100px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07531.jpg\" rel=\"lightbox[483]\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-513 \" title=\"DSC07531\" src=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07531-150x150.jpg\" alt=\"The new package\" width=\"100\" height=\"100\" \/><\/a><figcaption id=\"caption-attachment-513\" class=\"wp-caption-text\">The new package<\/figcaption><\/figure>\n<p>So I set out to replace the hall effect array with reed switches. The switches are surface-mounted on protoboard as described <a href=\"http:\/\/nscadesign.ca\/mleblanc\/?p=430\">here<\/a>.<\/p>\n<p>I also took the opportunity to completely rework the sender unit, including replacing the Arduino Mini Pro with a minimal ATMEGA8 chip using its internal oscillator. I&#8217;ll save my Mini Pro for another project that either requires the 16 MHz clock speed or its 16kb of program memory.<\/p>\n<figure id=\"attachment_514\" aria-describedby=\"caption-attachment-514\" style=\"width: 100px\" class=\"wp-caption alignright\"><a href=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07537.jpg\" rel=\"lightbox[483]\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-514   \" title=\"DSC07537\" src=\"http:\/\/nscadesign.ca\/leblanc.blog\/wp-content\/uploads\/2010\/04\/DSC07537-150x150.jpg\" alt=\"In situ\" width=\"100\" height=\"100\" \/><\/a><figcaption id=\"caption-attachment-514\" class=\"wp-caption-text\">In Situ<\/figcaption><\/figure>\n<p>In the original design, the entire unit enclosed the mechanical gauge. In the new design, the sensor array and the microcontroller\/transmitter are separate, connected by a ribbon cable.<\/p>\n<p>The Arduino sketch is also optimized (see below). Instead of nested if\/else conditionals, I&#8217;ve used a much more elegant method. For each sensor level, the system looks for a closed reed switch. When it finds one, it uses bitwise ANDing to match the number of the closed reed switch to a binary value. This binary value is then presented to the transmitter.<\/p>\n<pre>\/* Oil tank level using reed switches\r\n v. 2.01 Mar. 21 2010\r\n by Michael B. LeBlanc, NSCAD University\u00a0 *\/\r\n\r\nint level;\u00a0\u00a0 \/\/the reading from the oil tank gauge\r\n\r\nvoid setup() {\r\n pinMode(10, OUTPUT);\u00a0 \/\/ warning LED\r\n pinMode(11, OUTPUT);\u00a0 \/\/ D0 to TX\r\n pinMode(12, OUTPUT);\u00a0 \/\/ D1 to TX\r\n pinMode(13, OUTPUT);\u00a0 \/\/ D2 to TX\r\n Serial.begin(9600);\u00a0\u00a0 \/\/FOR TESTING\r\n}\r\n\r\nint sensorpin=0;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ What sensor pin we are checking\r\nbyte binary;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ This will hold the binary value of the sensor pin\r\nbyte D0;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ This will hold the one's bit\r\nbyte D1;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ This will hold the two's bit\r\nbyte D2;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ This will hold the four's bit\r\n\r\nvoid loop() {\r\n for (int i=0; i&lt;8; i++)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Start with sensor 0 and work up to sensor 7\r\n {\r\n sensorpin = i + 2;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Add 2 to calculate which Arduino sensor pin we want to check\r\n if (digitalRead(sensorpin) == HIGH)\u00a0 \/\/ If the switch is closed:\r\n {\r\n\r\n D0 = B001 &amp; i;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ bitwise AND the binary value of the sensor to mask the 1's bit\r\n\r\n digitalWrite(11,D0);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ write the value to Arduino pin 11\r\n\r\n D1 = B010 &amp; i;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ bitwise AND the binary value of the sensor to mask the 2's bit\r\n D1 = D1 &gt;&gt; 1;\r\n\r\n digitalWrite(12,D1);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ write the value to Arduino pin 12\r\n\r\n D2 = B100 &amp; i;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ bitwise AND the binary value of the sensor to mask the 4's bit\r\n D2 = D2 &gt;&gt; 2;\r\n\r\n digitalWrite(13,D2);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ write the value to Arduino pin 12\r\n }\r\n }\r\n\r\n delay(100);\r\n\r\n \/\/ blink LEDs on pin 10 if tank is empty\r\n if ((digitalRead(10)==LOW) &amp;&amp; (digitalRead(2) == HIGH))\r\n {\r\n digitalWrite(10,HIGH);\r\n delay(100);\r\n }\r\n else\r\n {\r\n digitalWrite(10,LOW);\r\n }\r\n}<\/pre>\n<p><a href=\"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.5\/ca\/\" rel=\"license\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft\" style=\"margin: 28px 8px;\" src=\"http:\/\/i.creativecommons.org\/l\/by-nc-sa\/2.5\/ca\/88x31.png\" alt=\"Creative Commons License\" width=\"88\" height=\"31\" \/><\/a><br \/>\nRemote Fuel Oil Tank Gauge by <a href=\"http:\/\/blog.generaleccentric.net\/?page_id=2\" rel=\"cc:attributionURL\">Michael B LeBlanc<\/a> is licensed under a <a href=\"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.5\/ca\/\" rel=\"license\">Creative Commons Attribution-Noncommercial-Share Alike 2.5 Canada License<\/a>.<br \/>\nContact the writer for permissions beyond the scope of this license.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In \u201cFun with Reed Switches\u201d I mentioned that field testing of the Fuel Gauge system (as originally designed) was unsuccessful. I attributed the failure to the sensor array, which uses latching hall effect switches. I suspect that the hall effect does not work with extremely slow movements, such as that of the mechanical gauge on &hellip; <a href=\"https:\/\/blog.generaleccentric.net\/?p=483\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Testing Results: Oil Level Fuel Gauge<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_links_to":"","_links_to_target":"","footnotes":""},"categories":[23,102,22],"tags":[40,42],"class_list":["post-483","post","type-post","status-publish","format-standard","hentry","category-arduino-electronics","category-design","category-electronics","tag-atmega8","tag-bitwise-arithmetic"],"_links":{"self":[{"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=\/wp\/v2\/posts\/483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=483"}],"version-history":[{"count":30,"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions"}],"predecessor-version":[{"id":530,"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions\/530"}],"wp:attachment":[{"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.generaleccentric.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}