#define SOIL_SENSOR 4

#define MOTOR_IN1 18
#define MOTOR_IN2 19

int moistureValue = 0;
int threshold = 2500;   // Adjust after calibration

void setup() {
  Serial.begin(115200);

  pinMode(MOTOR_IN1, OUTPUT);
  pinMode(MOTOR_IN2, OUTPUT);

  // Pump OFF initially
  digitalWrite(MOTOR_IN1, LOW);
  digitalWrite(MOTOR_IN2, LOW);
}

void loop() {

  moistureValue = analogRead(SOIL_SENSOR);
  Serial.print("Moisture Value: ");
  Serial.println(moistureValue);

  if (moistureValue > threshold) {
    Serial.println("Soil Dry → Pump ON");

    // Rotate motor in one direction
    digitalWrite(MOTOR_IN1, HIGH);
    digitalWrite(MOTOR_IN2, LOW);
  }
  else {
    Serial.println("Soil Wet → Pump OFF");

    // Stop motor
    digitalWrite(MOTOR_IN1, LOW);
    digitalWrite(MOTOR_IN2, LOW);
  }

  delay(2000);
}