Automatic plant watering system using AVR(Atmega16) Microcontroller

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>=600)                                //Pump ON trigger point
   {
     PORTC|=(1<<0);
   }
  else if(adc_value<=700)                        //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 600 as triggering point for pump On (low moisture) and 700 for turning off the pump(high moisture).
  • Set the triggering points in such a way to keep some difference in between them to avoid relay chattering.

50 Comments

  1. Sk Md Abdul Kaium

    Everything was fine. But my pump doesn’t stop even if I put the moisture detecting pin in the water bowl.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *