Water and soil moisture sensor for raspberry pi

My local MicroCenter shop sells a water and soil moisture sensor combo package from velleman. They do exactly what they say with one that measures water levels, and the other measures how much moisture is in soil. I bought this package maily for the soil moisture sensor to track whether or not my plants need water, but I will show some sample code and help you get them both working with your raspberry pi. If your pi is new and fresh out of the box, follow my Quick setup guide

What you will need

Step one: Wire the connections

Following the wiring diagram above, make all the connections between the pi and the MCP3008:

  • MCP3008 VDD to Raspberry Pi 3.3V
  • MCP3008 VREF to Raspberry Pi 3.3V
  • MCP3008 AGND to Raspberry Pi GND
  • MCP3008 DGND to Raspberry Pi GND
  • MCP3008 CLK to Raspberry Pi SCLK
  • MCP3008 DOUT to Raspberry Pi MISO
  • MCP3008 DIN to Raspberry Pi MOSI
  • MCP3008 CS/SHDN to Raspberry Pi CE0

Next simply connect the Velleman sensor to the Pi and the MCP3008:

  • S goes to CH0 of the MCP3008 (any of the 8 will work, but for this example I will use the third channel)
  • + goes Raspberry Pi 3.3V
  • - goes to Raspberry Pi GND

Step two: Download and Install the MCP3008 Library

  • sudo apt-get update
  • sudo apt-get install build-essential python-dev python-smbus git
  • cd ~
  • git clone https://github.com/adafruit/Adafruit_Python_MCP3008.git
  • cd Adafruit_Python_MCP3008
  • sudo python setup.py install

Step three: Download and Install the Python Package Index

  • sudo apt-get update
  • sudo apt-get install build-essential python-dev python-smbus python-pip
  • sudo pip install adafruit-mcp3008

Step four: Download example code and test your sensor!

You can play around with the samples that come from adafruit:

  • cd ~/Adafruit_Python_MCP3008/examples

You can also download my custom code based on the wiring diagram above and test your sensor as well:

  • wget http://www.thispi.com/downloads/mcp3008-soil-moisture-sensor.py
  • Then run the script: python mcp3008-soil-moisture-sensor.py
  • You should see output similar to: Moisture level: 400