Complete Guide to Use Soil Moisture Sensor w/ Examples

Complete Guide to Use Soil Moisture Sensor w/ Examples © CC BY-SA

In this tutorial, you will learn how to use a soil moisture sensor. Practical examples are also provided to help you master the code.

  • 4,496 views
  • 7 comments
  • 23 respects

Components and supplies

Apps and online services

About this project

You can read this and other amazing tutorials on ElectroPeak's official website

Overview

In this tutorial, you will learn how to use a soil moisture sensor. Practical examples are also provided to help you master the code.

What You Will Learn:

  • How soil moisture sensors work
  • How to use soil moisture sensor with Arduino

How Does It Work?

The soil moisture sensor consists of two probes that measure the volume of water in the soil. The two probes allow the electric current to pass through the soil and, according to its resistance, measures the moisture level of the soil.

When there is more water, the soil conducts more electricity, which means that the resistance will be less. So the moisture level will be higher. Dry soil reduces conductivity. So, when there is less water, the soil conducts less electricity, which means it has more resistance. So the moisture level will be lower.

Soil Moisture Sensor – Pin Out

There are different types of soil moisture sensor on the market, but their working principal are all similar; so if your sensor is different from the one you see in this tutorial, don’t worry! All of these sensors have at least three pins: VCC, GND, and AO. The AO pin changes according to the amount of moisture in the soil and increases as there is more water in the soil. Some models have an additional base called DO. If the moisture amount is less than the permissible amount (which can be changed by the potentiometer on the sensor) the DO pin will be “1”, otherwise will remain”0″.

Interfacing Soil Moisture Sensor and Arduino

In this tutorial, we have used the Waveshare Soil Moisture Sensor. It has a detection length of 38mm and a working voltage of 2V-5V. It has a Fork-like design, which makes it easy to insert into the soil. The analog output voltage boosts along with the soil moisture level increases.

Circuit

Using this sensor is quite easy. You connect the AO pin to any analog pin. If your sensor has a DO pin, you can connect it to any digital pin.

Code

/* 
 Soil Moisture Sensor  
 modified on 21 Feb 2019 
 by Saeed Hosseini @ Electropeak 
 https://electropeak.com/learn/ 
*/
#define SensorPin A0 
float sensorValue = 0; 
void setup() { 
 Serial.begin(9600); 
} 
void loop() { 
 for (int i = 0; i <= 100; i++) 
 { 
   sensorValue = sensorValue + analogRead(SensorPin); 
   delay(1); 
 } 
 sensorValue = sensorValue/100.0; 
 Serial.println(sensorValue); 
 delay(30); 
} 

For each soil moisture measurement, we took an average of 100 sensor data to make the data more stable and accurate.

Please note that after 10-20 months, the sensor may get oxidized in the soil and lose its accuracy. Therefore you should replace it every year. Since it has a low price and easy setup, it worths the annual replacement.

Project: Make Your Plant SMART!!!

Code

codeArduino
/* 
  Soil Moisture Sensor  
  modified on 21 Feb 2019 
  by Saeed Hosseini @ Electropeak 
  https://electropeak.com/learn/ 
*/
#define SensorPin A0 
 float sensorValue = 0; 
void setup() { 
  Serial.begin(9600); 
} 
void loop() { 
  for (int i = 0; i <= 100; i++) 
  { 
    sensorValue = sensorValue + analogRead(SensorPin); 
    delay(1); 
  } 
  sensorValue = sensorValue/100.0; 
  Serial.println(sensorValue); 
  delay(30); 

}

Comments

Similar projects you might like

How to Use a Soil Moisture Sensor

by MisterBotBreak

  • 4,066 views
  • 7 comments
  • 31 respects

The Quantified Cactus: An Easy Plant Soil Moisture Sensor

Project tutorial by Jen Looper

  • 6,847 views
  • 2 comments
  • 25 respects

Soil Moisture Sensor With LCD Display

Project tutorial by Patel Darshil

  • 19,347 views
  • 4 comments
  • 37 respects

Using the YL-39 + YL-69 Soil Humidity Sensor with Arduino

Project tutorial by Sorin Trimbitas

  • 29,396 views
  • 6 comments
  • 19 respects

Wireless Soil Moisture Probe with Helium and DFRobot

Project tutorial by Mark Phillips and Peter Main

  • 10,435 views
  • 9 comments
  • 27 respects

DIY Plant Moisture Sensor

Project tutorial by millerman4487

  • 3,665 views
  • 4 comments
  • 23 respects
Add projectSign up / Login