const int soilMoisturePin = 12; // Pin connected to the potentiometer
const int pumpPin = 26; // Pin connected to the LED
const int moistureThreshold = 500; // Adjust this threshold according to your readings
void setup() {
pinMode(soilMoisturePin, INPUT);
pinMode(pumpPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int moistureLevel = analogRead(soilMoisturePin);
Serial.print("Moisture level: ");
Serial.println(moistureLevel);
if (moistureLevel < moistureThreshold) {
Serial.println("Soil too dry. Activating pump...");
digitalWrite(pumpPin, HIGH); // Turn on the LED (simulating water pump)
delay(5000); // Pump water for 5 seconds
digitalWrite(pumpPin, LOW); // Turn off the LED
Serial.println("Watering complete.");
} else {
Serial.println("Soil moisture level is adequate. No action taken.");
}
delay(1000); // Adjust the delay time according to your needs
}