}
void loop() {
// Read the changing voltage from the soil sensor (0 to 1023)
int soilValue = analogRead(soilPin);
// Print raw value to screen so you can see your dirt's status
Serial.print("Soil Moisture Value: ");
Serial.println(soilValue);
// -----------------------------------------------------------------
// CONDITION: Soil is too dry (Value is ABOVE the threshold limit)
// -----------------------------------------------------------------
if (soilValue > dryThreshold) {
Serial.println("[!!!] ALERT: SOIL IS BONE DRY! PLANT NEEDS WATER!");
// Play a rhythmic, pulsing "Water Me!" distress chime
digitalWrite(alarmLed, HIGH);
tone(buzzerPin, 1000); // Low-mid pleading frequency
delay(200);
digitalWrite(alarmLed, LOW);
noTone(buzzerPin);
delay(800); // 1-second interval loop so it doesn't drive you crazy
}
// -----------------------------------------------------------------
// CONDITION: Soil is hydrated and healthy (Value is LOW)
// -----------------------------------------------------------------
else {
noTone(buzzerPin);
digitalWrite(alarmLed, LOW);
delay(1000); // Check once per second when healthy to save battery
}
}
Comments