In this article, we are going to interface a Soil moisture sensor FC-28 with Arduino. This sensor measures the volumetric content of water inside the soil and gives us the moisture level as output. The sensor is equipped with both analog and digital output, so it can be used in both analog and digital mode. In this article, we are going to interface the sensor in both modes. So let’s begin our tutorial on interfacing Arduino and Soil moisture sensor.

Working of Sensor

The soil moisture sensor consists of two probes which are used to measure the volumetric content of water. The two probes allow the current to pass through the soil and then it gets the resistance value to measure the moisture value.

When there is more water, the soil will conduct more electricity which means that there will be less resistance. Therefore, the moisture level will be higher. Dry soil conducts electricity poorly, so when there will be less water, then the soil will conduct less electricity which means that there will be more resistance. Therefore, the moisture level will be lower.

This sensor can be connected in two modes; Analog mode and digital mode. First, we will connect it in Analog mode and then we will use it in Digital mode.

Like to do an exciting course on Arduino with 12+ Projects?

We have developed a comprehensive course on Arduino named “Arduino Course [Zero to Hero] – Learn By Doing Projects”. The course is published in partnership with Udemy – the worlds best online education platform. If you are looking to master Arduino and develop a couple really exciting projects using the Arduino platform, enrolling in this course would be the best decision you can make to achieve your dreams. So lets take a quick look at what all you will learn in this course.

View Course Details

Our course “Arduino Course [Zero to Hero]” follows a complete learn by doing approach, where you will be learning each and every concept by doing a project. The course is designed with 12+ projects ranging from easy, medium, and advanced projects. The course begins by introducing basic concepts and simple led based projects, and then moves on to explain mid level concepts like sensor interfacing, sensor based projects and finally the course teaches you how to do advanced projects and IoT (Internet of Things) based projects using the Arduino platform.

You will do the following projects in this full video course:

  1. Automatic Hand Sanitizer/Soap Dispenser
  2. Automatic Light Control using LDR
  3. Generating Patterns with LED’s
  4. Smart Door Lock using Keypads (Digital Code Lock)
  5. Home Security System (Protect against Fire accident, Gas leakage,)
  6. Weather Monitoring System (Measure Temperature & Humidity)
  7. Home Automation using Smartphone & TV Remote Control
  8. Line Follower Robot (the basics to build robots)
  9. Obstacle Avoidance Robot (learn to build intelligence in robots)
  10. Mobile Phone controlled Robot Car (wireless controlled robots)
  11. Smart Irrigation System
  12. IoT based Weather Station (Display weather data on website/web application)
View Course Details

Specifications

The specifications of the soil moisture sensor FC-28 are as follows

Input Voltage3.3 – 5V
Output Voltage0 – 4.2V
Input Current35mA
Output SignalBoth Analog and Digital

 Pin Out – Soil Moisture Sensor

The soil Moisture sensor FC-28 has four pins

  • VCC: For power
  • A0: Analog output
  • D0: Digital output
  • GND: Ground

The Module also contains a potentiometer which will set the threshold value and then this threshold value will be compared by the LM393 comparator. The output LED will light up and down according to this threshold value.

Pin Out Diagram - Soil Moisture Sensor
Pin Out – Diagram

Analog Mode – Interfacing Soil Moisture Sensor and Arduino

To connect the sensor in the analog mode, we will need to use the analog output of the sensor. When taking the analog output from the soil moisture sensor FC-28, the sensor gives us the value from 0-1023. The moisture is measured in percentage, so we will map these values from 0 -100 and then we will show these values on the serial monitor.

You can further set different ranges of the moisture values and turn on or off the water pump according to it.

Circuit Diagram

The connections for connecting the soil moisture sensor FC-28 to the Arduino are as follows.

  • VCC of FC-28 to 5V of Arduino
  • GND of FC-28 to GND of Arduino
  • A0 of FC-28 to A0 of Arduino
Interface Soil Moisture Sensor and Arduino
Circuit Diagram – Analog Mode

Analog Code 

int sensor_pin = A0;

int output_value ;

void setup() {

   Serial.begin(9600);

   Serial.println("Reading From the Sensor ...");

   delay(2000);

   }

void loop() {

   output_value= analogRead(sensor_pin);

   output_value = map(output_value,550,0,0,100);

   Serial.print("Mositure : ");

   Serial.print(output_value);

   Serial.println("%");

   delay(1000);

   }

Code Explanation

First of all, we have defined two variables; one for the soil moisture sensor pin and the other for storing the output of the sensor.

int sensor_pin = A0; // Soil Sensor input at Analog PIN A0

int output_value ;

In the setup function, the “Serial.begin(9600)” command will help in communication between the Arduino and serial monitor. Then, we will print the “Reading From the Sensor …” on the serial monitor.

void setup() {

   Serial.begin(9600);

   Serial.println("Reading From the Sensor ...");

   delay(2000);

   }

In the loop function, we will read from the sensor analog pin and will store the values in the “output_ value” variable. Then, we will map the output values to 0-100, because the moisture is measured in percentage. When we took the readings from the dry soil, then the sensor value was 550 and in the wet soil, the sensor value was 10. So, we mapped these values to get the moisture. After that, we printed these values on the serial monitor.

void loop() {

   output_value= analogRead(sensor_pin);

   output_value = map(output_value,550,10,0,100);

   Serial.print("Mositure : ");

   Serial.print(output_value);

   Serial.println("%");

   delay(1000);

   }

Digital Mode – Interfacing Arduino and Soil Moisture Sensor

To connect the soil moisture sensor FC-28 in the digital mode, we will connect the digital output of the sensor to the digital pin of the Arduino. The Sensor module contains a potentiometer with it, which is used to set the threshold value. This threshold value is then compared with the sensor output value using the LM393 comparator which is placed on the sensor module.

The LM393 comparator will compare the sensor output value and the threshold value and then gives us the output through the digital pin. When the sensor value will be greater than the threshold value, then the digital pin will give us 5V and the LED on the sensor will light up and when the sensor value will be less than this threshold value, then the digital pin will give us 0V and the light will go down.

Circuit Diagram

The connections for connecting the soil moisture sensor FC-28 to the Arduino in digital mode are as follows.

  • VCC of FC-28 to 5V of Arduino
  • GND of FC-28 to GND of Arduino
  • D0 of FC-28 to pin 12 of Arduino
  • LED positive to pin 13 of Arduino
  • LED negative to GND of Arduino
Interface Arduino and Soil Moisture Sensor
Circuit Diagram – Digital Mode

Digital Code

int led_pin =13;

int sensor_pin =8;

void setup() {

  pinMode(led_pin, OUTPUT);

  pinMode(sensor_pin, INPUT);

}

void loop() {

  if(digitalRead(sensor_pin) == HIGH){

    digitalWrite(led_pin, HIGH);

  } else {

    digitalWrite(led_pin, LOW);

    delay(1000);

  }

}

Code Explanation

First of all, we have initialized two variable for connecting the LED pin and the Sensor digital pin.

int led_pin =13;

int sensor_pin =8;

In the setup function, we have declared the LED pin as the output pin because; we will power the LED through that pin. Then, we declared the sensor pin as input pin because the Arduino will take the values from the sensor through that pin.

void setup() {

  pinMode(led_pin, OUTPUT);

  pinMode(sensor_pin, INPUT);

}

In the loop function, we have read from the sensor pin. If the output value of the sensor will be higher than the threshold value, then the digital pin will be high and the LED will light up. If the sensor value will be lower than the threshold value, then the LED will go down.

void loop() {

  if(digitalRead(sensor_pin) == HIGH){

    digitalWrite(led_pin, HIGH);

  } else {

    digitalWrite(led_pin, LOW);

    delay(1000);

  } }

So that finishes our tutorial on interfacing Arduino and Soil moisture sensor.If you got any doubts, please ask in the comments section.

Photographs

Video

Applications of Soil Moisture Sensor

A Soil Moisture Sensor has many applications, especially in agriculture. Irrigation is a key factor in farming. Detecting the amount of moisture in the soil and managing irrigation systems (turn on the system when the moisture level falls below a certain predefined value) helps to avoid a lot of wastage of water and human resources. These kinds of sensors make automation of farming easier. This is also used in controlled environments where experiments are conducted.

Author

32 Comments

  1. In map function, what is the 3rd argument? In program it’s 0 and in explanation it is 10.

  2. GAUTAM BIWAL

    In this program i can’t able to found where you have mentioned the threshold value for the sensor.

    • Dattatreo Sikdar

      output_value = map(output_value,550,10,0,100);

      Here is the threshold value for the sensor….

  3. how do i split the 5V VCC from the arduino to power 2 of these?
    Thanks!

  4. FYI, on the digital version of the circuit, the pic of the wiring and wiring instructions don’t match – the pic is accurate to the code so as long as you follow the pic you’ll be fine.

  5. Hello my serial monitor showing -85% only please help

  6. hi can you help us we are using 12v soil humidity sensor but it didn’t work. thank you

    • Try using relay to the soil moisture sensor

  7. I want this

    Proteus library for FC-28 soil moisture sensor

  8. if i want to connect multiple soil moisuter sensor to one ardiuno what i do

    • JayRonRon

      You can share the 5V signal and the ground wire. The signal pin would then be different for each sensor. You could plug the first sensor into A0 and the second into A1 and so on. Just remember you can only draw 1A from the 5V supply so if you need a few sensors that will work but there is a limit before you start over drawing current. For the code, I recommend starting with a simple change. They only have 1 sensor but you can add more by initializing the following and propogated it through the code:

      int sensor_pin0 = A0;
      int output_value0 ;
      int sensor_pin1 = A1;
      int output_value1 ;

      That will initiate 2 sensor pins and output values you can use.

  9. Afzal Raza

    hello, it was really helpful, but have a doubt
    i have a sensor exactly like you have but…it does not have analog output (A0),
    it has only digital output (D0)..
    yes i have saw that you have also given code for digital output (pin D0)..in my case i don’t have sound buzzer with me, what can i do…is it necessary to buy one, or by just connecting the sensor D0 pin to digital pin 8 on arduino…and can i see the output in serial monitor

  10. Dear JoJo,

    Thanks for the clear explanation. I have it all setup and working. I connected both the Digital and the Analog pins to be able to read the moisture percentages as well check on the threshold value. My assumption was that my led connected to pin 13 would be HIGH at the same time as the D0 Led on the moisture sensor. This is however not the case.

    Do you have an explanation for this?

    Thanks!

    • Sorry, I noticed that when the D0 led burns it actually returns a low to the digital pin. Contrary to what I expected….

      Solved by changing my if-statement.

  11. Julian Rogers

    Hi. I assume this module measures resistance between the probes as a proxy for moisture content. If the supply to the electrodes is DC, as I assume it is, polarization will occur on the electrodes. This involves the production of bubbles of gas caused by electrolysis. After a short time these interrupt the current flow and the reading drops. I believe this can be avoided by measurement using AC rather than DC but that complicates the circuit.

  12. Nishant Kumar Rai

    What’s the difference between analog and digital modes?

    • analog pin gives the value in between 0 and 1023
      digital pins gives only zeros and ones

  13. butterly biggledown

    What about electrolysis on the hygrometer? It will decay.

  14. Thanks Jijo. I got this working with your help.
    I doubt though. My moisture sensor is not giving a consistent reading. It starts with low %age, reaches a level then starts dropping again.
    Any Idea on how to stabilise the readings?

    • jojo

      Which sensor are you using? You might have to calibrate the sensor. Read the sensor datasheet.

    • KARTHIKEYAN.S

      It’s not a problem in case if you don’t have buzzer.inspite of buzzer you can use LED for indication.you can also use digital output for coding but you need to change some codes in the program.