A Digital Moisture Sensor and Computer

for future robotics applications.

Updated 3/5/15

Key Search Words: PIC Microcontroller, CCS C Compiler, PIC Projects

 This seemed the obvious task to deal with before designing a robot which can water plants and keep the cultivated plants healthy. While my first thoughts were to simply dump a teaspoon or two of water onto the growing plant each day, it became quite obvious this was an excellent way to exterminate everything I attempted to grow. As the plant grows, it needs more and more water proportionately and the task is to keep the soil around the root the same pre determined moisture level all the time, so as it gets larger and uses up more water, the conditions for growth are optimal. A moisture sensor that is buried around the plants roots will monitor this level and report its findings to the robot at watering time. But before we can do this, a reliable moisture sensor computer had to be developed. This is the first shot at this.
Starting with the right soil - Miracle Grow potting soil mix. The first step is to screen out the largest chunks and make the mixture as uniform as possible.

The dry soil right out of the bag reads nothing on a commercial analog meter type device, which uses electro-galvonic action to measure moisture. It reads for about 5 seconds and then drops out as the salts in the soil are depleted by the battery like action around the probe.

An Ohm meter connected to two stainless steel long bolts about an inch apart also reads nothing.

Next, I added one teaspoon at a time some water to the soil and tested it with both setups. At some point I will start getting readings!
Finally - after nearly an ounce of water I get the first of four numbers on the galvanic display. You have to keep plunging it in and out every five or tens seconds since it continually drops to zero.
An active probe was then built (schematic at bottom of this page) which allowed the very tiny signal from the two probes to be amplified to yield a 0 - 5v level to go to the processor.
The moisture computer and Parallax LCD display were put in a polyethylene box and an external power supply was added.
Inside the box. The board has a voltage regulator and PIC chip.

The Moisture Computer in Action. The display currently reads the 10 bit sensor value on top, and on the bottom a 0 - 10 reading for moisture that is 2.5x more resolution than the cheapie electro-galvanic probe. And this one can be left in all the time without drifting downward, since it reads current rather than "battery" action.

The probe is inserted into a potted bean sprout, which is just seen coming up here. With the correct watering at hand, the readings are mid range from 4 - 5.

We will monitor the readings as the plant grows and this will give us a good handle on what the robot will have to do!

Schematic (click for larger) of the Moisture computer and probe.
//Chris Schur
//Project Name here:  12F675
//Date:  1/4/15
/*Description of this Program: This program Will eventually read the moisture
sensor and put the result continously to the display.  Here in this version,
we test sending both text and int16 numbers to the very old parallax serial
LCD display.  It works!  */

//I/O Designations ---------------------------------------------------
// A0 (GPIO0):  (An0) - Analog Input: Sensor voltage in
// A1 (GPIO1):  (An1) - Digital Output: LCD out
// A2 (GPIO2):  (An2) - Digital Output: Status LED
// A3 (GPIO3):  X (can ONLY be input)
// A4 (GPIO4):  XTAL OUT (An3) 
// A5 (GPIO5):  XTAL IN

//Include Files:
#include <12F675.h>  //Normally chip, math, etc.  used is here.
//Directives and Defines:
#device ADC=10  //This directive will only work if put RIGHT HERE first...
#use delay(crystal=10MHz)
#use fast_io(A)
//For serial LCD only:
#use rs232(baud = 9600, xmit=Pin_A1, bits=8, parity=N, INVERT, stream = LCD)

//Global Variables:
int16 RESULT;  //a/d conversion of sensor
int8 MOISTURE; //scaled value

//-- Main Program
void main(void) {
   // Set TRIS I/O directions, define analog inputs, compartors:
        set_tris_A(0b101001);  //sets port directions
        //(analog inputs digital by default)
        setup_adc_ports(sAN0);  //sensor v input is 0 - 5v
   //Initialize variables and Outputs:  --------------------------------------
    RESULT = 500;
while (true)  {
   output_high(Pin_A2);  //LED on
   output_low(Pin_A2);   //LED off
    fputc(254,LCD);    //Non Text INSTRUCTION BYTE TO FOLLOW
    fputc(1,LCD);      //CLEAR SCREEN  
    fprintf(LCD,"RESULT= %Lu",RESULT);  //this formatted combination of text
                                        // and 16 bit integer in one line. the
                                        //%Lu means a 16bit integer 
                                        //number follows.
    MOISTURE = (RESULT / 100);                                    
    fputc(254,LCD);    //Non Text INSTRUCTION BYTE TO FOLLOW
    fputc(192,LCD);      //move to start of line 2  
    fprintf(LCD,"MOISTURE= %u",MOISTURE);  //send text plus integer8 value...