{"id":2263,"date":"2014-08-24T22:38:42","date_gmt":"2014-08-24T18:38:42","guid":{"rendered":"http:\/\/nayarweb.com\/blog\/?p=2263"},"modified":"2014-08-24T22:52:03","modified_gmt":"2014-08-24T18:52:03","slug":"moisture-sensing-with-raspberry-pi","status":"publish","type":"post","link":"https:\/\/nayarweb.com\/blog\/2014\/moisture-sensing-with-raspberry-pi\/","title":{"rendered":"Moisture Sensing with Raspberry Pi"},"content":{"rendered":"<p>I had bought a moisture sensor for quite a long time. But i didn&#8217;t have an Analog-to-Digital converter. I hence bought a MCP3008. But then, i didn&#8217;t have a breadboard and wires to connect my equipment. Today i finally managed to get everything and build it \ud83d\ude00<\/p>\n<p><a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/CameraZOOM-20140824201441062.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/CameraZOOM-20140824201441062-225x300.jpg\" alt=\"Moisture Sensing with Raspberry Pi\" width=\"225\" height=\"300\" class=\"aligncenter size-medium wp-image-2264\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/CameraZOOM-20140824201441062-225x300.jpg 225w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/CameraZOOM-20140824201441062-768x1024.jpg 768w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/CameraZOOM-20140824201441062.jpg 1920w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>I followed the guide found <a href=\"http:\/\/computers.tutsplus.com\/tutorials\/build-a-raspberry-pi-moisture-sensor-to-monitor-your-plants--mac-52875\" target=\"_blank\">here<\/a><\/p>\n<p>However, i was having a problem by importing the mcp3008 module in the Python shell. It was giving me the following error<\/p>\n<p><code>&gt;&gt;&gt; import mcp3008<br \/>\nTraceback (most recent call last):<br \/>\n  File \"&lt;stdin&gt;\", line 1, in &lt;module&gt;<br \/>\n  File \"mcp3008.py\", line 4, in &lt;module&gt;<br \/>\n    spi.open(0,1)<br \/>\nIOError: [Errno 2] No such file or directory<\/code><\/p>\n<p>Googling a bit, i came across the solution <a href=\"http:\/\/www.raspberrypi.org\/forums\/viewtopic.php?t=76461&#038;p=545861\" target=\"_blank\">here<\/a>. All i had to do was to remove the black listed SPI modules in <code>etc\/modprobe.d\/raspi-blacklist.conf<\/code><\/p>\n<p>I tested my setup by dipping the moisture sensor in water. When not in water, I would get a value of 1023. When fully dipped in water, it would be floating from 450 to 470. To get the readings in terms of percentage, i used the following formula\/code<\/p>\n<p><code>while True:<br \/>\n    m = mcp3008.readadc(5)<br \/>\n    m = (1024 - m)\/450.0 * 100<br \/>\n    print 'Moisture Level: ' + str(m)<br \/>\n    sleep(.5)<\/code><\/p>\n<p><a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/moisture_sensor.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/moisture_sensor-300x190.png\" alt=\"moisture_sensor\" width=\"300\" height=\"190\" class=\"aligncenter size-medium wp-image-2265\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/moisture_sensor-300x190.png 300w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2014\/08\/moisture_sensor.png 676w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Wo wo wo! Wait! Why using Windows???<\/p>\n<p>Long story! Infact, i&#8217;m using Putty on Windows 7, ssh&#8217;ed in a virtual Ubuntu Server in Virtual Box from which i shh&#8217;ed to my Raspberry Pi. To summarize: Windows 7 > Ubuntu Server (Virtual) > Raspberry Pi<\/p>\n<p>Who do such a thing? Because Putty was not able to connect directly to the Raspberry Pi. My Git Bash also failed for dunno what reason. Had to use a virtual Linux as middleman. lol \ud83d\ude00<\/p>\n<p>Neways, now i plan in getting a temperature and other sensors (pH maybe) in the mix too. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had bought a moisture sensor for quite a long time. But i didn&#8217;t have an Analog-to-Digital converter. I hence bought a MCP3008. But then, i didn&#8217;t have a breadboard and wires to connect my equipment. Today i finally managed to get everything and build it \ud83d\ude00 I followed the guide found here However, i &hellip; <a href=\"https:\/\/nayarweb.com\/blog\/2014\/moisture-sensing-with-raspberry-pi\/\" class=\"continue-reading\">Continue reading <span class=\"screen-reader-text\">Moisture Sensing with Raspberry Pi<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[167],"class_list":["post-2263","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/comments?post=2263"}],"version-history":[{"count":2,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2263\/revisions"}],"predecessor-version":[{"id":2267,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2263\/revisions\/2267"}],"wp:attachment":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/media?parent=2263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/categories?post=2263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/tags?post=2263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}