const int AirValue = 733; // you might need to calibrate this number, instruction is down below const int WaterValue = 355; // you might need to calibrate this number, instruction is down below const int DrySoilMoisturePercentage = 50; const int SoilMoisturePin = A0; const int RelayPin = D2; int soilMoistureValue = 0; int soilmoisturepercent = 0; void setup() { Serial.begin(9600); pinMode(SoilMoisturePin, INPUT); pinMode(RelayPin, OUTPUT); digitalWrite(RelayPin, HIGH); } void loop() { soilMoistureValue = analogRead(SoilMoisturePin); soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100); Serial.print(soilmoisturepercent); Serial.println("%"); if (soilmoisturepercent <= DrySoilMoisturePercentage) { Serial.println("Water pumps running..."); digitalWrite(RelayPin, LOW); delay(1000); } if (soilmoisturepercent >= DrySoilMoisturePercentage) { Serial.println("Water pumps stopped..."); digitalWrite(RelayPin, HIGH); delay(1000); } }