Arduino moisture-sensing pot

I built a simple Arduino setup that checks the soil in a plant pot. When the soil gets too dry, an LED lights up to remind me to water the plant.
This example averages five readings so one noisy measurement is less likely to trigger the watering reminder. It assumes lower readings mean drier soil. Set the threshold after comparing readings from wet and dry soil.
const int sampleCount = 5;
long total = 0;
for (int sample = 0; sample < sampleCount; sample++) {
total += analogRead(moistureSensorPin);
delay(20);
}
int averageMoisture = total / sampleCount;
bool needsWater = averageMoisture < dryThreshold;
The Arduino uses needsWater to decide when to turn on the LED.