const int moistureSensorPin = A0; // Signal pin of the moisture sensor
const int ledPin = 13; // LED connected to pin 8
const int moistureThreshold = 1; // Adjust based on testing
void setup() {
Serial.begin(9600); // Start Serial Monitor
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(moistureSensorPin, INPUT); // Set sensor pin as input
}
void loop() {
int moistureValue = analogRead(moistureSensorPin); // Read sensor value
Serial.print("Moisture Value: ");
Serial.println(moistureValue); // Print sensor value for debugging
// Check moisture level
if (moistureValue < moistureThreshold) {
digitalWrite(ledPin, HIGH); // Turn on LED if soil is dry
} else {
digitalWrite(ledPin, LOW); // Turn off LED if soil is moist
}
delay(500); // Wait 0.5 seconds before the next reading
}