#define SOIL_PIN 34 // Analog pin connected to the potentiometer
#define PUMP_PIN 26 // Digital pin connected to the relay or LED
#define MOISTURE_THRESHOLD 2000 // Adjust this threshold for your setup
void setup() {
Serial.begin(115200); // Start serial communication at 115200 baud
pinMode(SOIL_PIN, INPUT); // Set soil sensor pin as input
pinMode(PUMP_PIN, OUTPUT); // Set pump (relay/LED) pin as output
digitalWrite(PUMP_PIN, LOW); // Initially turn off the pump (LED)
}
void loop() {
int soilMoistureValue = analogRead(SOIL_PIN); // Read the soil moisture sensor value
Serial.print("Soil Moisture Level: ");
Serial.println(soilMoistureValue);
// Compare soil moisture to the threshold
if (soilMoistureValue > MOISTURE_THRESHOLD) {
// Soil is dry, turn the pump on
digitalWrite(PUMP_PIN, HIGH);
Serial.println("Soil is dry. Turning pump ON.");
} else {
// Soil is wet, turn the pump off
digitalWrite(PUMP_PIN, LOW);
Serial.println("Soil is wet. Turning pump OFF.");
}
delay(500); // Wait for 0.5 seconds before the next reading
}