Arduino Soil Moisture Sensor Getting Started Tutorial

(Last Updated On: July 17, 2019)

soil moisture sensor


In this Tutorial, you will learn how to use a soil moisture sensor with Arduino. A soil moisture sensor has many applications, especially in agriculture. Before I use this sensor in some intermediate and advanced level projects, first I decided to make a very basic getting started tutorial to explain the basic connections and programming. This tutorial covers

  1. Basic introduction
  2. Interfacing
  3. Programming and finally
  4. Testing

Let’s get started….

The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:

Arduino Uno:

Mega 2560:
Soil Moisture Sensor:
12v 10A SPDT relay:
2n2222 npn transistors:
10k Resistor:
lm7805 Voltage Regulator:
330-ohm resistors pack:
female DC power jack socket:
470 uf capacitors:
5×7 cm vero board:
female headers:
connection wires:
Super Starter kit for Beginners:
Jumper Wires:
Bread Board:
12v Adaptor:
PCB plate:
Variable Supply:
Digital Multimeter:
Vero Board / strip board:
Soldering iron kit: “best” You guys should definitely purchase this:
Solder wire:
Wire Stripper:
wire cutter:
PCB small portable drill machine:

FC-28 Soil Moisture sensor:

soil moisture sensor

A soil moisture sensor actually consists of two components.

This is  component number1

soil moisture sensor

And this is  component number 2.

soil moisture sensor

Component number 1 is basically a two-legged lead, that goes into the soil, as you can see this component has two male headers which connect to the component number 2 which is an amplifier/ Analog to digital converter circuit.

soil moisture sensor

This circuit is connected with the Arduino using these 4 male headers. These 4 male headers are labeled with Vcc.Ground….D0 and A0. D is for the digital while A is for the analog. So it means we can get values in both Digital and Analog. The digital output is in the form of 0 or 1which can be controlled using this potentiometer. This module has also two led’s, one led is the power ON led, while the other led works with the digital output pin. When the moisture is below a certain value which is set using the potentiometer then led remains off. When there is moisture, this led turns ON.  While the analog output can be any number between 0 and 1024. This value will entirely depend on the water content present in the soil. So now we can say that the soil moisture sensor has two modes

  1. Analog Mode and
  2. Digital Mode.

First of all let’s cover the analog Mode.

soil moisture sensor

The component 1 which is a two-legged lead is connected with component 2 using two jumper wires, it doesn’t matter which pin you connect with which one, as it has no polarity. The VCC pin is connected with 5volts, The ground wire which is the blue wire is connected with the Arduino’s ground, while the analog output pin is connected with pin A1 of the Arduino.

Analog Mode Programming:

As you know my friends every Arduino and the mega program has at least two functions, which are the void setup and void loop function. void means that this function is not returning any value, while the empty parenthesis means that this function is not taking any arguments as the input.

reads the moisture sensor and store the value in msvalue variable. And then using the serial.println function we send the value to the serial monitor, where we can check the value of the moisture sensor.

 Then using two if conditions we can turn on and turn off the led. When the sensor value is greater than 500 and the flag is false then turn on the led, which means that it needs water. And then change the flag status to true and use a delay of 1 second as 1000 milliseconds are equal to 1 second.

If the value is less then 300 then simply turn off the led. And change the flag status back to false.

I have already uploaded this program let’s watch this in action…

soil moisture sensor

Soil Moisture Sensor Digital Mode:

soil moisture sensor

Now simply remove the yellow wire and connect it with the digital output pin and connect the other end with digital pin 4 of the Arduino.

Digital Mode Programming:

Watch Video Tutorial:

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply