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 microcontroller to read the soil moisture level from a Soil Moisture Sensor through a Soil Moisture Module. If the moisture level falls below a predefined threshold, the Arduino activates a 12V Single Channel Relay, which in turn powers a water pump to irrigate the soil. The system is powered by a 9V battery.
/*
* 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 and is responsible for reading the soil moisture level from the sensor connected to analog pin A0. Depending on the moisture level, it controls the relay connected to digital pin D3, which in turn controls the water pump. The serial communication is used for debugging purposes to monitor the soil moisture readings.