The Soil Moisture Sensor is an electronic device designed to measure the moisture content in soil, providing valuable data for agricultural applications, gardening, and environmental monitoring. By detecting the conductivity between two probes, the sensor can infer the level of moisture present, as water conducts electricity more effectively than dry soil.
Pin Name | Description |
---|---|
VCC | Power supply (3.3V to 5V) |
GND | Ground |
AOUT | Analog output (moisture level voltage) |
DOUT | Digital output (threshold-based moisture) |
// Define the sensor pin
const int moistureSensorPin = A0; // Analog input pin that the sensor is attached to
const int sensorPowerPin = 7; // Digital pin used to power the sensor
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
pinMode(sensorPowerPin, OUTPUT); // Set the sensor power pin as an output
}
void loop() {
digitalWrite(sensorPowerPin, HIGH); // Turn the sensor on
delay(10); // Wait 10 milliseconds for stabilization
// Read the value from the sensor
int sensorValue = analogRead(moistureSensorPin);
digitalWrite(sensorPowerPin, LOW); // Turn the sensor off
// Print the moisture level to the serial monitor
Serial.print("Moisture level: ");
Serial.println(sensorValue);
delay(1000); // Wait for a second before reading again
}
Q: Can the sensor be left in the soil permanently? A: It is not recommended to leave the sensor in the soil permanently as it can lead to corrosion of the probes.
Q: Is the sensor waterproof? A: The probes are water-resistant but the electronic components are not. Avoid exposing them to water.
Q: How do I set the threshold for the digital output? A: The threshold can be set through a potentiometer on the sensor module or via software in the microcontroller.
Remember to keep the documentation updated with any changes to the component or its usage, and always provide clear and accurate information to ensure the best user experience.