Water-Saving Irrigation System for Agricultural Fields Based on 51 Microcontroller (Soil Moisture Control)

1. Overall System Architecture This system uses the 51 microcontroller as the control core, collecting soil moisture data from agricultural fields through soil moisture sensors. It automatically controls the opening and closing of irrigation equipment based on user-defined moisture thresholds, achieving water-saving irrigation. The system mainly consists of the following modules:

Water-Saving Irrigation System for Agricultural Fields Based on 51 Microcontroller (Soil Moisture Control)

The water-saving irrigation system based on the 51 microcontroller adopts a modular design concept, mainly consisting of data acquisition module, control processing module, execution output module, and human-computer interaction module (《Design of Water-Saving Irrigation System Based on AT89C51 Microcontroller》

Water-Saving Irrigation System for Agricultural Fields Based on 51 Microcontroller (Soil Moisture Control)

Circuit design diagram of the automatic irrigation system based on the 51 microcontroller, including core components such as the microcontroller module, soil moisture detection, and water pump control

The working principle of the system is as follows: the soil moisture sensor continuously collects the simulated signal of soil moisture conditions, which is converted into a digital signal by the ADC0832 analog-to-digital converter and transmitted to the 51 microcontroller. The microcontroller compares the current moisture value with the preset threshold. When it falls below the lower limit, it activates the water pump for irrigation; when it exceeds the upper limit, it stops irrigation. Meanwhile, the LCD1602 display screen shows the monitoring data in real-time (Undergraduate Thesis – Application of Water-Saving Irrigation System Based on AT89C51 Microcontroller)

Detailed Hardware Design

1. Core Controller

The AT89C51 microcontroller is selected as the main control chip, with the following main features:

  • 4KB Flash program memory
  • 128B RAM data memory
  • 32 programmable I/O ports
  • 2 16-bit timers/counters
  • Full-duplex serial communication port
  • #include <reg51.h>

#include “lcd1602.h” // LCD driver header file#include “adc0832.h” // ADC driver header filesbit Relay = P1^0; // Relay control pin

2. Soil Moisture Detection Module

The system uses the YL-69 soil moisture sensor, with the following main parameters:

  • Operating voltage: 3.3V-5V
  • Detection depth: 0-5cm
  • Output signal: Analog (0-5V)
  • Response time: <1s

The sensor output signal is converted by the ADC0832, which is an 8-bit resolution, dual-channel A/D converter with a sampling rate of up to 50kHz (Characteristics and Usage of DHT11 Temperature and Humidity Sensor).

3. Actuator Design

The irrigation control uses a 5V relay module to drive the water pump, with the following technical parameters:

  • Control voltage: DC 5V
  • Load capacity: 10A/250VAC
  • Response time: <10ms
  • Electrical life: 100,000 times

Water-Saving Irrigation System for Agricultural Fields Based on 51 Microcontroller (Soil Moisture Control)

The system hardware circuit schematic diagram shows the connection method of the 51 microcontroller with sensors, display modules, crystal oscillator circuits, and other components

Software System Implementation

1. Main Program Framework

The system software is developed in C51 language, and the main program flow includes four main stages: initialization, data acquisition, threshold judgment, and control output (Design of Agricultural Soil Moisture Monitoring and Automatic Irrigation System Based on 51 Microcontroller).

void main() { Init_System(); // System initialization while(1) { humidity = Get_Humidity(); // Get humidity value Display_Value(humidity); // LCD display if(humidity < HUMI_LOW) { Start_Irrigation(); // Start irrigation } else if(humidity > HUMI_HIGH) { Stop_Irrigation(); // Stop irrigation } Key_Scan(); // Key scanning Delay_ms(1000); // Delay 1 second }}

2. Key Subroutine Implementation

ADC0832 Driver Code:

unsigned char ADC0832_Read(bit CH) { unsigned char i, dat = 0; CS = 0; _nop_(); // Start conversion DI = 1; _nop_(); // Start bit CLK = 1; _nop_(); DI = CH; _nop_(); // Channel selection CLK = 1; _nop_(); DI = 1; _nop_(); // Stop bit for(i=0; i<8; i++) { // Read 8-bit data CLK = 1; _nop_(); dat <<= 1; if(DO) dat |= 0x01; CLK = 0; _nop_(); } CS = 1; // End conversion return dat;}

LCD1602 Display Driver

void LCD_Write_Cmd(unsigned char cmd) { LCD_RS = 0; LCD_RW = 0; LCD_Data = cmd; LCD_EN = 1; Delay_ms(2); LCD_EN = 0;}void LCD_Display_String(unsigned char x, unsigned char y, unsigned char *str) { if(y == 0) LCD_Write_Cmd(0x80 + x); else LCD_Write_Cmd(0xC0 + x); while(*str) { LCD_Write_Data(*str++); }}

Water-Saving Irrigation System for Agricultural Fields Based on 51 Microcontroller (Soil Moisture Control)

The system architecture diagram shows the connection relationships between AT89C51 and various modules, including sensor input, display output, and control signal flow

System Optimization and Function Expansion

1. Water-Saving Algorithm Optimization

By introducing a fuzzy control algorithm, the traditional threshold control method is improved, dynamically adjusting the irrigation duration based on the rate of change of soil moisture to avoid over-irrigation:

void Fuzzy_Control(float humi, float delta_humi)

{

float Kp = 0.5, Ki = 0.2; // Proportional and integral coefficients static float integral = 0; float error = HUMI_SET – humi; integral += error; if(integral > 100) integral = 100; else if(integral < -100) integral = -100; irrigation_time = Kp*error + Ki*integral; if(irrigation_time < 0) irrigation_time = 0;}

2. Wireless Transmission Expansion

An ESP8266 WiFi module can be added for remote monitoring, uploading data to the cloud platform via MQTT protocol (1431 – Agricultural Irrigation System Based on 51 Microcontroller (Humidity, Timing, Automatic) Proteus, Schematic…).

3. Multi-Parameter Fusion

Integrating the DHT11 temperature and humidity sensor to achieve environmental temperature and humidity compensation, improving irrigation decision accuracy: void DHT11_Read(float *temp, float *humi)

{

unsigned char buf[5];

DHT11_Start();

if(DHT11_Check()) {

for(int i=0; i<5; i++) buf[i] = DHT11_Read_Byte(); if(buf[0]+buf[1]+buf[2]+buf[3] == buf[4]) { *humi = buf[0] + buf[1]*0.1; *temp = buf[2] + buf[3]*0.1; } }}

Practical Application Testing

Comparative experiments conducted in a vegetable greenhouse show that compared to traditional timed irrigation methods, this system can achieve water savings of 30%-40%, while crop yield increases by about 15%. The main performance indicators of the system are as follows:

Comparative experiments conducted in a vegetable greenhouse show that compared to traditional timed irrigation methods, this system can achieve water savings of 30%-40%, while crop yield increases by about 15%. The main performance indicators of the system are as follows:

Water-Saving Irrigation System for Agricultural Fields Based on 51 Microcontroller (Soil Moisture Control)

Conclusion and Outlook

The water-saving irrigation system designed based on the 51 microcontroller has characteristics of low cost, high reliability, and good water-saving performance, making it particularly suitable for small and medium-sized agricultural irrigation scenarios. Future optimizations can be made in the following areas:

  1. Add a solar power supply module to enhance system endurance
  2. Adopt low-power wide-area network technologies such as LoRa to expand monitoring range
  3. Introduce machine learning algorithms to achieve irrigation prediction optimization

Water-Saving Irrigation System for Agricultural Fields Based on 51 Microcontroller (Soil Moisture Control)

The complete circuit schematic diagram of the system shows the circuit structure and connection relationships of each module

Leave a Comment