Arduino Soil Moisture Sensor Getting Started Tutorial

(Last Updated On: July 17, 2019)

soil moisture sensor

Description:

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: https://amzn.to/2tVz

1vu
Mega 2560: https://amzn.to/2ze1kdu
Soil Moisture Sensor: https://amzn.to/2W5IkFz
12v 10A SPDT relay: https://amzn.to/2MThQBK
2n2222 npn transistors: https://amzn.to/2EmXsIb
10k Resistor: https://amzn.to/2KTd6OW
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
female DC power jack socket: https://amzn.to/2KEo1gt
470 uf capacitors: https://amzn.to/2xDCOzf
5×7 cm vero board: https://amzn.to/2OHGbvn
female headers: https://amzn.to/2zqmtiJ
connection wires: https://amzn.to/2DpBuW7
Super Starter kit for Beginners: https://amzn.to/2KJvmKG
Jumper Wires: https://amzn.to/2KMoVXs
Bread Board: https://amzn.to/2MS4q8X
12v Adaptor: https://amzn.to/2Ntr6h1
PCB plate: https://amzn.to/2IUwpCt
Variable Supply: https://amzn.to/2MT4Qfj
Digital Multimeter: https://amzn.to/2Nvft9i
Vero Board / strip board: https://amzn.to/2MTf9jD
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2zfoNuJ
Solder wire: https://amzn.to/2ufUMWf
Wire Stripper: https://amzn.to/2KOqxfU
wire cutter: https://amzn.to/2ucIq14
PCB small portable drill machine: https://amzn.to/2Nu62XF

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