The Smart Irrigation System is designed to monitor soil moisture levels and automatically irrigate when the soil becomes too dry. The system uses an Arduino UNO as the main controller, which reads the soil moisture level through a Soil Moisture Module connected to its analog input. A 12V single-channel relay is used to control a 5V mini water pump, which is activated when the soil moisture falls below a predefined threshold. The relay is powered by the Arduino and triggered by one of its digital outputs. The Soil Moisture Module is interfaced with a YL-69 Sonda probe that measures the moisture in the soil. The system is powered by a 9V battery connected to the relay and the water pump.
/*
* Smart Irrigation System
* This Arduino sketch reads soil moisture levels using a soil moisture sensor.
* If the soil is too dry, it activates a relay to turn on a water pump.
*/
const int soilMoisturePin = A0; // Analog pin connected to soil moisture sensor
const int relayPin = 3; // Digital pin connected to relay module
const int threshold = 500; // Threshold value for soil moisture
void setup() {
pinMode(relayPin, OUTPUT); // Set relay pin as output
digitalWrite(relayPin, LOW); // Ensure relay is off initially
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int soilMoistureValue = analogRead(soilMoisturePin); // Read soil moisture
Serial.print("Soil Moisture: ");
Serial.println(soilMoistureValue); // Print soil moisture value
if (soilMoistureValue < threshold) {
digitalWrite(relayPin, HIGH); // Turn on water pump
} else {
digitalWrite(relayPin, LOW); // Turn off water pump
}
delay(1000); // Wait for 1 second before next reading
}
The code is written for the Arduino UNO microcontroller. It initializes the relay pin as an output and the serial communication for debugging purposes. In the main loop, it reads the soil moisture value from the sensor and prints it to the serial monitor. If the moisture level is below the threshold, it activates the relay to turn on the water pump; otherwise, it turns the pump off. The system pauses for one second before taking the next reading.