Create Makers

Soil Moisture Sensor With Arduino

Working Principle of Resistive Soil Moisture Sensor

Disclosure: Some of the links below are affiliate links and we only earn a small commission if you purchase through our links at no additional cost to you. The earning mainly used for maintaining the website.

Water is important to keep us healthy – plants as well. Overwatering or underwatering is bad for the growth of plants. Then how do we know the right amount of water needed by the plants? By asking the plants? Or take a soil sample and taste it? Here, a soil moisture sensor comes in handy to monitor the moisture content of the soil.

Starter Pack

  1. Arduino Board
  2. Resistive Soil Moisture Sensor
  3. Jumper Wires
  4. Breadboard

How a Resistive Soil Moisture Sensor Works?

As the name “resistive”, a soil moisture sensor’s working principle is based on resistance co-responding to soil’s moisture content. The relationship of the probe’s resistance is inversely proportional to the soil moisture level.

The two exposed conductive plates on the fork-shaped probe act as a variable resistor. When more water is in the soil, the resistance will be low. If less water is present in the soil, the conductivity will become poor which results in high resistance. The sensor then outputs the voltage accordingly to the resistance. This voltage is useful to determine the moisture level of the soil or trigger an action like irrigating the plants.

See how is the resistance value changes when different moisture of soil (tissue) are put onto the probe.

Hardware Overview

The soil moisture sensor consists of two parts – probe and module.

The Fork-Shaped Probe

A very simple probe that to be inserted into the soil. The two metal plates are responsible for electron conductivity when water is present. Power is supplied from the electronic module and returns a certain voltage depending on the moisture content of the soil.

The Module

The main function of this module is to convert the analog signal from the probe to a digital signal. This sensor can work with both analog and digital signals.
When working with an analog signal, a microcontroller is needed to process the signal and set the threshold for triggering some actions.
While working with the digital signal can with or without the microcontroller. A high precision comparator, LM393 converts analog signal from the probe to digital signal. There is a built-in potentiometer for adjusting the sensitivity of the digital output to set threshold. The module will always be HIGH if below the threshold. A LOW output is when the moisture content of the soil exceeds the threshold.

Reading Soil Moisture Sensor Values

VCC

Power supply from 3.3V to 5.0V.

GND

Ground.

Digital Output

"HIGH" or "LOW" signal depends on threshold set on trim pot.

Analog Output

Output values to be read by microcontroller. Values may vary depend on power supply.

Interfacing the soil moisture sensor is very simple. There are two ways to connect it to read the output – analogue and digital.

Analogue Output

Arduino Pins

Module Pins

VCC

VCC

GND

GND

A0

A0

Analog Output Codes

const int soilAnalog = A0;
int soilVal;

void setup() {
 Serial.begin(9600);
 delay(100);
}


void loop() {
 soilVal = analogRead(soilAnalog);
 Serial.print("Analog Output: ");
 Serial.println(soilVal);
 delay(1500)
}
analogRead(val)

To read analog values from the sensor.

Analog Output with Condition Codes

const int soilAnalog = A0;
int soilVal;

void setup() {
 Serial.begin(9600);
 delay(100);
}


void loop() {
 soilVal = analogRead(soilAnalog);
 Serial.print("Analog Output: ");
 Serial.println(soilVal);

 if(soilVal >= 700){
  Serial.println("Status: Soil is too dry, please the plants");
 }

 else if(soilVal >= 400 && soilVal < 700){
  Serial.println("Status: Soil is good");
 }

 else{
  Serial.println("Status: Soil is too wet, stop watering the plants");
 }


 Serial.println();
 delay(1500)
}
if(condition 1){
 action 1
}

else if(condition 2){
 action 2
}

else{
 action 3
}

You can add condition statements to do some actions. In our case, we set the value “700” as dry condition and we print a message at the serial monitor. Other than printing a message, you can control Arduino to turn on the water pump to water the plants.
The values here are the condition we set for the moisture level contents. They can be different depending on the types of plants. This is just an example of an application only.

Digital Output

Arduino Pins

Module Pins

VCC

VCC

GND

GND

D2

D0

Digital Output Codes

const int soilDigital = 2;
int soilVal;

void setup() {
 Serial.begin(9600);
 delay(100);
}


void loop() {
 soilVal = digitalRead(soilDigital);
 Serial.print("Digital Output: ");
 Serial.println(soilVal);
 delay(1500)
}
digitalRead(val)

To read digital values from the sensor.

Digital Output with Condition Codes

const int soilDigital = 2;
int soilVal;

void setup() {
 Serial.begin(9600);
 delay(100);
}


void loop() {
 soilVal = digitalRead(soilDigital);
 Serial.print("Digital Output: ");
 Serial.println(soilVal);

 if(soilVal){
  Serial.println("Status: Soil is too dry, please the plants");
 }

 else{
  Serial.println("Status: Soil is good");
 }


 Serial.println();
 delay(1500)
}

The analog output can have more values to play with. Digital outputs only have two, either HIGH or LOW. So, there are only two conditions. These codes can differentiate dry and wet conditions. They can not differentiate between wet and very wet conditions.

BONUS: A Better Way to Hookup the Resistive Soil Moisture Sensor

Arduino Pins

Module Pins

D3

VCC

GND

GND

D2

D0

const int soilVCC = 3;
const int soilDigital = 2;
int soilVal;

void setup() {
 pinMode(soilVCC, OUTPUT);
 digitalWrite(soilVCC, LOW);
 Serial.begin(9600);
 delay(100);
}


void loop() {
 digitalWrite(soilVCC, HIGH);
 delay(50);
 soilVal = digitalRead(soilDigital);
 delay(50);
 digitalWrite(soilVCC, LOW);
 Serial.print("Digital Output: ");
 Serial.println(soilVal);

 if(soilVal){
  Serial.println("Status: Soil is too dry, please the plants");
 }

 else{
  Serial.println("Status: Soil is good");
 }


 Serial.println();
 delay(1500);
}

If we keep on supplying power to the sensor, the conductive metal on the probe will corrode very fast and can not last long.

pinMode(pin, mode)

To tell Arduino to use the selected pin as input or output. Our case here we set the pin as “OUTPUT” mode to supply power to the sensor.

digitalWrite(pin, value)

To write “HIGH” or “LOW” value to digital pin.

We configure Digital Pin 3 of Arduino as output to supply voltage to power up the soil moisture sensor. When we want to read soil moisture contents, we set Digital Pin 3 as “HIGH” to give power supply. After reading the soil moisture contents, we set Digital Pin 3 to “LOW” again to cut off the power. This method can prolong the life of the resistive soil moisture sensor.

Nay! We Love Videos

Bye Bye

Too much or less water is bad for your plants. They can not tell you how much is enough for them to grow healthy. Here, a soil moisture sensor comes in handy to help you to monitor your soil moisture contents. You can start growing beautiful plants without all the hassle.

Hope you find this tutorial helpful in your projects. Subscribe to our newsletter for more tutorials.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments