The YL-69 Module LM393 is a soil moisture sensor designed to measure the moisture content of soil, making it an essential tool for agriculture, gardening, and environmental monitoring. The module uses an LM393 comparator to provide a digital output when the soil moisture level crosses a certain threshold, which can be adjusted using an onboard potentiometer. It can also provide an analog output that gives a variable voltage depending on the moisture level.
Pin | Description |
---|---|
VCC | Connect to 3.3V-5V power supply |
GND | Connect to ground |
D0 | Digital output; goes high or low based on moisture threshold |
A0 | Analog output; provides a variable voltage related to moisture level |
// Define the sensor pins
const int analogPin = A0; // Analog output from the sensor
const int digitalPin = 2; // Digital output from the sensor
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
pinMode(digitalPin, INPUT); // Set the digital pin as input
}
void loop() {
int analogValue = analogRead(analogPin); // Read the analog value
bool isDry = digitalRead(digitalPin); // Read the digital value
// Print the analog value to the serial monitor
Serial.print("Moisture Level (Analog): ");
Serial.println(analogValue);
// Print the digital status to the serial monitor
Serial.print("Is the soil dry? (Digital): ");
Serial.println(isDry ? "Yes" : "No");
delay(1000); // Wait for a second before reading again
}
Q: Can the YL-69 Module be used with a 5V system? A: Yes, the module can operate with a 3.3V to 5V power supply.
Q: How do I know if the sensor is working correctly? A: Test the sensor by placing it in dry soil and slowly adding water. The analog value should increase, and the digital output should change when the threshold is crossed.
Q: Is it possible to use the sensor without an Arduino? A: Yes, the sensor can be used with any microcontroller that has analog and digital input pins.
Q: How long do the sensor probes last? A: The lifespan of the probes depends on usage and environmental conditions. Regular cleaning and minimizing exposure to moisture can extend their life.
Q: Can the sensor be left in the soil permanently? A: While the sensor can be left in the soil, prolonged exposure to moisture can lead to corrosion. It's recommended to only power the sensor when measurements are needed.