This project is about the interfacing of YL69 soil hygrometer sensor module with Arduino for measuring humidity of soil. This module can be interfaced with other microcontrollers and processors as well. This sensor module has a wide range of potentiality in the field of Sensor based Smart Agriculture, Vertical farming and Internet of Things (IOT).
Circuit Planning:
Arduino UNO R3 YL69 Sensor
Pins--> Vin Vcc
Pins--> GND GND
Pins--> A0 A0
Code:
int rainPin = A0;
// you can adjust the threshold value
int thresholdValue = 1000;
void setup(){
pinMode(rainPin, INPUT);
Serial.begin(9600); //Sensor streaming 9600 bits of data per seconds
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(rainPin);
Serial.println("Soil-humidity sensor value: ");
Serial.print(sensorValue);
if(sensorValue < thresholdValue){
Serial.println(" - Plant doesn't need watering now...");
}
else {
Serial.println(" - Time to water your plant now...");
}
delay(1500);
}
Results:
SerialMonitor:
SerialPlotter:
🛠️ เจาะลึกเบื้องหลังการทำงาน (Deep Dive / Technical Analysis)
The YL-69 Sensor (often packaged with the LM393 comparator chip) is the introductory standard for all agricultural Arduino projects. While the "Automatic Watering System" controls the pumps, this foundational lesson taught by engineers like Sheekar Banerjee focuses purely on safely reading and mapping the raw electrical conductivity of the dirt itself.
Analog-to-Digital Conversion (ADC)
The YL-69 is essentially just a giant variable resistor made of two exposed aluminum prongs.
- The Circuitry: The two prongs are pushed deep into the soil. Because water conducts electricity, the wetter the soil, the lower the resistance between the two prongs.
- The current flows down to the LM393 analog amplifier board.
- The
analogRead()Math: The signal travels to Arduino pinA0where the 10-bit ADC translates the 0-5V signal into a number from 0 to 1023.0suggests a short circuit (You dropped the sensor in a glass of pure water).1023suggests infinite resistance (Bone dry sand).
Preventing Galvanic Corrosion
The biggest failure of the YL-69 is that it dissolves within 3 days if left powered on in wet dirt.
- This is called Galvanic Corrosion (electrolysis tears the copper traces right off the fiberglass board).
- The Engineer's Solution: Do NOT wire the sensor's
VCCpin directly to the5Vpin on the Arduino. - Wire the sensor's VCC to a digital pin (e.g.,
Pin 7). - In the code:
digitalWrite(7, HIGH); delay(100); moisture = analogRead(A0); digitalWrite(7, LOW); delay(600000); - By only powering the sensor for a tenth of a second every 10 minutes, the sensor will physically survive buried in the dirt for years instead of days!
Setup List
- Arduino Uno/Nano.
- YL-69 / HL-69 Soil Moisture Probes with LM393 Comparator module.
- (Warning: Ensure the probe prongs are pushed beneath the root level of the plant for accurate moisture readings, not just the topsoil).