0% found this document useful (0 votes)
9 views

LAB-3-SOIL

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

LAB-3-SOIL

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

CPEN 130 - Embedded Systems

Laboratory Activity 3

Arduino-Based Soil Moisture Monitoring and Irrigation Automation System

Submitted by:
Miro G. Angeles
Deen Reiner B. Crusem
Julius Caezar R. Eugenio
BS CPE 4-1

Submitted to:
Prof. Aileen V. Rocillo

November 2024
Laboratory Activity 3
Arduino-Based Soil Moisture Monitoring and Irrigation Automation System

OBJECTIVES
At the end of the experiment, the students should be able to:
1. Monitor soil moisture levels using a soil moisture sensor.
2. Automatically control a water pump through a relay module based on moisture readings.
3. Display real-time moisture data on an LCD screen.

Introduction

Automated technologies for tracking soil conditions and managing irrigation are
essential to smart agriculture because they maximize water use and boost crop productivity.
Yu (2021) asserts that because soil moisture directly affects the amount of irrigation that plants
need, it is one of the most important variables affecting crop yield. Crop problems like water
stress and dehydration, which can result in decreased quality and yield, can be avoided with
proper soil moisture management. By keeping an eye on soil moisture levels, farmers can
optimize crop quality and reduce water waste, guaranteeing that plants get the exact amount
of water they require.Farmers may prevent the negative consequences of both excessive and
insufficient watering, which have a substantial impact on crop health and yield, by keeping an
eye on soil moisture. In order to prevent these issues, Rivai (2019) emphasizes the
significance of regular and accurate irrigation, stressing that inadequate water management
can result in stunted growth, lower yields, and even crop loss. Automated irrigation and real-
time soil moisture monitoring assist maintain ideal soil conditions. By ensuring that water is
used responsibly and crops receive the precise amount of water they need, smart irrigation
systems help to improve agricultural operations' sustainability and efficiency (Taneja, 2017).
This approach is especially valuable in water-scarce regions where resource conservation is
critical, as proper automation supports both agricultural success and environmental protection
by reducing unnecessary water use (Kumar, 2022).

This project builds an automatic irrigation and soil moisture monitoring system using
an Arduino, relay module, water pump, LCD display, and soil moisture sensor. The Arduino
receives data from the soil moisture sensor, which determines the soil's water content. To start
irrigation, the Arduino automatically activates the water pump via the relay module if the
moisture content drops below a predetermined threshold. In order to securely operate high-
power components like the water pump, the Arduino serves as the primary control unit,
processing input from the soil moisture sensor and sending signals to the relay, which
operates as an electrical switch (Chew, 2020). By doing this, over-watering is avoided and
water resources are preserved because the water pump only runs when required. In order to
guarantee that the soil is sufficiently irrigated without wasting any water, the water pump then
distributes precise amounts of water. Furthermore, users may immediately monitor soil
conditions and measure the efficacy of the irrigation process thanks to the LCD display's real-
time soil moisture readings. By reducing labor costs and encouraging optimal water use, this
integrated system provides an effective, automated method of crop irrigation that supports
agricultural sustainability on both an economic and environmental level.

Materials and Components


• Arduino Uno Board
• Breadboard
• Soil Moisture Sensor
• Water Pump
• LCD Display (16x2)
• Jumper Wires

CIRCUIT DIAGRAM

Figure 1. Wiring Diagram of the Soil Moisture Monitoring System


Figure 2. Schematic Diagram of the Soil Moisture Monitoring System

This schematic diagram shows a circuit where an Arduino Uno (U2) controls a 16x2
LCD display (U1), a sensor (SEN1), and a water pump motor (M1) through a relay module
(K1). The components are powered by a 5V source, with the Arduino acting as the central
controller for processing sensor data and operating the motor.

Procedure

Step 1. Connection of Components


1.1. Setting up the Breadboard
a. Connect the 5V pin of the Arduino to the positive (red) rail of the breadboard using
a jumper wire.
b. Connect the GND pin of the Arduino to the negative (blue) rail of the breadboard
using a jumper wire.
c. Connect the power (positive) and ground (negative) rails of the top and bottom
parts of the breadboard to ensure consistent power distribution.

1.2. Connect the Soil Moisture Sensor


a. Place the soil moisture sensor module on the breadboard.
b. Connect the VCC pin of the soil moisture sensor to the positive rail (5V) on the
breadboard.
c. Connect the GND pin of the soil moisture sensor to the negative rail (GND) on the
breadboard.
d. Connect the SIG (Signal) pin of the soil moisture sensor to the A0 pin of the Arduino
using a jumper wire.
1.3: Connect the Water Pump and Relay Module
a. Place the relay module on the breadboard.
b. Connect the VCC pin of the relay module to the positive rail (5V) on the breadboard.
c. Connect the GND pin of the relay module to the negative rail (GND) on the
breadboard.
d. Connect the IN pin of the relay module to digital pin 8 on the Arduino using a jumper
wire.
e. Connect the water pump as follows:
o Connect one wire of the water pump to the COM (Common) terminal of the
relay module.
o Connect the other wire of the water pump to the positive rail (5V) on the
breadboard.
o Connect the NO (Normally Open) terminal of the relay to the negative rail
(GND) on the breadboard.

1.4: Connect the Buzzer


a. Attach/Solder the I2C module to the 16x2 LCD.
b. Connect the SDA pin of the I2C module to the A4 pin of the Arduino using a jumper
wire.
c. Connect the SCL pin of the I2C module to the A5 pin of the Arduino using a jumper
wire.
d. Connect the VCC pin of the I2C module to the positive rail (5V) on the breadboard.
e. Connect the GND pin of the I2C module to the negative rail (GND) on the
breadboard.

The table below provides a summary of the pin assignments for the various components
connected to the Arduino Uno board:

Component Arduino Pin Assignment Description


Soil Moisture Sensor GND Ground connection for the
GND soil moisture sensor.
Soil Moisture Sensor 5V Power supply for the soil
VCC moisture sensor.
Soil Moisture Sensor A0 Analog input to read soil
Signal moisture level.
LCD Display SDA A4 Serial data line (SDA) for
I2C communication with
the LCD.
LCD Display SCL A5 Serial clock line (SCL) for
I2C communication with
the LCD.
LCD Display VCC 5V Power supply for the LCD
display.
LCD Display GND GND Ground connection for the
LCD display.
Relay Module IN Digital Pin 8 Control signal from
Arduino to activate the
relay for the pump.
Relay Module VCC 5V Power supply for the relay
module.
Relay Module GND GND Ground connection for the
relay module.
Relay Module Normally Connected to Pump No current flow to the
Closed (NC) pump when relay is off.
Relay Module Normally Connected to Pump Allows current flow to the
Open (NO) pump when relay is
activated.
Water Pump Connected via Relay Module Activates when soil
moisture drops below the
threshold.
Table 1. Pin Assignments

Step 2. Code Development or Algorithm Design


a. Start writing the Arduino code to design the control system for monitoring soil
moisture and activating the water pump based on moisture feedback. The code
begins by defining the pins for the soil moisture sensor, relay module, and LCD,
ensuring clear and effective communication between the Arduino and the connected
components. Functions are assigned to read sensor data, calculate moisture
percentages, and control the pump, while the LCD displays real-time moisture levels
and pump status, enabling efficient monitoring and irrigation control.
b. The algorithm is designed to:
• Read the raw values from the soil moisture sensor and convert them to a
moisture percentage.
• Display the calculated moisture percentage on the 16x2 LCD for real-time
monitoring.
• Automatically turn on the water pump when the soil moisture falls below 30%
and turn it off when it exceeds 70%, ensuring optimal irrigation.
• Continuously update the pump status on the LCD for user awareness.

Step 3. Explanation of Logic Used


a. Loop: The loop function continuously reads data from the soil moisture sensor,
calculates the soil's moisture percentage, and updates the LCD with the current
moisture level and pump status. It ensures real-time monitoring and automation of
the irrigation process.
b. Conditional Logic: The program employs conditional statements (if-else) to
determine the appropriate actions based on the calculated soil moisture
percentage:
• Low Moisture (< 30%): If the soil moisture percentage drops below 30%, the
relay is triggered to turn on the water pump, supplying water to the soil. The LCD
updates to display "Pump: ON," signaling that irrigation is active.
• Optimal Moisture (> 70%): When the soil moisture percentage rises above
70%, the relay is deactivated to turn off the water pump, stopping irrigation. The
LCD updates to display "Pump: OFF," signaling that irrigation has stopped.
• Normal Monitoring: During normal operation, the LCD continuously updates
the displayed moisture percentage and pump status based on sensor readings,
providing real-time feedback to the user.

Step 4. Uploading the Code and Testing the System

After thoroughly reviewing the Arduino code, upload it to the Arduino board
using the Arduino IDE and conduct several tests to ensure proper functionality.
Simulate different soil moisture levels by placing the sensor in dry or wet soil and
observe the system’s response on the LCD, ensuring it accurately displays the
moisture percentage and pump status. Verify that the relay triggers the pump when
moisture falls below 30% and turns it off above 70%. If issues arise, check wiring,
sensor readings, and code logic, adjusting parameters as needed for reliable
operation. Repeat testing to confirm consistent performance.
Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h> void loop() {
// Read the raw soil moisture sensor value
// Initialize the LCD with I2C address 0x27 and soilMoistureValue = analogRead(A0);
16x2 display size
LiquidCrystal_I2C lcd(0x27, 16, 2); // Debugging: Log raw soil sensor value to the
Serial Monitor
const int AirValue = 600; // Dry soil sensor Serial.print("Raw Soil Value: ");
reading (adjust if needed) Serial.println(soilMoistureValue);
const int WaterValue = 310; // Wet soil sensor
reading // Convert the sensor value to a moisture percentage
const int RelayPin = 8; // Relay pin for moisturePercentage = map(soilMoistureValue,
controlling the pump AirValue, WaterValue, 0, 100);
moisturePercentage = constrain(moisturePercentage,
int soilMoistureValue = 0; // Raw sensor reading 0, 100); // Ensure value is between 0-100%
float moisturePercentage = 0; // Mapped moisture
percentage // Debugging: Log moisture percentage to the Serial
bool pumpStatus = false; // Track pump state Monitor
float lastMoisturePercentage = -1; // Previous Serial.print("Moisture Percentage: ");
moisture value for LCD optimization Serial.println(moisturePercentage);
bool lastPumpStatus = false; // Previous pump
// Ensure the LCD always displays moisture
state
percentage
void setup() { if (moisturePercentage != lastMoisturePercentage) {
Serial.begin(9600); lcd.setCursor(10, 0);
Serial.println("System Initialization..."); lcd.print(" "); // Clear previous value
lcd.setCursor(10, 0);
// Initialize the LCD and turn on the backlight lcd.print(moisturePercentage, 0); // Display
lcd.init(); moisture percentage
lcd.backlight(); lcd.print("%");
lastMoisturePercentage = moisturePercentage;
// Setup the relay pin }
pinMode(RelayPin, OUTPUT);
digitalWrite(RelayPin, HIGH); // Ensure the
water pump is off initially

// Initial LCD Display


lcd.setCursor(0, 0);
lcd.print("Moisture: --%");
lcd.setCursor(0, 1);
lcd.print("Pump: OFF");

Serial.println("Initialization Complete");
}
// Control the water pump based on moisture level
if (moisturePercentage < 30.0 && !pumpStatus) {
Serial.println("Pump Turned ON"); // Debugging
digitalWrite(RelayPin, LOW); // Turn the water pump on (LOW triggers the relay)
pumpStatus = true;
}
else if (moisturePercentage > 70.0 && pumpStatus) {
Serial.println("Pump Turned OFF"); // Debugging
digitalWrite(RelayPin, HIGH); // Turn the water pump off (HIGH turns relay off)
pumpStatus = false;
}

// Ensure the LCD always reflects the current pump status


if (pumpStatus != lastPumpStatus || lastPumpStatus == false) {
lcd.setCursor(6, 1);
lcd.print(" "); // Clear previous value
lcd.setCursor(6, 1);
lcd.print(pumpStatus ? "ON " : "OFF");
lastPumpStatus = pumpStatus;
}

delay(5000); // 5-second delay for stable operation


}

Results

The outcomes of the Soil Moisture Monitoring and Irrigation System met the objectives
of the project effectively. The soil moisture sensor accurately measured moisture levels, and
the relay module automated the activation and deactivation of the water pump. When the soil
moisture level dropped below the set threshold of 30%, the water pump was triggered,
demonstrating efficient irrigation automation. Conversely, the pump turned off when the
moisture level exceeded 70%, ensuring water conservation and avoiding over-irrigation.

Additionally, the LCD display consistently showed real-time moisture readings and
pump status, confirming successful data communication between the sensor, Arduino, and
display module. The system reliably adjusted irrigation according to varying soil conditions,
emphasizing its potential as a sustainable solution for agricultural applications.
Test No. Soil Moisture Pump LCD Status Notes
Level (%) Status
1 25 On Displayed: “Pump: ON” Works as expected
2 75 Off Displayed: “Pump: OFF” Works as expected
3 40 On Displayed: “Pump: OFF” Works as expected
4 80 Off Displayed: “Pump: OFF” Works as expected
5 20 On Displayed: “Pump: ON” Works as expected
6 65 Off Displayed: “Pump: OFF” Works as expected

Table 2. Output after testing

Fig 2. Output When Moisture goes above 30%

Fig 3. Output When Moisture goes Equal or Below 30%


Fig 4. Front View of the Soil Moisture Monitoring System

Fig 5. Back View of the Soil Moisture Monitoring System

Fig 6. Side View of the Soil Moisture Monitoring System


Discussions

The results from testing the Arduino-Based Soil Moisture Monitoring and Irrigation
Automation System demonstrated that the soil moisture sensor effectively detected varying
moisture levels in the soil and triggered appropriate actions. When the moisture level fell below
the threshold of 30%, the system automatically activated the water pump, ensuring timely
irrigation. Conversely, the pump deactivated once the moisture level exceeded 70%,
highlighting the system's ability to conserve water. The LCD display successfully provided
real-time updates on soil moisture levels and the pump's status, offering clear and accessible
feedback for the user.

However, during the testing phase, some challenges and potential areas for
improvement were identified. One challenge encountered was the sensor's sensitivity to
external environmental factors, such as variations in soil composition and ambient
temperature. These factors occasionally caused slight inconsistencies in the readings.
Additionally, the water pump's response time to changing soil moisture levels was sometimes
delayed, particularly when transitioning between thresholds. This delay could potentially
impact irrigation timing in critical scenarios.

Proposed Improvements:

1. Enhanced Calibration of the Soil Moisture Sensor: Regular calibration of the sensor
to account for variations in soil type and environmental conditions could improve the
accuracy of moisture readings. Adding an adjustable threshold mechanism in the
system design would also enhance its adaptability for different agricultural
applications.
2. Integration of a Backup Power Source: Including a backup power source, such as
a rechargeable battery, could ensure uninterrupted operation during power outages,
which are critical for maintaining consistent irrigation cycles.
3. Improved Response Time for the Water Pump: Optimizing the relay module's
operation or incorporating a faster-acting relay system could address the delayed
response of the pump, ensuring more precise irrigation control.
Conclusion

In conclusion, the project objectives for the Arduino-Based Soil Moisture Monitoring
and Irrigation Automation System were successfully achieved. The integration of a soil
moisture sensor with the Arduino allowed the system to accurately detect real-time moisture
levels in the soil and automate the irrigation process. When the moisture level fell below the
threshold of 30%, the water pump was activated to ensure adequate irrigation, and it was
automatically deactivated when the moisture level exceeded 70%, conserving water
effectively.

Furthermore, the system included an LCD display that provided clear, real-time
feedback on soil moisture levels and the pump's operational status. This automation improved
the system's efficiency, reduced manual intervention, and ensured consistent monitoring and
irrigation.

Lastly, the overall functionality of the system was demonstrated successfully through
testing under various moisture conditions. The integration of sensor technology, Arduino
components, and automation illustrated a practical and reliable application for sustainable
agriculture. The project highlights how such systems can enhance agricultural practices by
optimizing water usage and ensuring timely irrigation, offering a promising solution for efficient
resource management in farming.
References

Yu, L., Gao, W., R Shamshiri, R., Tao, S., Ren, Y., Zhang, Y., & Su, G. (2021). Review of
research progress on soil moisture sensor technology

Kumar, K., Devi, V. L., & Kumar, M. D. (2022). Design of solar powered smart water pump for
moisture controller in agriculture sector. Materials Today: Proceedings, 64, 130-140.

Rivai, M., Ashari, M., & Mustaghfirin, M. A. (2019, October). Drip irrigation system using bldc
motor-driven direct pumping and soil moisture sensor. In 2019 International
Conference on Computer Science, Information Technology, and Electrical Engineering
(ICOMITEE) (pp. 221-226). IEEE.

Taneja, K., & Bhatia, S. (2017, June). Automatic irrigation system using Arduino UNO. In 2017
International Conference on Intelligent Computing and Control Systems (ICICCS) (pp.
132-135). IEEE.

Chew, K. M., Tan, S. C. W., Loh, G. C. W., Bundan, N., & Yiiong, S. P. (2020, February). IoT
soil moisture monitoring and irrigation system development. In Proceedings of the
2020 9th International Conference on Software and Computer Applications (pp. 247-
252).
Appendices

Fig 7. Members Wiring and Coding the Soil Moisture Monitoring System

Fig 8. Members Assembling the Miniature Soil Moisture Monitoring System


Table 2. Soil Moisture Sensor Datasheet
Parameters Details/Value
Model Generic Soil Moisture Sensor
Operating Voltage 3.3V - 5V
Output Voltage 0 - 4.2V (varies with moisture level)
Interface Type Analog
Moisture Range 0% (dry) - 100% (wet)
Output Type Analog Voltage
Pin Assignments VCC, GND, Analog Out
Sensor Type Resistive
Probe Material Corrosion-resistant metal
Dimensions 60mm x 20mm x 5mm
Cable Length 20cm
Response Time ≤ 1 second
Working Temperature 10°C - 60°C
Humidity Range 0 - 100% RH
Application Soil moisture monitoring for irrigation systems

You might also like