Automatic plant watering system using AVR(Atmega16) Microcontroller

Share on FacebookShare on Google+Tweet about this on TwitterShare on RedditShare on StumbleUponPin on Pinterest
plant-watering-system-AVR-microcontroller

Plant watering system evolved through various stages where primitive irrigation systems possess many drawbacks as it fails to conserve water and human energy. So introducing Automation in it can help us to overcome these drawbacks and pave way to conserve water. This can be done with a simple Soil moisture sensor and a Microcontroller, AVR in our case. You can try out this system to automate watering the plants in your home at affordable cost.

 

SOIL MOISTURE SENSOR:

The Soil moisture sensor plays a crucial factor in this plant watering system. There are several ways to measure the moisture of the soil. We are going to measure the moisture level by the conductivity property of the moist soil. We all know that the moist soil conducts electricity better than the dry one. And the impedence level of the dry soil is higher than the moist one. 

soil-moisture-sensor
Source : www.instructables.com
Here we are going to employ a Simple soil moisture sensor KDQ11 which you can which you can buy from ebay. This sensor is associated with comparator LM-393 so whenever the soil is moist the sensor gives low signal as output and high in the case of dry soil. The analog output from this sensor module is fed to the A/D pin of the controller for conversion.

ALTERNATE METHOD TO MEASURE SOIL MOISTURE:

soil-moisture-sensor-using-two-wires

For those you cannot get Soil moisture sensor, you can make one by your own, it may be unorthodox but will be effective. Insert two wires to the dry soil and measure the resistance of it. And again repeat the same by pouring some water to the soil (moist condition). Now you have to built a voltage resistor network using a resistor and the soil. Here the soil acts as a potentiometer which varies its resistance based on its condition. 

 

Calculate the resistor value you are about to use based on the resistance you have done before in wet and dry condition. And determine the trigger point in which you system have to switch the pump on.

 

And last but not the least Pump actuator, use a relay which is capable of switching heavy load such as pumps. The power transistor TIP122 is used to switch the Relay On/Off based on the moisture content of the soil.

CODE:

This code was built using AVR studio 4.

#include<avr/io.h>
int adc(void);
void pump(void);
int adc_value;
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)
   {
     adc_value=adc();                //reading moisture level
     pump();                               //Pump activator routine
   }
   return 0;
 }
 
int adc(void)
 {
   int lower_bits,higher_bits,result;  
   ADCSRA|=(1<<6);              //Turning on conversion
   while(ADIF==0);
   lower_bits=ADCL;
   higher_bits=ADCH;
   result=lower_bits|higher_bits<<8;         //Accessing converted value by shifting
   return result;
 }
 
void pump(void)
 {
  if(adc_value>=700)                                //Pump ON trigger point
   {
     PORTC|=(1<<0);
   }
  else if(adc_value<=600)                        //Pump Off trigger point
   {
     PORTC&=~(1<<0);
   }
 }

NOTE:

  • The Trigger point of pump activation depends on the soil so make your calibration before setting the On and off point. Here i have used 700 as triggering point for pump On and 600 for turning off the pump.
  • Set the triggering points in such a way to keep some difference in between them to avoid relay chattering.

Related Designs and Schematics

Share on FacebookShare on Google+Tweet about this on TwitterShare on RedditShare on StumbleUponPin on Pinterest
The following two tabs change content below.

Frank Donald

Junior Network Engineer at Tata Communications
Frank Donald is an Electronics and Communication Engineer who is very passionate about his subject. Reading, Surfing and Blogging are the things he loves.

Ask your query

31 Comments on "Automatic plant watering system using AVR(Atmega16) Microcontroller"

Notify of
avatar
Sort by:   newest | oldest | most voted
AWAIS SATTI
Guest

sir can you please give me your email id i have some queries regarding this project.it will be so kind of you.thank you

Subhankar
Guest
Hello, instead of relay, i used l293d motor driver. So I changed the code little bit… #include int adc(void); void pump(void); int adc_value; int main(void) { DDRC=0x03; ADCSRA=0x87; ADMUX=0x00; while(1) { adc_value=adc(); pump(); } return 0; } int adc(void) { int lower_bits,higher_bits,result; ADCSRA|=(1<<6); while(ADIF==0); lower_bits=ADCL; higher_bits=ADCH; result=lower_bits|higher_bits<=600) { PORTC = 0b00000001; } else if(adc_value<=550) { PORTC = 0b00000011; } } I declared pin 0 & 1 of port c as o/p and changed the last 4 line. Actually my sensor o/p is 4.2v (at dry) and 2.1(at wet). But in both cases(i.e. wet & dry) the port C pin 0… Read more »
Subhankar
Guest

Hello sir, I have some trouble with the code. Actually I haven’t understand the code of line No. 8 & 9 (i.e. ADCSRA=0x87; ADMUX=0x00;)
and from 21 to 25
(i.e. ADCSRA|=(1<<6);
while(ADIF==0);
lower_bits=ADCL;
higher_bits=ADCH;
result=lower_bits|higher_bits<<8;).
If you explain, it would be helpfull for me.
Thank you.

Subhankar
Guest

Hello, can i use L293d motor driver instead of relay?

SS
Guest
Frank Donald, Is there anything wrong in the code? because after burning it, i am getting low voltage for wet soil and high voltage for dry soil from the analog sensor input… but the problem is, i am always getting high voltage at PC0 in borh cases.. there in no change in the values for dry and wait soil.. in such case where is the actual problem.. is there anything wrong in the circuit design or in the code? I have followed everyting you have described here. please help. And one more thing, can you please tell me the proper… Read more »
Hasan
Guest

How I will know moisture sensor values? Will It be displayed? Is there any way to know/display the input coming from the moisture sensor so that I can know the exact value of the moisture? please help.

James
Guest

Hi,
I am a newbie. Can you please tell me how many softwares in total will be needed to complete the project? And can you please tell me the steps of building the project (for example: After building the above circuit along with moisture sensor, what will be the next step to test if the code is working or not? ). Please help.

AA
Guest

can you please explain the role of R2,D1 and Q1?

SK
Guest

Why we are using the capacitors C1,C2 and the crystal oscillator (8 MHZ) and forming a circuit? What is the role of this?

Anonymous
Guest

sorry. it will work. but i dont get why there is void in arguments. it is used to write there () when function is no void…

Frank Donald
Guest

Hello,
Well i guess you are confused about it. The term void means empty that is we are not gonna pass any argument into the function however leaving empty makes them unspecified. This stackoverflow discussion gives you a great idea “Is there a difference between foo(void) and foo() in C++ or C” . kindly leave comment with your name or profile next time. Cheers

wpDiscuz