Saturday, July 7, 2018

Automatic Irrigation System Using Soil Moisture Sensor and PIC16F887



In this project we will interface soil moisture sensor with PIC16F887. The micro controller PIC16F887 is a  very popular micro controller in PIC16 series. The sensor can detect if the soil is humid or not. If the soil is dry, then micro controller will turn on the motor to give water in the soil. When There is enough water in the soil, that means the soil is not dry, we will turn off the motor. We will also use a lcd and a led to indicate that motor is on or off. For driving the motor we will use L293D motor driver. This L293D is a dual channel motor drive. Here we will only use 1 channel, because we will run only on motor. The current limit for L293D is 1A. So, choose a motor which doesn't require more 500mA - 700mA current. We will use small motor to demonstrate the process. 



PIC16F887 Pin Diagram


Soil Moisture Sensor


To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2


MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language for programming. Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F887  IC. 

To do this project we need following components;


   1. PIC16F887
   2. LED
   3. 16 MHz Crystal Oscillator
   4. Breadboard
   5. Wires
   6. 5V DC Power source
   7. Soil Moisture Sensor
   8. 16*2 LCD
   9. L293D Motor Driver
  10. DC motor
  11. 470 ohm resistor
  12. Header for connect LCD
  13. 10K potentiometer

CODE

 sbit LCD_RS at RD0_bit;
 sbit LCD_EN at RD1_bit;
 sbit LCD_D4 at RD2_bit;
 sbit LCD_D5 at RD3_bit;
 sbit LCD_D6 at RD4_bit;
 sbit LCD_D7 at RD5_bit;
 sbit LCD_RS_Direction at TRISD0_bit;
 sbit LCD_EN_Direction at TRISD1_bit;
 sbit LCD_D4_Direction at TRISD2_bit;
 sbit LCD_D5_Direction at TRISD3_bit;
 sbit LCD_D6_Direction at TRISD4_bit;
 sbit LCD_D7_Direction at TRISD5_bit;
 // End LCD module connections

 double source=0;
 double temp=0;
 int view=0;
 char txt[6];

 void main()

 {

  TRISC = 0x00;
  PORTC = 0x00;
  ADC_Init();                   // Initialize ADC
  Lcd_Init();                   // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);          // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);     // Cursor off
                                // clear LCD

  Lcd_Out(1, 1, "     EEE 332    ");
  Lcd_Out(2, 1, "    ABDUR ROUF  ");
  delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "  SOIL MOISTURE ");
  Lcd_Out(2, 1, " MICROCONTROLLER");
  delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);          // Clear display
                                //  char code for degree
                                // Display "C" for Celsius
  while(1)
  {
        source=Adc_Read(1);
     
        if(source>600)
        {
          PORTC = 0b11111101;                  //motor on
          delay_ms(500);
          Lcd_Cmd(_LCD_CLEAR);
          Lcd_Out(1,5, "Dry Soil");
          Lcd_Out(2,5, "Motor On");
        }
     
        if(source<=600)
        {
          PORTC = 0b00000000;
          delay_ms(500);                  //motor on
          Lcd_Cmd(_LCD_CLEAR);
          Lcd_Out(1,5, "Humid Soil");
          Lcd_Out(2,5, "Motor OFF");
        }
     }

 }


Schematic



Schematic 1




Schematic 2




Schematic 3



5 comments:

  1. hi can you send me the full details of this project

    ReplyDelete
  2. Guys, you can send me this project file. thank you very much

    ReplyDelete
  3. Guys, you can send me this project file?. thank you very much
    My gmail: loctran2k@gmail.com

    ReplyDelete
  4. You have everything in here. Just follow the tutorial, you will get result. Best of luck.

    ReplyDelete
    Replies
    1. Dear friend, if I run my code, I get an error, do I need to write any additional lines at the beginning of the code? Thank you

      Delete

Line Follower Robot using Arduino

This project was a part of Line Follower Robot Competition