Toggle Nav

Interfacing Soil Moisture Sensor with Arduino

Table of Contents

Soil Moisture Sensor Features

Soil moisture sensors are designed in the form of two-pronged forks to easily sink into the soil. The function of this module is simple. When the sensor is placed in a conductive material (eg wet soil), the two sensor pads are connected to each other. The wetter the soil means the lower resistance between the pads, resulting in more current passing through the circuit. This way, the sensor can measure the amount of soil moisture.


The output of this sensor is analog voltage. The higher the soil moisture, the higher the output voltage.

You can download the datasheet of this module here. 

Soil Moisture Sensor Pinout

This module has 3 pins:

  •  VCC: Module power supply – 2-5 V
  •  GND: Ground
  •  AOUT: Analog voltage output

You can see the pinout of this module in the following image.

Required Materials

Hardware Components

*Arduino Nano × 1
*STM32F103C8T6 ARM Minimum Board × 1
Waveshare Moisture Sensor × 1
Female to Female jumper wire × 1

* You need either of Arduino or STM32 boards, not both of them.

Software Apps

Arduino IDE

Interfacing Soil Moisture Sensor with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to Soil Moisture Sensor. Connect wires accordingly.
If you use STM32, connect the module as shown below.

Step 2: Code

Upload the following code to your Arduino. This code converts the sensor output voltage to digital using ADC and displays the result in the serial monitor.
  Soil Moisture Sensor
  modified on 15 Sep 2020
  by Mohammad Reza Akbari @ Electropeak

// for Arduino uncomment this
//int Sensor = A0;

// for STM32 uncomment this
int Sensor = PA0;

int ad_value;

void setup()
  pinMode(Sensor, INPUT);
void loop()
  ad_value = analogRead(Sensor);
  Serial.print("Output: ");

Liked What you see?

Get updates and learn from the best

More To Explore

Leave a Reply

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