Toggle Nav

Complete Guide to Use Soil Moisture Sensor & Interfacing w/ Arduino

Table of Contents


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

Soil Moisture Sensor - 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.


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.


  Soil Moisture Sensor  
  modified on 21 Feb 2019 
  by Saeed Hosseini @ Electropeak 
#define SensorPin A0 
 float sensorValue = 0; 
void setup() { 
void loop() { 
  for (int i = 0; i <= 100; i++) 
    sensorValue = sensorValue + analogRead(SensorPin); 
  sensorValue = sensorValue/100.0; 

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.

Related Projects

Buy A Soil Moisture Sensor

Liked What you see?

Get updates and learn from the best

More To Explore

Comments (6)

  • Joe Reply

    regarding the moisture sensor, what is the range of readings and how does one interpret them? I’m guessing 0-1024 based on standard base-2 math and observable changes, but it is unclear how to utilize the sensor readings once acquired. is 0 totally dry? Thanks so much

    April 18, 2020 at 3:46 pm
    • Amir Mogoeir Reply

      The output of this sensor in analog, thus you get 0-5V for output. 0V is totally dry and 5V in the maximum wetness. The rest is up to you how to convert it to 0-1023.

      May 30, 2020 at 1:13 pm
  • Raghul Prasanth Reply

    Hi sir i want to make this project as it is shown in the video with oled display. And i have a problem with air and waiter value pf this sensor the water value changes from 240-310 and air value is between 630-1014. Can you please help me in this

    October 1, 2020 at 1:02 pm
    • Mohammadreza Akbari Reply

      Hi Raghul Prasanth. I can’t understand what u mean about “air value” and “waiter value”. Can you explain more?

      October 26, 2020 at 11:49 am
  • yena Reply

    hi may i know why my serial monitor not reading?

    January 31, 2021 at 8:06 am
    • Mehran Maleki Reply

      Hi. Check the baud rate of your Serial Monitor and make sure it’s set to 9600.

      February 2, 2021 at 11:18 am

Leave a Reply

Your email address will not be published. Required fields are marked *