{"id":1451,"date":"2017-11-29T10:08:26","date_gmt":"2017-11-29T10:08:26","guid":{"rendered":"http:\/\/www.sabulo.com\/sb\/?p=1451"},"modified":"2017-11-29T10:08:26","modified_gmt":"2017-11-29T10:08:26","slug":"accelerometer-that-tiny-workhorse","status":"publish","type":"post","link":"https:\/\/www.sabulo.com\/sb\/blender\/accelerometer-that-tiny-workhorse\/","title":{"rendered":"Accelerometer, that tiny workhorse"},"content":{"rendered":"<figure id=\"attachment_1452\" aria-describedby=\"caption-attachment-1452\" style=\"width: 300px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/InstagramCapture_849bc7de-7ad9-4777-83de-28a3f282f113.jpg\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-1452 size-medium\" src=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/InstagramCapture_849bc7de-7ad9-4777-83de-28a3f282f113-300x300.jpg?resize=300%2C300\" alt=\"The accelerometer chip (1 x 1 cm)\" width=\"300\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/InstagramCapture_849bc7de-7ad9-4777-83de-28a3f282f113.jpg?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/InstagramCapture_849bc7de-7ad9-4777-83de-28a3f282f113.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/InstagramCapture_849bc7de-7ad9-4777-83de-28a3f282f113.jpg?resize=768%2C768&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/InstagramCapture_849bc7de-7ad9-4777-83de-28a3f282f113.jpg?w=1024&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1452\" class=\"wp-caption-text\">The accelerometer chip (1 x 1 cm)<\/figcaption><\/figure>\n<p>Accelerometers are wondrous little devices that offer boundless possibilities&#8230; as soon as you figure out a need for them.<\/p>\n<p>For some time now, I have been thinking about a filament break detector for 3D printing. Filament comes in spools of 400m (1 kilogram) and they are usually hung on racks on which they rotate. The filament is fed to the printer via a small stepper motor turning a grooved feed wheel. If the filament breaks, or the feed wheel eats a notch into the filament, it will no longer enter the extruder, and the print fails. Usually the filament wire breaks if it has been exposed to air humidity for a long period &#8211; it is hygroscopic and becomes brittle.<\/p>\n<p>The printers are not aware of the filament feed. There is no detector for smooth feed, and consequently any hitch in feed will fail the print. I have thought of making an optoelectronic feed detector that would shine a light on the filament spool and detect its movement, but that would require a striped disc to be attached to the spool, as well as the actual reading device installed on the rack. Then I thought of a mechanical device that would ride on the filament itself and detect its movement via rotating discs, but that soon turned out to be too complex.<!--more--><\/p>\n<p>Then I happened upon the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Accelerometer\">accelerometer<\/a>. In essence it is three tiny damped masses on springs, aligned along the X, Y, and Z directions. Connecting it to 3.3V, and wiring each of the axis outputs to analog inputs of the Arduino, gives you a numerical value for each axis which you can read and act on. There are countless examples of code on how to do this wiring and coding, and I managed it within 15 minutes &#8211; my soldering skills were slowing me down as you have to solder wires to the tiny holes on the accelerometer.<\/p>\n<figure id=\"attachment_1453\" aria-describedby=\"caption-attachment-1453\" style=\"width: 300px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture.jpg\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-1453 size-medium\" src=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture-300x265.jpg?resize=300%2C265\" alt=\"Arduino Nano\" width=\"300\" height=\"265\" srcset=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture.jpg?resize=300%2C265&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture.jpg?resize=170%2C150&amp;ssl=1 170w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture.jpg?resize=150%2C133&amp;ssl=1 150w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture.jpg?w=594&amp;ssl=1 594w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1453\" class=\"wp-caption-text\">Arduino Nano<\/figcaption><\/figure>\n<p>The idea I had for the filament movement detector is simple: build an Arduino Nano based device that monitors the values of the X, Y and Z axis at 0.5 second intervals. When all three axis report no movement, start counting. When the no-move counter exceeds 10, indicating that the spool has not budged for 5 seconds, sound an alarm.<\/p>\n<p>To test this, I wrote a small program that uses the Serial Monitor feature of the Arduino to display the values. I found that the values are between 200 and 400 for each axis depending on its alignment to the ground. I was not that interested in the values as such, as I am more interested in the difference between two measurements 0.5 seconds apart. First I tested just the values, then added three variables to hold the previous value for each axis, and a delta value for the difference. The delta value is used to see the movement.<\/p>\n<p>As always, I tested this idea first on an Arduino Uno, because it is much easier to try things on it with its plug-in connectors and larger size. But for the actual device, I got hold of Arduino Nano, which has the same processing power in a much smaller package. It measures only 45mm x 14mm. It can be powered with a 6V battery and housed in a small 3D printed box. After the program has been sent to the Nano, you can disconnect the USB cable, and whenever you start the Nano, it will run that program.<\/p>\n<p>The parts list:<\/p>\n<ul>\n<li>Arduino Nano<\/li>\n<li>accelerometer<\/li>\n<li>piezoelectric buzzer<\/li>\n<li>switch<\/li>\n<li>6V battery<\/li>\n<li>pieces of wire of different colors<\/li>\n<\/ul>\n<p>The wiring is rather simple too: connect the +pole of the battery to the pin Vin (for Voltage in), and the -pole to the GND pin. Connect the GND of the accelerometer to the same GND on the Nano. Connect the VOD pin of the accelerometer to the 3.3V pin on the Arduino, and the X, Y and Z pins to the analog pins A0, A1, and A2 on the Arduino. The buzzer is wired to GND and digital pin 9. All connections are to be soldered so be careful not to fry the chip or the Nano with the soldering iron.<\/p>\n<p>The code is as follows:<\/p>\n<pre>int x, y, z;                    \/\/ axis values\r\nint xold, yold, zold = 0;       \/\/ previous axis values\r\nint xdelta, ydelta, zdelta = 0; \/\/ difference of the two\r\nint zerocount = 0;              \/\/ number of sero movement instances\r\nint sensitivity = 8;            \/\/ size of delta\r\nconst int buzzer = 9;           \/\/ buzzer to arduino pin 9\r\n\r\nvoid setup()\r\n{\r\n pinMode(buzzer, OUTPUT);       \/\/ Set buzzer - pin 9 as an output\r\n}\r\n\r\nvoid loop()\r\n{\r\n x = analogRead(3); \/\/ read analog input pin 0 for x axis value\r\n y = analogRead(4); \/\/ read analog input pin 1 for y axis value\r\n z = analogRead(5); \/\/ read analog input pin 1 for z axis value\r\n delay(500); \/\/ wait 500ms for next reading\r\n \r\n xdelta = x-xold; \/\/ difference between two readings\r\n ydelta = y-yold; \/\/ difference between two readings\r\n zdelta = z-zold; \/\/ difference between two readings\r\n\r\n if ((((abs(xdelta)&lt;sensitivity) &amp;&amp; ((abs(ydelta)&lt;sensitivity) &amp;&amp; ((abs(ydelta)&lt;sensitivity)))))) {\r\n zerocount++;\r\n }\r\n else {\r\n zerocount = 0;\r\n }\r\n xold = x;\r\n yold = y;\r\n zold = z;\r\n \r\n if (zerocount &gt; 10) {\r\n tone(buzzer, 1000); \/\/ Send 1KHz sound signal...\r\n delay(1000); \/\/ ...for 1 sec\r\n noTone(buzzer); \/\/ Stop sound...\r\n delay(1000); \/\/ ...for 1sec\r\n\r\n}\r\n else {\r\n }\r\n}\r\n\r\n<\/pre>\n<p>The ABS (absolute value) function in the delta merely accounts for the fact that the X value may be smaller than the xold value, resulting in a negative value, which would have to be handled separately. Doing the ABS gives me the difference between the values in positive integers which is all I need. The Sensitivity variable allowed me to calibrate the movement detection &#8211; the smaller the Sensitivity, the smaller the movement that counts as movement. If it wasn&#8217;t there, the buzzer would never sound, since even when flat on a table the values fluctuate between -3 and 3 in successive measurements.<\/p>\n<p>The zerocount variable is added to every time all three axis show movement less than the Sensitivity variable. This means the spool has to be at complete rest. In the C++ language on which the Arduino sketch language is based, the boolean AND is represented by two ampersands &#8220;&amp;&amp;&#8221;. Hence the comparison in the IF clause is<\/p>\n<pre>if ((((abs(xdelta)&lt;sensitivity) &amp;&amp; ((abs(ydelta)&lt;sensitivity) &amp;&amp; ((abs(ydelta)&lt;sensitivity))))))<\/pre>\n<p>That may look complex but it is actually rather like combining IF clauses in Excel, for example. The zerocount is reset to 0 whenever one axis shows a movement.<\/p>\n<figure id=\"attachment_1462\" aria-describedby=\"caption-attachment-1462\" style=\"width: 293px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture-1.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1462\" src=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture-1-293x300.jpg?resize=293%2C300\" alt=\"Device assembled\" width=\"293\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture-1.jpg?resize=293%2C300&amp;ssl=1 293w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture-1.jpg?resize=146%2C150&amp;ssl=1 146w, https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/uploads\/2017\/11\/Capture-1.jpg?w=665&amp;ssl=1 665w\" sizes=\"auto, (max-width: 293px) 100vw, 293px\" \/><\/a><figcaption id=\"caption-attachment-1462\" class=\"wp-caption-text\">Device assembled<\/figcaption><\/figure>\n<p>To house the device, I printed a small box with compartments, and will add a little latch to pin this box to the rotating spool. It is normal for the spool to not rotate for 2-3 seconds when the printer is moving the print head between layers and starting points on different layers, but 5 or more seconds will indicate a problem.<\/p>\n<p>I will print a cover later, but this is the essential device as it runs. See it in operation.<\/p>\n<p><iframe loading=\"lazy\" title=\"Accelerometer based filament sensor for 3D printers\" width=\"825\" height=\"464\" src=\"https:\/\/www.youtube.com\/embed\/PDXtki55R04?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<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1451\" class=\"pvc_stats all  \" data-element-id=\"1451\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/i0.wp.com\/www.sabulo.com\/sb\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif?resize=16%2C16&#038;ssl=1\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Accelerometers are wondrous little devices that offer boundless possibilities&#8230; as soon as you figure out a need for them. For &hellip; <a href=\"https:\/\/www.sabulo.com\/sb\/blender\/accelerometer-that-tiny-workhorse\/\" class=\"more-link\">More <span class=\"screen-reader-text\">Accelerometer, that tiny workhorse<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1451\" class=\"pvc_stats all  \" data-element-id=\"1451\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/www.sabulo.com\/sb\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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","enabled":false},"version":2}},"categories":[63,48,6,60],"tags":[],"class_list":["post-1451","post","type-post","status-publish","format-standard","hentry","category-accelerometer","category-arduino","category-blender","category-colido-diy-priinter"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6vhqE-np","_links":{"self":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts\/1451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/comments?post=1451"}],"version-history":[{"count":10,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts\/1451\/revisions"}],"predecessor-version":[{"id":1464,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/posts\/1451\/revisions\/1464"}],"wp:attachment":[{"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/media?parent=1451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/categories?post=1451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sabulo.com\/sb\/wp-json\/wp\/v2\/tags?post=1451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}