[Diaoye learns programming] Arduino smart agriculture develops a reasonable irrigation plan based on the growth stage and water demand of crops

Insert image description here
Arduino is an open source electronics prototyping platform that allows you to create a variety of interactive projects using simple hardware and software. The core of Arduino is a microcontroller board that can connect various sensors, actuators, displays and other external devices through a series of pins. Arduino programming is based on the C/C++ language. You can use the Arduino IDE (Integrated Development Environment) to write, compile and upload code to the Arduino board. Arduino also has a rich library and community that you can use to extend the functionality of Arduino and learn about Arduino.

The characteristics of Arduino are:
1. Open source: Arduino’s hardware and software are open source, and you can freely modify, copy and share them.
2. Easy to use: Arduino’s hardware and software are designed for beginners and non-professionals, you can easily get started and use them.
3. Cheap: Arduino’s hardware and software are very economical, and you can realize your ideas at a very low cost.
4. Diversity: Arduino has many models and versions. You can choose the appropriate Arduino board according to your needs and preferences.
5. Innovation: Arduino allows you to express your creativity and imagination electronically. You can use Arduino to make a variety of interesting and useful projects, such as robots, smart homes, and art. Devices etc.

Insert image description here
The main features of Arduino smart agriculture:
1. Sensor and actuator integration: Arduino smart agriculture system can integrate various sensors (such as temperature sensor, humidity sensor, soil moisture sensor, etc. ) and actuators (such as water pumps, motors, lights, etc.) to monitor and control the agricultural environment.
2. Data collection and analysis: Arduino smart agricultural system can collect agricultural environment data and conduct real-time analysis and processing. These data can be used to monitor plant growth status, soil conditions, climate changes, etc., and help farmers make appropriate decisions.
3. Remote monitoring and control: The Arduino smart agricultural system can achieve remote monitoring and control through network connection. Farmers can remotely monitor the conditions of farmland through mobile phones, computers and other devices, and perform corresponding control operations, such as remote irrigation, temperature adjustment, etc.
4. Automation and intelligence: Arduino smart agricultural system can automatically perform a series of tasks, such as automatic watering, automatic adjustment of lighting, etc., reducing farmers' labor burden and improving work efficiency. At the same time, through intelligent algorithms and decision-making models, the system can make automated decisions based on real-time data, making agricultural production more intelligent.

The core advantages of Arduino smart agriculture:
1. Low cost: Arduino is an open source hardware platform, the hardware cost is relatively low, and it is easy to obtain and use. Farmers can assemble and customize smart agricultural systems themselves according to their needs and budgets.
2. Flexibility: The Arduino platform has good scalability and compatibility and can be combined with various sensors and actuators to adapt to different agricultural environments and needs. Farmers can choose appropriate components and functions based on their actual conditions.
3. Ease of use: The Arduino platform has simple and easy-to-use programming interfaces and development tools. Even non-professional farmers or beginners can quickly get started and develop. The Arduino community provides a large number of tutorials and sample codes for easy learning and reference.

Limitations of Arduino smart agriculture:
1. Limited processing power: Arduino is a small embedded system with relatively limited processing power. For some complex agricultural applications, more powerful hardware platforms may be needed to handle large amounts of data and complex algorithms.
2. Limited network connection capabilities: Arduino usually communicates through short-distance connections such as wired or Bluetooth. For remote farmland or scenarios that require wide area network connections, additional equipment may be needed to achieve network connections.
3. Lack of standardization and supervision: Since Arduino is an open source platform, it lacks unified standards and supervision mechanisms. This may lead to compatibility issues between different systems and increase the difficulty of system maintenance and management.
4. Requires certain technical knowledge: Although the Arduino platform is relatively easy to use, for some farmers, it still requires certain electronic and programming knowledge. For farmers who lack relevant technical knowledge, additional training and support may be needed.

Insert image description here
In Arduino smart agriculture, formulating a reasonable irrigation plan based on the growth stage and water demand of crops means using the Arduino control system to automatically control the work of irrigation equipment based on the growth stage and water demand information of crops to achieve reasonable irrigation of crops. Below I will explain in detail from three aspects: main features, application scenarios and matters needing attention.

Main features:
Automated control: Use the Arduino control system to automatically control the opening and closing of irrigation equipment according to the preset crop growth stage and water demand information. Data on soil moisture or crop water demand are obtained through sensors, and based on set thresholds and logical judgments, automated irrigation control is implemented and reasonable water supply is provided.
Precise water demand control: According to the growth stage and water demand characteristics of the crop, the irrigation system can accurately calculate the current water demand of the crop based on the set parameters and algorithms, and perform operations based on the water demand. Control of irrigation volume. This can avoid the problem of over-irrigation or insufficient water, provide a suitable moisture environment for crops, and improve yield and quality.
Flexible irrigation plan adjustment: Through programming and setting parameters, irrigation plans suitable for different growth stages can be developed according to the growth characteristics and water demand changes of different crops. During the growth of crops, as the growth stage changes, the irrigation plan can be flexibly adjusted to meet the needs of crop growth.
Data recording and analysis: Arduino smart agricultural system can record data such as soil moisture, water demand and actual irrigation volume. These data can be used for subsequent data analysis to understand the growth status and water use efficiency of crops, and provide support for the optimization and decision-making of irrigation plans.

Application scenario:
Field crop planting: In large areas of farmland, the Arduino smart agricultural system is used to develop a reasonable irrigation plan based on the growth stage and water demand of the crops to achieve Precision irrigation of field crops. It can be differentiated and adjusted between different plots and crops to improve water utilization efficiency.
Greenhouse planting: In the greenhouse, the Arduino smart agriculture system is used to realize intelligent irrigation of crops in the greenhouse according to the growth stage and water demand of the crops. It can provide precise water supply according to the greenhouse environment and crop needs to support the healthy growth of greenhouse crops.
Indoor plant cultivation: When cultivating plants in an indoor environment, the Arduino smart agriculture system can be used to automatically adjust the amount of irrigation according to the growth stage and water demand of the crops. Ensure that indoor plants receive the right amount of water to promote healthy plant growth.

Things to note:
Selection and installation of soil moisture sensors: Choose a suitable soil moisture sensor to ensure its measurement accuracy and stability. Install the sensor where it accurately reflects soil moisture to avoid errors and delays.
Selection and configuration of irrigation equipment: Select appropriate irrigation equipment based on crop water requirements and the size of the irrigation area to ensure reasonable water supply. Configure the layout of irrigation equipment and pipe network to ensure that water can be evenly distributed to the roots of crops.
Setting of algorithms and parameters: Set appropriate algorithms and parameters according to the growth characteristics and water demand changes of crops. This needs to be debugged and optimized according to specific crops and actual conditions to ensure the accuracy and effectiveness of the irrigation plan.
Energy supply and system stability: The Arduino smart agricultural system requires a stable power supply to ensure the normal operation of the system. At the same time, the system should be properly maintained and inspected to ensure its stability and reliability.
Data analysis and decision support: Analyze and utilize recorded data to obtain valuable information and optimize irrigation plans and decisions. At the same time, the irrigation plan is adjusted in a timely manner to respond to changes and needs in crop growth.

In short, Arduino smart agriculture formulates a reasonable irrigation plan based on the growth stage and water demand of crops, which has the characteristics of automatic control, precise water demand regulation, flexible irrigation plan adjustment, and data recording and analysis. It is suitable for field crop cultivation, greenhouse cultivation and indoor plant cultivation and other scenarios. During the application process, attention needs to be paid to sensor selection and installation, irrigation equipment selection and configuration, algorithm and parameter setting, energy supply and system stability, as well as data analysis and decision support, etc. By rationally utilizing the Arduino smart agricultural system, the efficiency of agricultural production and the sustainability of water resource utilization can be improved.

Insert image description here
Case 1: Automatic irrigation system based on soil moisture sensor:

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <Adafruit_TSL2591.h>
#include <Adafruit_VEML6075.h>

#define SOIL_MOISTURE_PIN A0
#define PUMP_PIN 3
#define MIN_MOISTURE_LEVEL 300
#define MAX_MOISTURE_LEVEL 700

Adafruit_SSD1306 display(128, 32, &Wire, -1);

void setup() {
    
    
  pinMode(PUMP_PIN, OUTPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
}

void loop() {
    
    
  int moistureLevel = analogRead(SOIL_MOISTURE_PIN);
  
  display.print("Moisture Level: ");
  display.println(moistureLevel);
  
  if (moistureLevel < MIN_MOISTURE_LEVEL) {
    
    
    digitalWrite(PUMP_PIN, HIGH);
    display.println("Pump: ON");
  } else if (moistureLevel > MAX_MOISTURE_LEVEL) {
    
    
    digitalWrite(PUMP_PIN, LOW);
    display.println("Pump: OFF");
  }
  
  display.display();
  delay(2000);
  display.clearDisplay();
}

Interpretation of key points:
The program uses a soil moisture sensor to read the soil moisture level and controls the on/off state of the water pump based on the set minimum and maximum moisture thresholds.
In the setup() function, initialize the water pump and OLED display.
In the loop() function, read the soil moisture value and determine whether it is lower than the minimum threshold or higher than the maximum threshold.
If the soil moisture is lower than the minimum threshold, the water pump is turned on for irrigation and the corresponding information is displayed on the display; if the soil moisture is higher than the maximum threshold, the water pump is turned off and the corresponding information is displayed.
Use the delay function to control the time interval between each soil moisture detection.
This example program shows how to automatically control an irrigation system based on readings from a soil moisture sensor. The program reads the soil moisture value and compares it with the set minimum and maximum thresholds to decide whether to turn on the water pump for irrigation. The soil moisture value is displayed on the connected OLED display and shows the on/off status of the water pump.

Case 2: Irrigation system based on real-time clock and time control:

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <DS3231.h>

#define PUMP_PIN 3
#define WATERING_DURATION 10 // 灌溉持续时间(单位:秒)

DS3231 rtc;
Adafruit_SSD1306 display(128, 32, &Wire, -1);

void setup() {
    
    
  pinMode(PUMP_PIN, OUTPUT);
  rtc.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
}

void loop() {
    
    
  DateTime now = rtc.now();
  
  display.print("Current Time: ");
  display.print(now.hour());
  display.print(":");
  display.println(now.minute());
  
  if (now.hour() == 8 && now.minute() == 0) {
    
    
    digitalWrite(PUMP_PIN, HIGH);
    display.println("Pump: ON");
    delay(WATERING_DURATION * 1000);
    digitalWrite(PUMP_PIN, LOW);
    display.println("Pump: OFF");
  }
  
  display.display();
  delay(2000);
  display.clearDisplay();
}

Interpretation of key points:
The program uses the real-time clock module (DS3231) to read the current time and control the on/off status of the water pump according to the set time point.
In the setup() function, initialize the water pump, real-time clock and OLED display.
In the loop() function, the current time is obtained and displayed on the OLED display.
If the current time is the set irrigation time (here it is set to 8:00 every day), the water pump will be turned on for irrigation and the corresponding information will be displayed on the display. The irrigation duration is defined by the "WATERING_DURATION" variable.
Use the delay function to control the time interval between each time detection.
This example program shows how to control an irrigation system based on the time of the real-time clock. The program reads the time of the real-time clock and compares it with the set irrigation time point to decide whether to turn on the water pump for irrigation. The current time is displayed on the connected OLED display, and the on/off status of the water pump is displayed.

Case 3: Intelligent sunlight control system based on light sensor:

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <Adafruit_TSL2591.h>
#include <Adafruit_VEML6075.h>

#define LIGHT_SENSOR_PIN A0
#define LIGHT_THRESHOLD 100
#define LIGHT_ON_DURATION 10 // 日照持续时间(单位:秒)

Adafruit_SSD1306 display(128, 32, &Wire, -1);

void setup() {
    
    
  pinMode(LIGHT_SENSOR_PIN, INPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
}

void loop() {
    
    
  int lightLevel = analogRead(LIGHT_SENSOR_PIN);
  
  display.print("Light Level: ");
  display.println(lightLevel);
  
  if (lightLevel < LIGHT_THRESHOLD) {
    
    
    digitalWrite(LIGHT_PIN, HIGH);
    display.println("Light: ON");
    delay(LIGHT_ON_DURATION * 1000);
    digitalWrite(LIGHT_PIN, LOW);
    display.println("Light: OFF");
  }
  
  display.display();
  delay(2000);
  display.clearDisplay();
}

Interpretation of key points:
The program uses the light sensor to read the light level and controls the on/off status of the daylight lamp according to the set light threshold.
In the setup() function, initialize the light sensor and OLED display.
In the loop() function, read the value of the light sensor and compare it with the set light threshold.
If the light level is below the threshold, the daylight is turned on and the corresponding information is displayed on the display. The duration of sunlight is defined by the "LIGHT_ON_DURATION" variable.
Use the delay function to control the time interval between each light detection.
This example program shows how to control a smart lighting system based on readings from a light sensor. The program reads the value of the light sensor and compares it with the set light threshold to decide whether to turn on the sunlight lamp. The value of the light sensor is displayed on the connected OLED display, as well as the on/off status of the daylight lamp.

The above are several practical application reference code examples, which are based on soil moisture sensors, real-time clock and time control, and light sensors to implement irrigation plans in smart agriculture. These programs demonstrate how to use Arduino and sensor technology to monitor environmental parameters and automatically control them based on preset thresholds and times to achieve a reasonable irrigation schedule.

Insert image description here
Case 4: Irrigation plan based on growth stage

#define SOIL_MOISTURE_PIN A0
#define PUMP_PIN 3

int soilMoistureThresholds[] = {
    
    700, 500, 300}; // 对应生长阶段的土壤湿度阈值
int wateringDurations[] = {
    
    3000, 2000, 1000}; // 对应生长阶段的灌溉持续时间

int currentStage = 0;

void setup() {
    
    
  pinMode(SOIL_MOISTURE_PIN, INPUT);
  pinMode(PUMP_PIN, OUTPUT);
}

void loop() {
    
    
  int soilMoisture = analogRead(SOIL_MOISTURE_PIN);

  if (soilMoisture > soilMoistureThresholds[currentStage]) {
    
    
    digitalWrite(PUMP_PIN, HIGH); // 打开水泵
    delay(wateringDurations[currentStage]);
    digitalWrite(PUMP_PIN, LOW); // 关闭水泵
  }

  // 检查是否需要切换生长阶段
  if (currentStage < 2 && soilMoisture < soilMoistureThresholds[currentStage + 1]) {
    
    
    currentStage++;
  }

  delay(1000);
}

Interpretation of key points:
The code uses a soil moisture sensor to read the soil moisture value and controls irrigation based on thresholds and irrigation duration set for different growth stages.
In the setup() function, initialize the soil moisture sensor and water pump pins.
In the loop() function, read the value of the soil moisture sensor. If the current soil moisture exceeds the threshold of the current growth stage, the water pump is turned on for irrigation, and the water pump is turned off after a certain period of time.
In each cycle, check whether the current soil moisture is lower than the threshold of the next growth stage, and if so, switch to the next growth stage.

Case 5: Irrigation plan based on water demand

#define SOIL_MOISTURE_PIN A0
#define PUMP_PIN 3

int wateringThreshold = 500; // 需水量阈值
int wateringDuration = 3000; // 灌溉持续时间

void setup() {
    
    
  pinMode(SOIL_MOISTURE_PIN, INPUT);
  pinMode(PUMP_PIN, OUTPUT);
}

void loop() {
    
    
  int soilMoisture = analogRead(SOIL_MOISTURE_PIN);

  if (soilMoisture > wateringThreshold) {
    
    
    digitalWrite(PUMP_PIN, HIGH); // 打开水泵
    delay(wateringDuration);
    digitalWrite(PUMP_PIN, LOW); // 关闭水泵
  }

  delay(1000);
}

Interpretation of key points:
The code uses a soil moisture sensor to read the soil moisture value and controls irrigation based on the water demand threshold and irrigation duration.
In the setup() function, initialize the soil moisture sensor and water pump pins.
In the loop() function, read the value of the soil moisture sensor. If the current soil moisture exceeds the water demand threshold, the water pump is turned on for irrigation, and the water pump is turned off after a certain period of time.

Case 6: Irrigation schedule based on growth stage and water requirements

#define SOIL_MOISTURE_PIN A0
#define PUMP_PIN 3

int soilMoistureThresholds[] = {
    
    700, 500, 300}; // 对应生长阶段的土壤湿度阈值
int wateringDurations[] = {
    
    3000, 2000, 1000}; // 对应生长阶段的灌溉持续时间

int currentStage = 0;

void setup() {
    
    
  pinMode(SOIL_MOISTURE_PIN, INPUT);
  pinMode(PUMP_PIN, OUTPUT);
}

void loop() {
    
    
  int soil湿度 = analogRead(SOIL_MOISTURE_PIN);

  if (soilMoisture > soilMoistureThresholds[currentStage]) {
    
    
    digitalWrite(PUMP_PIN, HIGH); // 打开水泵
    delay(wateringDurations[currentStage]);
    digitalWrite(PUMP_PIN, LOW); // 关闭水泵
  }

  // 检查是否需要切换生长阶段
  if (currentStage < 2 && soilMoisture < soilMoistureThresholds[currentStage + 1]) {
    
    
    currentStage++;
  }

  delay(1000);
}

Interpretation of key points:
The code uses a soil moisture sensor to read the soil moisture value and controls irrigation based on the soil moisture threshold and irrigation duration set for different growth stages.
In the setup() function, initialize the soil moisture sensor and water pump pins. In the loop() function, the value of the soil moisture sensor is read. If the current soil moisture exceeds the threshold of the current growth stage, the water pump is turned on for irrigation, and the water pump is turned off after a certain period of time. In each cycle, check whether the current soil moisture is below the threshold of the next growth stage, and if so, switch to the next growth stage. These cases demonstrate the implementation of Arduino smart agriculture to develop reasonable irrigation plans based on the growth stage and water demand of crops. Automation of irrigation is achieved by using a soil moisture sensor to read the soil moisture value, comparing it with a preset threshold, and controlling the on/off status of the water pump based on the comparison result.

In Case 4, different soil moisture thresholds and irrigation durations are set according to the growth stage of the crop. By judging whether the current soil moisture exceeds the threshold of the current growth stage, it is decided whether to irrigate and switch between different growth stages. In Case 5, only the water demand threshold is considered, and whether to irrigate is decided by judging whether the current soil moisture exceeds the water demand threshold. In Case 6, the growth stage and water demand of the crop are comprehensively considered, and the corresponding soil moisture threshold and irrigation duration are set according to different growth stages. Whether to irrigate is decided by judging whether the current soil moisture exceeds the threshold of the current growth stage. , and switch between different growth stages. The implementation of these irrigation plans can be adjusted according to specific crop needs and growing environments, helping farmers to automatically manage the irrigation process and improve crop growth effects and water resource utilization efficiency.

Note that the above cases are only for expansion of ideas and are for reference only. They may have errors, be inapplicable, or fail to compile. Your hardware platform, usage scenario, and Arduino version may affect the choice of usage method. When actually programming, you need to make adjustments based on your own hardware configuration, usage scenarios, and specific needs, and conduct multiple actual tests. You'll also want to connect the hardware correctly and understand the specifications and characteristics of the sensors and devices you use. For codes involving hardware operations, you must confirm the correctness and safety of parameters such as pins and levels before use.

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/134963749