DIY Soil Testing with Arduino and FC-28 Moisture Sensor




In this article, we are going to interface an FC-28 Soil moisture sensor with an Arduino. This sensor measures the volumetric content of water in soil and gives us the moisture level. The sensor gives us both analog and digital output, so it can be used in both analog and digital mode. We are going to connect it in both modes in this article.

Arduino-soil-sensor3




How Does it Work?

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 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 is 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.

Specifications

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

  • Input Voltage: 3.3 – 5V
  • Output Voltage: 0 – 4.2V
  • Input Current: 35mA
  • Output Signal: Both Analog and Digital

Pin Out

The FC-28 soil moisture sensor  has four pins:

  • VCC: Power
  • A0: Analog Output
  • D0: Digital Output
  • GND: Ground

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

READ  Drumming MIDI Glove Using Arduino and Light Sensors

FC-28-pin-out

Analog Mode

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 a value from 0 to 1023. The moisture is measured in percentage, so we will map these values from 0 to 100 and then we will show these values on the serial monitor.

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

Circuit Diagram

The connections for theFC-28 soil moisture sensor to the Arduino are as follows:

  • VCC of the FC-28 to 5V of the Arduino
  • GND of the FC-28 to GND of the Arduino
  • A0 of the FC-28 to A0 of the Arduino

Circuit Diagram

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 “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 percentages. When we took the readings from the dry soil, the sensor value was 550, and in the wet soil, the sensor value was 10. We mapped these values to get the moisture. After that, we printed these values on the serial monitor.

READ  DIY Digital Compass (for your car)
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

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, which is used to set the threshold value. The threshold value is then compared with the sensor output value using the LM393 comparator, which is placed on the sensor module. The LM393 comparator compares the sensor output value and the threshold value, and then gives us the output through the digital pin. When the sensor value is greater than the threshold value, the digital pin will give us 5V, and the LED on the sensor will light up. When the sensor value will be less than this threshold value, the digital pin will give us 0V and the light will go down.

Circuit Diagram

The connections for the FC-28 soil moisture sensor and 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

Circuit Diagram

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);
}
}

Digital Code Explanation

First of all, we have initialized two variables for connecting the LED pin and the sensor’s 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. We declared the sensor pin as the input pin, because the Arduino will take the values from the sensor through that pin.

READ  Arduino Based Distance Measurement using Ultrasonic Sensor
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 is 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);
}
}




This Post / Project can also be found using search terms:

  • fc28 soil moisture sensor for matlab
  • moisture sensor fc-28 arduino
  • arduino soil moisture sensor test code
  • soiltesting sensor in arudino code

Leave a Comment

*
= 3 + 8

(Spamcheck Enabled)

Read previous post:
IBM shows working devices fabricated at 7nm node

Continuing semiconductor scaling down to feature sizes of 7 nm is expected to yield further gains in performance, and lower...

Close
Scroll to top