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

Circuit

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.

Code

#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);
  
  Serial.begin(9600);
}

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

  // 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
          
  Serial.println();
}

//  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
}

References

[1] https://lastminuteengineers.com/soil-moisture-sensor-arduino-tutorial/

[2] https://arduinopoint.com/soil-moisture-sensor-arduino-project/

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!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO