const int moisturePin = A0; // Soil moisture sensor pin const int relayPin = 8; // Relay control pin const int buzzerPin = 9; // Buzzer pin const int moistureThreshold = 400; // Adjust based on your sensor // Dry Soil: Around 0 to 300 (lower values indicate less moisture). // Normal/Moist Soil: Around 300 to 600 (suitable moisture level for most plants). // Wet Soil: Above 600 (high moisture level, soil may be saturated). void setup() { pinMode(moisturePin, INPUT); pinMode(relayPin, OUTPUT); pinMode(buzzerPin, OUTPUT); Serial.begin(9600); } void loop() { int moistureLevel = analogRead(moisturePin); Serial.print("Moisture Level: "); Serial.println(moistureLevel); if (moistureLevel > moistureThreshold) { // If soil is dry digitalWrite(relayPin, HIGH); // Turn on the relay (activates pump) digitalWrite(buzzerPin, HIGH); // Sound the buzzer delay(3000); // Watering time (adjust as needed) digitalWrite(relayPin, LOW); // Turn off the relay (stops pump) digitalWrite(buzzerPin, LOW); // Turn off buzzer } else { digitalWrite(relayPin, LOW); // Make sure pump is off digitalWrite(buzzerPin, LOW); // Make sure buzzer is off } delay(1000); // Delay between readings }