CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to

A Plant Moisture computer for potted plants

Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Arizona Chris

Joined: 20 Dec 2014
Posts: 64
Location: Arizona

View user's profile Send private message Visit poster's website

A Plant Moisture computer for potted plants
PostPosted: Sun Mar 08, 2015 12:38 pm     Reply with quote

Hello All,

With the eventual goal of getting an autonomous robot to tend to the plant watering at some point, or perhaps an automated watering system, I developed this simple moisture sensing computer to monitor the soil resistance continuously by a special active probe I designed and put the results out to a Parallax LCD serial display. My goal is to have the future autonomous system grow a small garden indoors and we started with six potted seeds in a Miracle Grow soil mix. The sensor was placed very close to the roots of the plants and readings are (Yoohoo!) right smack in the mid range.

Circuit description:

The sensor consists of two 3 inch stainless steel screws with wires to the active circuitry on top. That is a 2N3904 NPN transistor, and two 330 ohm resistors. It is connected as follows - the 5v goes to the Collector of the transistor, then to one end of the 330 ohm. the other end of that 330 ohm goes to one of the probes. The other probe which is one inch apart goes directly to the base of the transistor. By connecting a second 330 ohm resistor to the emitter we generate a voltage of 0 - 5v across the resistor. This goes right into the the A/D converter on the PIC 12F675 chip. Pretty easy!

I have posted on my web site a complete write up with schematics and photos of this project. Please visit it at:

The moisture computer uses one my most favorite PIC chips, the 12F675. its nice tiny 8 pin dip format is perfect for most small tasks, and it is very cheap too at less than a dollar.

The readings are in 10 bit resolution on the A/D and I convert to a 0 - 10 final output reading of the soil moisture level by simply dividing by 100. This is more than twice the resolution of a standard commercial soil moisture probe I bought that reads with an (gasp) analog meter 1-4.

So here is the code, and while quite simple it accomplishes the task beautifully!


//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 continuously 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, comparators:
        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...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group