Moisture Sensing with Raspberry Pi

I had bought a moisture sensor for quite a long time. But i didn’t have an Analog-to-Digital converter. I hence bought a MCP3008. But then, i didn’t have a breadboard and wires to connect my equipment. Today i finally managed to get everything and build it 😀

Moisture Sensing with Raspberry Pi

I followed the guide found here

However, i was having a problem by importing the mcp3008 module in the Python shell. It was giving me the following error

>>> import mcp3008
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mcp3008.py", line 4, in <module>
spi.open(0,1)
IOError: [Errno 2] No such file or directory

Googling a bit, i came across the solution here. All i had to do was to remove the black listed SPI modules in etc/modprobe.d/raspi-blacklist.conf

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

while True:
m = mcp3008.readadc(5)
m = (1024 - m)/450.0 * 100
print 'Moisture Level: ' + str(m)
sleep(.5)

moisture_sensor

Wo wo wo! Wait! Why using Windows???

Long story! Infact, i’m using Putty on Windows 7, ssh’ed in a virtual Ubuntu Server in Virtual Box from which i shh’ed to my Raspberry Pi. To summarize: Windows 7 > Ubuntu Server (Virtual) > Raspberry Pi

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 😀

Neways, now i plan in getting a temperature and other sensors (pH maybe) in the mix too. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *