The SparkFun Soil Moisture Sensor is an easy-to-use device designed to measure the moisture content in soil, which is an essential parameter for gardening and agricultural applications. By detecting the moisture level, this sensor helps in determining when plants require watering, ensuring optimal plant growth and health.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5V) |
2 | GND | Ground connection |
3 | D0 | Digital output (active low) |
4 | A0 | Analog output |
// SparkFun Soil Moisture Sensor Example for Arduino UNO
const int MOISTURE_SENSOR_PIN = A0; // Analog output from the sensor
const int MOISTURE_LEVEL_THRESHOLD = 300; // Set the threshold value
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
int sensorValue = analogRead(MOISTURE_SENSOR_PIN); // Read the analog value
Serial.print("Moisture Level: ");
Serial.println(sensorValue); // Print the moisture level to the Serial Monitor
// Check if the moisture level is below the threshold
if (sensorValue < MOISTURE_LEVEL_THRESHOLD) {
// If the soil is dry, take appropriate action (e.g., activate a water pump)
Serial.println("Soil is dry - time to water the plants!");
} else {
// If the soil is moist, no action is needed
Serial.println("Soil is moist - no watering needed.");
}
delay(1000); // Wait for a second before reading again
}
Q: Can the sensor be left in the soil permanently? A: While the sensor can be left in the soil for extended periods, it is recommended to remove it when not in use to prevent corrosion.
Q: How do I adjust the digital output threshold? A: The digital output threshold is typically adjusted via a potentiometer on the sensor board. Turn the potentiometer until the digital output switches at the desired moisture level.
Q: Is the sensor waterproof? A: The sensor's probes are water-resistant, but the electronics are not waterproof. Care should be taken to avoid getting the top part of the sensor wet.
Q: What is the best way to insert the sensor into the soil? A: Insert the sensor vertically into the soil, ensuring that the probes are fully in contact with the soil but not forcing it into hard soil, which could damage the probes.