Measurement of moisture content of the soil is important for determining the quantity of water it contains. Proper measurement of a soils’ moisture content allows the need for irrigation to be quantified in advance for a crop showing signs of distress. In soil science, hydrology, and agricultural sciences, measuring a soils’ water content has an important role in groundwater recharge, agriculture, and soil chemistry. If the moisture content of the soil is optimum for plant growth, plants can readily absorb soil water. So, in today’s tutorial, we are going to go over a step by step procedure on how to interface an FC-28 Soil Moisture Sensor Module With an Arduino Uno MCU.
What is FC-28 Soil Moisture Sensor?
FC-28 is a soil moisture sensor or hygrometer module. It consists of two probes that are used to measure the volumetric content of water. It works by measuring the resistance between two metallic probes that are inserted into the soil to be monitored The package consists of a potentiometer, an LM393 comparator & testing probes. The sensor can be used in two distinct modes of operation Analog & digital. For analog mode, we will need to use the analog output of the sensor. Here the sensor gives us a value from 0 to 1023. in digital mode, the digital output of the sensor is connected to the digital pin of the Arduino. The sensor module contains a potentiometer, which is used to set the threshold value.
Key Features & Specifications
- Operating Voltage: 3.3V to 5V DC
- Operating Current: 15mA
- Output Digital – 0V to 5V, Adjustable trigger level from preset
- Output Analog – 0V to 5V based on infrared radiation from fire flame falling on the sensor
- LEDs indicating output and power
- Analog output of moisture content
- Digital output of moisture content with adjustable set-point
- PCB Size: 3.2cm x 1.4cm
- Comparator Chip: LM393
- Fork shaped soil probe
- 5-wire F/F interface cable, 8″ long
- Easy to use with Microcontrollers or even with normal Digital/Analog IC
Hardware Components
You will need the following parts to build this project
S.No | Component | Value | Qty |
---|---|---|---|
1) | Soil Moisture Sensor Module | FC-28 | 1 |
2) | Arduino Uno Board | Rev3, 8KB | 1 |
3) | Arduino USB Cable | – | 1 |
4) | Breadboard | – | 1 |
5) | Laptop/PC | – | 1 |
6) | Connectors | Female – Female | 1 |
7) | Jumper wires | – | As per need |
8) | Soil | – | – |
9) | Beaker/Cup | – | 1 |
FC-28 Soil Moisture Sensor Pinout
Useful Steps
1) Connect the the sensing leads of the FC-28 with the probes using 2 female jumper cables.
2) After that, connect the Vcc pin of the FC-28 sensor with the 5V pin of the Arduino uno.
Analog Mode
3) After that, join the GND pin of the FC-28 sensor with the GND pin of the arduino. Also, connect the Analog pin of the sensor with A1 pin of the arduino uno.
4) Connect your Arduino Uno to a laptop/PC and burn the code provided below on the arduino.
5) Stick the sensing element of the FC-28 in a cup filled with dry soil. The initial value from the sensor on the serial monitor will be higher than 550, meaning that the soil has low moisture content.
6) Now pour some water in to the cup/beaker. The value on the serial monitor will drop rapidly indicating that the soil moisture/water content is high.
Digital Mode
7) For Digital Mode, simply connect the D0 pin of the sensor with the Digital I/O pin 4 of the Arduino.
8) After slight tweaks to the source code (discussed below) to conform with the digital input from the sensor, power up and test the sensor.
Source Code
Analog Source Code
int msensor = A1;
int msvalue = 0;
boolean flag = false;
void setup()
{
Serial.begin(9600);
pinMode(msensor, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
msvalue = analogRead(msensor);
Serial.println(msvalue);
if ( (msvalue >= 500 ) && ( flag == false ) )
{
digitalWrite(LED_BUILTIN, HIGH);
flag = true;
delay(1000);
}
if ( (msvalue <= 300 ) && ( flag == true ) )
{
digitalWrite(LED_BUILTIN, LOW);
flag = false;
delay(1000);
}
delay(1000);
}
Digital Source Code
int msensor = 4;
boolean flag = false;
void setup()
{
Serial.begin(9600);
pinMode(msensor, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if ( (digitalRead(msensor) == HIGH ) && ( flag == false ) )
{
digitalWrite(LED_BUILTIN, HIGH);
flag = true;
delay(1000);
}
if ( (digitalRead(msensor) == LOW ) && ( flag == true ) )
{
digitalWrite(LED_BUILTIN, LOW);
flag = false;
delay(1000);
}
delay(1000);
}
FC-28 Soil Moisture Sensor Arduino Code Explanation
Analog Code
The analog operation of the above code is given below:
In this part of the declaring the analog I/O pin A1 for the A0 pin of the FC-28. Also, we have set the msvalue to 0 in order store the value from the FC-28 sensor. After that, we have set the initial state of the Boolean flag to false.
int msensor = A1;
int msvalue = 0;
boolean flag = false;
Setup()
In this part of the code, we are defining the I/O parameters for our on board LED and the A0 pin of the FC-28 Sensor. First, we are initializing the serial monitor to begin fetching the sensor readings through Serial.begin(9600). After that, we have set the A0 pin of the sensor as the input by declaring it’s pinMode() as the INTPUT. Similarly, we have set the On board LED as the Output by declaring it’s pinMode() as the OUTPUT.
void setup()
{
Serial.begin(9600);
pinMode(msensor, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
loop()
In this part of the code, we have first assigned the variable msensor to store the value from the A0 pin of the FC-28 using the analogRead() function. This value is then saved in msvalue tobe later used in the code. After that we have set a simple if-statement condition in order to check if the moisture content is above a certain threshold. If the value stored in msvalue greater than or equal to 500 and the flag variable is set to false then the arduino will trigger the onboard LED to turn ON. If the value stored in msvalue less than or equal to 300 and the flag variable is set to True then the arduino will trigger the onboard LED to turn OFF.
void loop()
{
msvalue = analogRead(msensor);
Serial.println(msvalue);
if ( (msvalue >= 500 ) && ( flag == false ) )
{
digitalWrite(LED_BUILTIN, HIGH);
flag = true;
delay(1000);
}
if ( (msvalue <= 300 ) && ( flag == true ) )
{
digitalWrite(LED_BUILTIN, LOW);
flag = false;
delay(1000);
}
delay(1000);
}
Digital Code
The analog operation of the above code is given below:
In this part of the declaring the digital I/O pin 4 for the D0 pin of the FC-28. After that, we have set the initial state of the Boolean flag to false.
int msensor = 4;
boolean flag = false;
Setup()
In this part of the code, we are defining the I/O parameters for our on board LED and the D0 pin of the FC-28 Sensor. First, we are initializing the serial monitor to begin fetching the sensor readings through Serial.begin(9600). After that, we have set the D0 pin of the sensor as the input by declaring it’s pinMode() as the INTPUT. Similarly, we have set the On board LED as the Output by declaring it’s pinMode() as the OUTPUT.
void setup()
{
Serial.begin(9600);
pinMode(msensor, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
loop()
In this part of the code, we have first used a function DigitalRead() function. The value returned from the function is then stored in the msensor variable. After that we have set a simple if-statement condition in order to check if the moisture content is above a certain threshold. If the state stored in DigitalRead(msensor) is HIGH and the flag variable is set to false then the arduino will trigger the onboard LED to turn ON. If the value stored in DigitalRead(msensor) is LOW and the flag variable is set to True then the arduino will trigger the onboard LED to turn OFF.
void loop()
{
if ( (digitalRead(msensor) == HIGH ) && ( flag == false ) )
{
digitalWrite(LED_BUILTIN, HIGH);
flag = true;
delay(1000);
}
if ( (digitalRead(msensor) == LOW ) && ( flag == true ) )
{
digitalWrite(LED_BUILTIN, LOW);
flag = false;
delay(1000);
}
delay(1000);
}
Working Explanation
The working of this sensor is as following. The FC-28 hygrometer consists of two sensing probes which determine the volumetric content of preset in any amount of soil. On sticking the two test probes in the test probes in the soil, the probes allow the current to pass through them and then fetch the resistance value in order to measure the moisture level of the soil.
When the water content is high, the soil will conduct more electricity, providing a lower resistance value in turn. Therefore, the moisture level will also be high. Since Dry soil conducts electricity poorly, therefore, then the soil will conduct less electricity which means that there will be more resistance. Therefore, the moisture level will be lower.
Aplications
- They are used in applications such as to measure the volumetric water content of the soil.
- Also used for monitoring soil health and plant disease forecasting.
See Also: How To Make A Temperature Controlled DC Fan Using An NTC Thermistor | High Power Audio Amplifier (20W) Using TDA2030 Hi-Fi Audio Amplifier IC | How To Interface MQ2 Gas Sensor With Arduino Uno | DIY Arduino Project