How to Detect Soil Moisture

In this tutorial, you will learn how to detect humidity in the soil with a soil hygrometer humidity detection moisture sensor and an Arduino.

Parts Required

  • Arduino
  • Soil Hygrometer Humidity Detection Moisture Sensor
  • LED
  • Jumper wires
  • Breadboard


How Soil Moisture Sensor works?

The working of the soil moisture sensor is pretty straightforward. The fork-shaped probe with two exposed conductors acts as a variable resistor (just like a potentiometer) whose resistance varies according to the water content in the soil.

soil moisture sensor working.gif
[1] Image source.

This resistance is inversely proportional to the soil moisture. The more water in the soil means better conductivity and will result in a lower resistance.


#define soilWet 100   
#define soilDry 500   

// Sensor pins
#define sensorPower 12
#define sensorPin A0

void setup() {
  pinMode(sensorPower, OUTPUT);
  // Initially keep the sensor OFF
  digitalWrite(sensorPower, LOW);

void loop() {
  //get the reading from the function below and print it
  int moisture = readSensor();
  Serial.print("Analog Output: ");

  // Determine status of our soil
  if (moisture < soilWet) {
    Serial.println("Solo Seco  - Tempo de Regar!");
  } else if (moisture >= soilWet && moisture < soilDry) {
    Serial.println("Humidade Perfeita");
  } else {
    Serial.println("Solo Humido");
  delay(1000);  // Take a reading every second for testing

//  This function returns the analog soil moisture measurement
int readSensor() {
  digitalWrite(sensorPower, HIGH);  // Turn the sensor ON
  delay(10);              // Allow power to settle
  int val = analogRead(sensorPin);  // Read the analog value form sensor
  digitalWrite(sensorPower, LOW);   // Turn the sensor OFF
  return val;             // Return analog moisture value




Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!

Hello! We have noticed you are using an ad blocker. Our website is funded by advertising which allows you to access all our content for free. By disabling your ad blocker, you are contributing to the sustainability of our project and ensuring we continue to provide high-quality, useful tutorials. We appreciate your support!