top of page
Writer's pictureSanskruti Ashtikar

Automated Irrigation System Using PIC Microcontroller

Updated: Dec 1

Introduction


Water is a crucial resource for agriculture, and its efficient use is essential for sustainable farming. An Automated Irrigation System helps optimize water usage by controlling the irrigation process based on soil moisture levels and environmental conditions. This project utilizes a PIC microcontroller to automate the watering process, ensuring that crops receive the right amount of water at the right time. In this article, we will explore the design, implementation, and coding aspects of building an Automated Irrigation System using a PIC microcontroller.





Required


  1. PIC Microcontroller (e.g., PIC16F877A)

  2. Soil Moisture Sensor

  3. Water Pump

  4. Relay Module

  5. LCD Display (16x2)

  6. Temperature and Humidity Sensor (optional, e.g., DHT11)

  7. Power Supply (5V and 12V)

  8. Crystal Oscillator (20 MHz)

  9. Capacitors (22pF, 100µF)

  10. Resistors (1kΩ, 10kΩ)

  11. Transistor (e.g., 2N2222 or BC547)

  12. Diode (e.g., 1N4007)

  13. Connecting Wires

  14. PCB or Breadboard for Prototyping


System Overview


The Automated Irrigation System uses a soil moisture sensor to monitor the moisture content in the soil. When the soil moisture level drops below a certain threshold, the PIC microcontroller activates a relay that turns on a water pump. The system can also incorporate environmental sensors like temperature and humidity sensors to make more informed decisions about watering. An LCD display provides real-time data on soil moisture and the system's status.


Block Diagram


  1. Soil Moisture Sensor: Detects the moisture level in the soil.

  2. PIC Microcontroller: Processes sensor data and controls the relay and water pump.

  3. Relay Module: Acts as a switch to control the water pump.

  4. Water Pump: Pumps water to the irrigation system.

  5. LCD Display: Shows real-time data such as soil moisture levels and system status.

  6. Temperature and Humidity Sensor (optional): Provides additional environmental data to optimize irrigation.


Circuit Diagram


[Insert a simplified circuit diagram here, showing connections between the PIC microcontroller, soil moisture sensor, relay module, water pump, and LCD display.]


Working Principle


  1. Soil Moisture Detection: The soil moisture sensor measures the volumetric water content in the soil. It typically outputs an analog signal that varies based on the moisture level.

  2. Signal Processing: The analog output from the soil moisture sensor is fed into the PIC microcontroller's analog-to-digital converter (ADC) channel. The microcontroller processes this signal to determine the soil moisture level.

  3. Automatic Watering:

  4. When the soil moisture level drops below a predefined threshold, the microcontroller sends a signal to the relay module to activate the water pump.

  5. The water pump remains on until the soil moisture reaches the desired level, at which point the microcontroller deactivates the relay, turning off the pump.

  6. The system continuously monitors the soil moisture to maintain optimal levels.

  7. Display and Monitoring: The system can display real-time data on an LCD, such as current soil moisture levels, pump status, and environmental conditions if additional sensors are used.


Software Implementation


  1. Initializing the Microcontroller:

  2. Set up the I/O pins for the soil moisture sensor, relay, and LCD.

  3. Configure the ADC to read the analog output from the soil moisture sensor.

  4. Initialize the LCD for displaying data.

  5. Monitoring Soil Moisture:

  6. Continuously read the soil moisture level using the ADC.

  7. Compare the moisture level with a predefined threshold to decide whether to activate the water pump.

  8. Controlling the Water Pump:

  9. Activate the relay to turn on the water pump when the soil moisture is low.

  10. Deactivate the relay to turn off the pump when the desired moisture level is reached.





Sample Code

#include <xc.h>
#include "lcd.h"
#define _XTAL_FREQ 20000000  // Define crystal frequency
// Configuration bits
#pragma config FOSC = HS    // High-speed oscillator
#pragma config WDTE = OFF   // Watchdog Timer Disable
#define SOIL_SENSOR_CH 0  // Soil moisture sensor connected to ADC channel 0
#define RELAY_PIN PORTBbits.RB1  // Relay connected to RB1
#define MOISTURE_THRESHOLD 500  // Threshold for soil moisture (example value)
void ADC_Init(void) {
    ADCON0 = 0x41;  // ADC enabled, Channel 0 selected
    ADCON1 = 0x80;  // Right justified result
}
unsigned int ADC_Read(unsigned char channel) {
    ADCON0 &= 0xC5;  // Clear the channel selection bits
    ADCON0 |= channel<<3;  // Select the ADC channel
    __delay_ms(2);  // Acquisition time
    GO_nDONE = 1;   // Start conversion
    while(GO_nDONE);  // Wait for the conversion to complete
    return ((ADRESH<<8) + ADRESL);  // Return the result
}


void main(void) {
    ADC_Init();  // Initialize ADC
    TRISBbits.TRISB1 = 0;  // Set RB1 as output (Relay)
    lcd_init();  // Initialize LCD
    
    RELAY_PIN = 0;  // Initialize relay as off
    
    unsigned int moistureLevel;
    while (1) {
        moistureLevel = ADC_Read(SOIL_SENSOR_CH);  // Read the soil moisture level
        
        lcd_clear();
        lcd_goto(1, 1);
        lcd_puts("Moisture:");
        lcd_goto(2, 1);
        lcd_put_num(moistureLevel);  // Display moisture level on LCD
        
        if (moistureLevel < MOISTURE_THRESHOLD) {  // If soil is too dry
            RELAY_PIN = 1;  // Turn on the water pump
            lcd_goto(2, 10);
            lcd_puts("Pump: ON");
        } else {
            RELAY_PIN = 0;  // Turn off the water pump
            lcd_goto(2, 10);
            lcd_puts("Pump: OFF");
        }
        
        __delay_ms(1000);  // Update every second
    }
}



Explanation of the Code


  • ADC Initialization and Reading: The ADC module is configured to read the analog signal from the soil moisture sensor. The moisture level is compared to a predefined threshold to determine if watering is necessary.

  • Relay Control: The relay is controlled based on the soil moisture reading. If the moisture level is below the threshold, the relay is activated to turn on the water pump.

  • LCD Display: The system displays the soil moisture level and the status of the water pump on an LCD.


Conclusion


An Automated Irrigation System using a PIC microcontroller is a practical and efficient solution for optimizing water usage in agriculture. By continuously monitoring soil moisture levels and automating the watering process, this system helps conserve water while ensuring that crops receive adequate hydration. This project demonstrates the use of sensors, analog-to-digital conversion, and relay control in a real-world application, making it an excellent learning experience for those interested in embedded systems and agricultural technology.


Further Enhancements


  1. Environmental Sensing: Integrate additional sensors, such as temperature and humidity sensors, to further optimize the irrigation process based on environmental conditions.

  2. Time-Based Control: Implement a time-based watering schedule in addition to moisture-based control for more precise irrigation.

  3. Remote Monitoring: Add a wireless module to send real-time data to a remote monitoring system, allowing for remote control and monitoring of the irrigation system.

  4. Water Level Monitoring: Include a water level sensor in the water reservoir to prevent the pump from running dry.


This project not only highlights the importance of automation in agriculture but also provides a hands-on approach to designing and implementing an embedded system that can have a significant impact on resource conservation and farming efficiency.


Want us to guide you through your project or make the project for you ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 



0 views0 comments

Related Posts

See All

Comments


bottom of page