voidloop() { int moisture = readSensor(); Serial.print("Analog Output: "); Serial.println(moisture);
if (moisture < soilWet) { Serial.println("Status: Soil is too wet"); } elseif (moisture >= soilWet && moisture < soilDry) { Serial.println("Status: Soil moisture is perfect"); } else { Serial.println("Status: Soil is too dry - time to water!"); }
delay(1000); // Take a reading every second for testing Serial.println(); }
intreadSensor() { digitalWrite(sensorPower, HIGH); // Turn the sensor ON delay(10); // Allow power to settle int val = analogRead(sensorPin); // Read the analog value form sensor digitalWrite(sensorPower, LOW); // Turn the sensor OFF return val; // Return analog moisture value }