Interfacing Soil Moisture Sensor With Arduino

by Rachana Jain in Circuits > Arduino

157 Views, 0 Favorites, 0 Comments

Interfacing Soil Moisture Sensor With Arduino

Untitled design (8).png
Untitled design (9).png

If you're building a Smart Garden that can water your plants automatically and provide real-time readings of soil wetness, then you will definitely need a Soil Moisture Sensor.

In this Instructable, we'll learn how to interface a soil moisture sensor with an Arduino to monitor the moisture levels of soil. 

Supplies

  1. Arduino Uno or any compatible board
  2. Soil Moisture Sensor
  3. Jumper wires
  4. Breadboard
  5. USB cable for Arduino

Understanding the Soil Moisture Sensor

Soil Moisture Sensor Pinout.png
Soil Moisture Sensor Hardware Overview.png

A soil moisture sensor is used to measure the water content in the soil. By providing real-time data on soil moisture levels, these sensors help optimize irrigation practices, improve crop yields, and conserve water. 

FC-28 is a resistive soil moisture sensor that measures the soil's water content by determining the resistance between two electrodes inserted into the soil. The resistance varies inversely with the amount of moisture present in the soil. 

Hardware Overview

  1. Probes: Two conductive metal probes that are inserted into the soil.
  2. Comparator Module: It includes:
  • A voltage comparator (often an LM393)
  • Adjustable potentiometer for setting the threshold
  • LEDs for indicating the digital output status
  • Output pins for both digital and analog signals

Pinout and Connections

The FC-28 module typically has four pins:

  1. VCC: Power supply input, usually 3.3V or 5V.
  2. GND: Ground connection.
  3. DO (Digital Output): Provides a high or low signal based on the soil moisture level compared to a set threshold.
  4. AO (Analog Output): Provides an analog voltage that is proportional to the soil moisture level.

Connecting the FC-28 to an Arduino

Wiring Analog.JPG
Schematic Analog.JPG

Here's a simple example of how to connect the FC-28 soil moisture sensor to an Arduino and read both the digital and analog outputs:

Wiring the Circuit

  • Connect the soil moisture sensor module to the Arduino:
  • VCC on the sensor module to 5V on the Arduino
  • GND on the sensor module to GND on the Arduino
  • A0 on the sensor module to A0 on the Arduino (analog output for moisture level)
  • Connect the probe to the module:
  • Insert the two pins of the probe into the slot on the module.

Arduino Code

Copy and paste the following code into the Arduino IDE:

// Library to Run I2C LCD
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define the analog pin for the soil moisture sensor
const int soilMoisturePin = A0;

// Variables to store sensor values
int sensorValue = 0;
int moisturePercent = 0;

void setup()
{
// initialize the lcd
lcd.init();
// Turn on the Backlight
lcd.backlight();
// Clear the display buffer
lcd.clear();
// Print a message to the LCD
lcd.setCursor(0, 0);
lcd.print("Soil Moisture:");
}

void loop()
{
// Read the value from the soil moisture sensor
sensorValue = analogRead(soilMoisturePin);

// Convert the sensor value to percentage
moisturePercent = map(sensorValue, 0, 1020, 100, 0);

// Display the moisture percentage on the LCD
lcd.setCursor(0, 1);
lcd.print(moisturePercent);
lcd.print(" % "); // Clear any extra characters

// Wait for 1 second
delay(1000);
}


For a more detailed tutorial on how soil sensor works, its schematic and how to use it in analog and digital modes visit: Soil Moisture Sensor with Arduino