กลับไปหน้ารวมไฟล์
yl69-soil-moisture-sensor-with-arduino-sheekar-banerjee-e2d9ca.md

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:

Serial Monitor Output from Arduino IDE while getting data from YL69 Soil Sensor

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.

  1. 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.
  2. The current flows down to the LM393 analog amplifier board.
  3. The analogRead() Math: The signal travels to Arduino pin A0 where the 10-bit ADC translates the 0-5V signal into a number from 0 to 1023.
    • 0 suggests a short circuit (You dropped the sensor in a glass of pure water).
    • 1023 suggests 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 VCC pin directly to the 5V pin 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).

ข้อมูล Frontmatter ดั้งเดิม

title: "YL69 Soil Moisture Sensor with Arduino | Sheekar Banerjee"
description: "This project is about interfacing YL69 soil moisture or hygrometer sensor which is generally used to detect the humidity of the soil."
author: "sheekar"
category: ""
tags:
  - "weather"
  - "environmental sensing"
  - "embedded"
  - "smart appliances"
  - "greener planet"
  - "data collection"
  - "plants"
  - "internet of things"
  - "monitoring"
  - "garden"
views: 7932
likes: 2
price: 299
difficulty: "Intermediate"
components:
  - "1x YL-69 Soil Hygrometer Humidity & Soil Moisture Detection Sensor For Arduino"
  - "1x Arduino UNO"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "a2b1433b303f5f5400c10b7948dfb45874f86e5b719aba67a8b20199270fe6a7"
encryptedPayload: "U2FsdGVkX19qLPWOM1natFcfMl9muNo8M632JUHZ4dGNvhOvEt5Lmq5Eid16OK83LwaybkJ86J6tJswKBDj/qStjdxQT6i4PfmB4XYqUTSY="
seoDescription: "Learn how to interface YL69 soil moisture sensor with Arduino to detect soil humidity in this project."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/yl69-soil-moisture-sensor-with-arduino-sheekar-banerjee-e2d9ca_cover.jpg"
lang: "en"