{"id":350,"date":"2016-06-20T04:49:00","date_gmt":"2016-06-20T04:49:00","guid":{"rendered":"http:\/\/authorjcnelson.com\/?p=350"},"modified":"2016-06-21T16:02:48","modified_gmt":"2016-06-21T16:02:48","slug":"adventures-with-arduino","status":"publish","type":"post","link":"https:\/\/authorjcnelson.com\/?p=350","title":{"rendered":"Adventures with Arduino"},"content":{"rendered":"<p>As you may have noticed in the previous post, I like hydroponic gardening. I like it because I just harvested all my brocoli, and I have a cauliflower that is turning into a monster in the waterfarm. \u00a0But one thing has been a constant question for me: Could I produce more?<\/p>\n<p>If you look at hydroponic forums, you&#8217;ll find that despite my success with a constant basic nutrient formula, there are people who post week by week, species specific formulas that require a large amount of tuning and care to produce the &#8220;right&#8221; mix. The more I thought about it, the more I thought, &#8220;You know what does things like this well? \u00a0Computers.&#8221;<\/p>\n<p>But this is a case of interfacing a computer (software) to the real world (hardware), and one thing that does that really well is the <a href=\"https:\/\/www.arduino.cc\">Arduino<\/a> platform. Arduino is a microcontroller board with an open-hardware definition. That means that anyone can (and does) produce their own arduino-compatible boards. And along with these boards, people have designed an impressive number of &#8220;shields&#8221; that allow the microcontroller to do fun things like control stepper motors, relays, and so on.<\/p>\n<p>In this case, what I want to build is a microcontroller that, when given a particular formula, dispenses the right amount of each nutrient and mixes it.<\/p>\n<p>So&#8230;I began hacking.<\/p>\n<p>Disclaimer: I&#8217;m a software guy. Give me a problem that I can solve with code, I&#8217;ll go at it. Hardware was new to me, even basic hardware problems like this, using pre-made components. So I learned.<\/p>\n<p>First off, I&#8217;m using the<a href=\"http:\/\/seeduino relay shield\"> seeduino relay shield<\/a>, which lets the arduino microcontroller turn on relays. Relays are in essence electric switches where a small load (like a microcontroller) can control a large one (like, say, a fan or motor). \u00a0In this case, what I wanted to control were called &#8220;normally closed pinch valves.&#8221; These can cost &gt; 120 dollars, and that&#8230;well, I write books. That should tell you my budget doesn&#8217;t include $120 valves when I&#8217;d need three.<\/p>\n<p>Salvage to the rescue! I found a seller on ebay selling used ones in lots of four, and made an offer. Three weeks later, I had three functioning pinch valves (all I needed) and one dud. To be fair, the seller said they were used, and a 1:4 failure rate for salvage parts ain&#8217;t all that bad.<\/p>\n<p>I wired up the relays using Molex pin connectors and ran some test code that should have turned each relay on and off in a cycle. With no valves connected, it ran fine.<\/p>\n<p>With ONE valve connected, it ran fine.<\/p>\n<p>With more than one, any one, the first relay would close, and the arduino would reset.<\/p>\n<p><strong>Frustrating.<\/strong><\/p>\n<p>So, first off I checked all the normal things: Was I drawing too much power? No.<\/p>\n<p>Was I shorting out? No.<\/p>\n<p>Next I started checking the voltages as each valve opened and closed, and I noticed something disturbing &#8211; when a relay closed (aka switched off), I got a wicked spike. \u00a0Turns out, this is a known thing. The solution was to use a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Flyback_diode\">flyback diode<\/a> to kill the EMF spike. This let me get two relays working, but not all three. I found a post recommending a smoothing capacitor, so I added one, and presto&#8230;three pinch valves, all operating on command.<\/p>\n<p>Next phase involves building: I need to rig three jars with tubing that goes through the valves and build the code that will control them for real. To begin with, I&#8217;ll manually calibrate and just do one set formula.<\/p>\n<p>So, I&#8217;m digging out the hole saws and mocking up my setup. One step at a time!<\/p>\n<p><a href=\"https:\/\/authorjcnelson.com\/wp-content\/uploads\/2016\/06\/arduino.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-351\" src=\"https:\/\/authorjcnelson.com\/wp-content\/uploads\/2016\/06\/arduino-225x300.jpg\" alt=\"arduino\" width=\"225\" height=\"300\" srcset=\"https:\/\/authorjcnelson.com\/wp-content\/uploads\/2016\/06\/arduino-225x300.jpg 225w, https:\/\/authorjcnelson.com\/wp-content\/uploads\/2016\/06\/arduino.jpg 720w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As you may have noticed in the previous post, I like hydroponic gardening. I like it because I just harvested all my brocoli, and I&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/authorjcnelson.com\/?p=350\">Continue reading<span class=\"screen-reader-text\">Adventures with Arduino<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,19],"tags":[],"class_list":["post-350","post","type-post","status-publish","format-standard","hentry","category-arduino","category-gardening","entry"],"_links":{"self":[{"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=\/wp\/v2\/posts\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=350"}],"version-history":[{"count":3,"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=\/wp\/v2\/posts\/350\/revisions"}],"predecessor-version":[{"id":354,"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=\/wp\/v2\/posts\/350\/revisions\/354"}],"wp:attachment":[{"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/authorjcnelson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}