Capacitive Soil Moisture Sensor and Arduino

Learn how to measure soil moisture using a capacitive hygrometer with Arduino.

What is a Capacitive Hygrometer?

A capacitive hygrometer measures soil moisture using variations in capacitance. Unlike resistive sensors, it is more accurate and avoids issues with electrode oxidation. These sensors are ideal for automatic irrigation systems.

Capacitive Hygrometer Sensor

How Does It Work?

The sensor uses a 555 timer to generate a square wave. The capacitance of the soil affects the signal, resulting in a voltage difference. Higher soil moisture increases the capacitance, lowering the output voltage.

Typical voltage ranges:

Sensor Function Diagram

Wiring Diagram

Connect the sensor as follows:

Wiring Diagram

Code Examples

1. Simple Reading


const int sensorPin = A0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int humedad = analogRead(sensorPin);
  Serial.print("Raw Moisture Value: ");
  Serial.println(humedad);
  delay(1000);
}
            

2. Percentage of Moisture

Convert the sensor's raw readings into a percentage:


const int sensorPin = A0;
const int humedadAire = 550;  // Dry air reading
const int humedadAgua = 250;  // Water reading

void setup() {
  Serial.begin(9600);
}

void loop() {
  int humedad = analogRead(sensorPin);
  int porcentajeHumedad = map(humedad, humedadAire, humedadAgua, 0, 100);
  porcentajeHumedad = constrain(porcentajeHumedad, 0, 100);

  Serial.print("Moisture: ");
  Serial.print(porcentajeHumedad);
  Serial.println("%");
  delay(1000);
}