# automatic plant watering system using microcontroller

#### Smartboy33

Joined Sep 6, 2014
3
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:
C:
    #include<avr/io.h>
void pump(void);
int main(void)
{
DDRC=0x01;                          //Defining PC0 as output
ADCSRA=0x87;                    //Setting the mode of operation
ADMUX=0x00;                     //Selection of channel and bit alignment
while(1)
{
pump();                               //Pump activator routine
}
return 0;
}

{
int lower_bits,higher_bits,result;
result=lower_bits|(higher_bits<<8);         //Accessing converted value by shifting
return result;
}

void pump(void)
{
{
PORTC|=(1<<0);
}
else if(adc_value<=600)                        //Pump Off trigger point
{
PORTC&=~(1<<0);
}
}
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?

Last edited by a moderator:

#### JohnInTX

Joined Jun 26, 2012
4,709
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

#### Attachments

• 1.8 MB Views: 24