Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
A Plant Moisture computer for potted plants |
Posted: Sun Mar 08, 2015 12:38 pm |
|
|
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:
http://www.schursastrophotography.com/PICprojects/MoistureComputer1.html
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
Code: | //****************************************************************************
//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...
#fuses NOPROTECT,NOMCLR
#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
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
//Initialize variables and Outputs: --------------------------------------
RESULT = 500;
//----------------------------------------------------------------
//MAIN LOOP:
while (true) {
output_high(Pin_A2); //LED on
delay_ms(250);
output_low(Pin_A2); //LED off
delay_ms(250);
fputc(254,LCD); //Non Text INSTRUCTION BYTE TO FOLLOW
delay_ms(1);
fputc(1,LCD); //CLEAR SCREEN
delay_ms(10);
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
delay_ms(1);
fputc(192,LCD); //move to start of line 2
delay_ms(10);
fprintf(LCD,"MOISTURE= %u",MOISTURE); //send text plus integer8 value...
}
} |
|
|