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
PIC Microcontroller (e.g., PIC16F877A)
Soil Moisture Sensor
Water Pump
Relay Module
LCD Display (16x2)
Temperature and Humidity Sensor (optional, e.g., DHT11)
Power Supply (5V and 12V)
Crystal Oscillator (20 MHz)
Capacitors (22pF, 100µF)
Resistors (1kΩ, 10kΩ)
Transistor (e.g., 2N2222 or BC547)
Diode (e.g., 1N4007)
Connecting Wires
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
Soil Moisture Sensor: Detects the moisture level in the soil.
PIC Microcontroller: Processes sensor data and controls the relay and water pump.
Relay Module: Acts as a switch to control the water pump.
Water Pump: Pumps water to the irrigation system.
LCD Display: Shows real-time data such as soil moisture levels and system status.
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
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.
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.
Automatic Watering:
When the soil moisture level drops below a predefined threshold, the microcontroller sends a signal to the relay module to activate the water pump.
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.
The system continuously monitors the soil moisture to maintain optimal levels.
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
Initializing the Microcontroller:
Set up the I/O pins for the soil moisture sensor, relay, and LCD.
Configure the ADC to read the analog output from the soil moisture sensor.
Initialize the LCD for displaying data.
Monitoring Soil Moisture:
Continuously read the soil moisture level using the ADC.
Compare the moisture level with a predefined threshold to decide whether to activate the water pump.
Controlling the Water Pump:
Activate the relay to turn on the water pump when the soil moisture is low.
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
Environmental Sensing: Integrate additional sensors, such as temperature and humidity sensors, to further optimize the irrigation process based on environmental conditions.
Time-Based Control: Implement a time-based watering schedule in addition to moisture-based control for more precise irrigation.
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.
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
Comments