automatic plant watering system using microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by Smartboy33, Dec 9, 2015.

  1. Smartboy33

    Thread Starter New Member

    Sep 6, 2014
    I am trying to build an automatic plant watering system using ATmega16. We are using moisture sensor YL69 for our project. The following is the image of the moisture sensor we have used.


    The circuit diagram of the project is as follows:

    The following is the code fragment we used:
    Code (C):
    2.     #include<avr/io.h>
    3.     int adc(void);
    4.     void pump(void);
    5.     int adc_value;
    6.     int main(void)
    7.      {
    8.       DDRC=0x01;                          //Defining PC0 as output
    9.       ADCSRA=0x87;                    //Setting the mode of operation
    10.       ADMUX=0x00;                     //Selection of channel and bit alignment
    11.       while(1)
    12.        {
    13.          adc_value=adc();                //reading moisture level
    14.          pump();                               //Pump activator routine
    15.        }
    16.        return 0;
    17.      }
    19.     int adc(void)
    20.     {
    21.        int lower_bits,higher_bits,result;
    22.        ADCSRA |= (1 << ADSC)|(1 << ADIF);  //Turn on conversion and clear flag
    23.        while(ADCSRA & (1 << ADIF) == 0);  //wait for flag
    24.        lower_bits=ADCL;
    25.        higher_bits=ADCH;
    26.        result=lower_bits|(higher_bits<<8);         //Accessing converted value by shifting
    27.        return result;
    28.      }
    30.     void pump(void)
    31.      {
    32.       if(adc_value>=700)                                //Pump ON trigger point
    33.        {
    34.          PORTC|=(1<<0);
    35.        }
    36.       else if(adc_value<=600)                        //Pump Off trigger point
    37.        {
    38.          PORTC&=~(1<<0);
    39.        }
    40.      }
    Is there anything wrong in the code? Because after burning it, i am getting low voltage(0.15) for wet soil and high voltage(4.84) for dry soil from the analog sensor input which is ok … but the problem is, I am always getting voltage like 0.7(and sometimes like 0.15) at PC0 in both cases(I am using multimeter for measuring this). There in no change in the values for dry and wet soil at PC0.. in such case where is the actual problem? Is there anything wrong in the circuit design or in the code? And one more thing, can anyone please tell me the proper way of measuring the output value I am getting from PC0 which in turn is switching on/off the pump?

    Another question is, I am using AVR programmer for 5V DC supply. In the above circuit design I have not made any connection at pin MOSI,MISO,RESET and SCK (of ATmega 16) with AVR programmer. Will I have to make this?

    Mod note: added code tags
    Last edited by a moderator: Dec 9, 2015
  2. JohnInTX


    Jun 26, 2012
    Here is a well done write-up of a similar system using the same sensor. The sensor has a built-in comparator which outputs a logic level depending on whether the soil conductivity is more or less than the threshold set by the pot. The 'analog' is reported in ohms (it says) , not volts that the ADC would want (as I read things). Can you post how you have the actual sensor wired? There isn't much real info on it that I found.

    Many google hits on the sensor reference a 'Digi-pot' then describe what a digi-pot is (from Wikipedia, it looks like) but it looks like the sensor board itself just has an ordinary trimpot for the comparator trip level. I suspect the 'analog' output is just the voltage that is applied to the comparator's sense pin as part of a resistive divider. You may need an amplifier or other scaling to make it work.

    Anyway, post your actual interface circuit. If you can find some actual reference material on the YL69 sensor, link that as well. Most of the posts I saw about it have a lot of cut and paste boilerplate that I don't think the 'technical' author really understands.

    Good luck.
    H/T to the author of the pdf.

    Some Info