Soil Moisture Sensor

Moisture Sensor

Related image

A typical Soil Moisture Sensor consist of two components. A two legged Lead, that goes into the soil or anywhere else where water content has to be measured. This has two header pins which connect to an Amplifier/ A-D circuit which is in turn connected to the Arduino.

Image result for rain sensor

The Amplifier has a Vin, Gnd, Analog and Digital Data Pins. This means that you can get the values in both Analog and Digital forms.

How does it work?

The voltage that the sensor outputs changes accordingly to the water content in the soil.

Most soil moisture sensors are designed to estimate soil volumetric water content based on the dielectric constant (soil bulk permittivity) of the soil. The dielectric constant can be thought of as the soil’s ability to transmit electricity. The dielectric constant of soil increases as the water content of the soil increases. This response is due to the fact that the dielectric constant of water is much larger than the other soil components, including air. Thus, measurement of the dielectric constant gives a predictable estimation of water content.

When there is water, the soil will conduct more electricity, which means that there will be less resistance. Dry soil conducts electricity poorly, so when there is less water, then the soil will conduct less electricity, which means that there will be more resistance.

The output can be a digital signal (D0) LOW or HIGH, depending on the water content. If the soil humidity exceeds a certain predefined threshold value, the modules outputs LOW, otherwise it outputs HIGH. The threshold value for the digital signal can be adjusted using the potentiometer.

The output can be a analog signal and so you’ll get a value between 0 and 1023.

Soil Moisture Sensor with the Arduino

In this example, you’ll read the analog sensor output values using the Arduino and print those readings in the Arduino IDE serial monitor.

Components Required

  • YL-69 moisture sensor
  • Arduino UNO
  • 1x Breadboard
  • 220 Ohm Resistors
  • Red LED
  • Green LED
  • Jumper wires


To complete the project, follow these schematics:

moisture sensor fritzing


Analog Mode

/*  SOli Mositure sensor Tutorial

int rainPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 800;

void setup(){
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(rainPin);
  if(sensorValue < thresholdValue){
    Serial.println(" - Doesn't need watering");
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
  else {
    Serial.println(" - Time to water your plant");
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);

Open the Arduino IDE serial monitor to see the values. Then, try your sensor in a wet and in a dry soil and see what happens.

When the analog value goes above a certain threshold, a red LED will turn on (indicates that the plant needs watering), and when the value goes below a certain threshold, a green LED will turn on (indicates that the plant is ok).

Digital Mode

Related image


/*  SOli Mositure sensor Tutorial
int led_pin =13;

int sensor_pin =8;

void setup() {

  pinMode(led_pin, OUTPUT);

  pinMode(sensor_pin, INPUT);


void loop() {

  if(digitalRead(sensor_pin) == HIGH){

    digitalWrite(led_pin, HIGH);

  } else {

    digitalWrite(led_pin, LOW);