Interfacing Capacitive Soil Moisture Sensor with Arduino

Keeping a houseplant alive can be a tough job, right? And often, it’s just about remembering to water it. Fortunately, soil moisture sensors can help us remember to water our plants and help them live longer.

However, the majority of inexpensive soil moisture sensors are resistive style, where there’s two prongs and the sensor measures the water content in the soil based on the conductivity between them. They work fine initially, but over time, they start to rust, even if they’re gold-plated! This rusting messes with the readings, so you have to keep adjusting your code to get it right. Also, they don’t work that well in loose soil.

Luckily, there’s a better option: Capacitive Soil Moisture Sensors. These sensors operate based on capacitive measurement, which offers significant advantages over resistive measurement. These sensors have only one probe, no exposed metal to rust, and don’t harm your plants by introducing electricity into the soil.

In this tutorial, you will learn how to effectively use capacitive soil moisture sensors with Arduino. By the end of this tutorial, you’ll have the knowledge and skills to keep your plants thriving, without having to worry about under or overwatering. Let’s get started!

Hardware Overview

Capacitive Soil Moisture Sensors are quite amazing. Just stick them into the ground and they output an analog signal that is proportional to how wet the soil is.

These sensors make use of a 555 timer IC and operate by measuring how quickly (or slowly) a capacitor charges through a resistor, but in these sensors the capacitor is not a literal component, but is formed by two PCB traces that are near one another. Their capacitance, and therefore their charging rate, changes in response to how much water is around them.

capacitive soil moisture sensor hardware overview

The sensor includes an on-board 3.3V voltage regulator, making it suitable for 3.3V and 5V MCUs. Plus, it consumes less than 5mA of current.

Note that this sensor can only provide a qualitative measurement of soil moisture. As the soil gets wetter, the output value decreases, and as it gets drier, the output value increases. When powered at 5V, the output ranges from about 1.5V (for wet soil) to 3V (for dry soil).

capacitive soil moisture sensor output animation

However, the final output value is affected by probe insertion depth and how tight the soil packed around it is.

Technical Specifications

Here are the specifications:

Operating Voltage3.3 to 5.5V
Operating Current< 5mA
Output Voltage at 5V1.5V to 3V (approx.)
Sensor Probe L x W (PCB)98 x 23mm (3.86 x 0.91″)
Cable Length20cm (8″)

How Does a Capacitive Soil Moisture Sensor Work?

To understand how a capacitive soil moisture sensor works, you need to first understand the behavior of the capacitor in an RC circuit.

simple rc circuit

In a simple RC circuit like this, when a positive voltage is applied to the Input, the capacitor (C) begins to charge through the resistor (R). As it does, the voltage across the capacitor changes. Over time, the capacitor voltage rises to equal input voltage. Here, you can see a graph plotting voltage against time for the charging capacitor.

capacitor charging curve

The time it takes for the capacitor to fully charge depends on the values of the resistor and the capacitor. If you keep the R constant and try two different capacitance values for C, you will observe that a capacitor with a larger capacitance requires more time to charge,

large value capacitor charging curve

whereas a capacitor with a smaller capacitance requires less time to charge.

small value capacitor charging curve

Now coming back to our sensor, the capacitor C on the sensor board is not a literal component, but simply two copper traces that act like a capacitor. This effect, known as Parasitic Capacitance, happens often in circuits and is usually negligible. However, by deliberately making the two copper traces larger, we can use this effect to our advantage.

The capacitance of this parasitic capacitor is determined by the shape of the traces and the environment surrounding it (technically known as the dielectric constant). As the sensor is inserted into the soil, the environment around the capacitor changes depending on whether the soil becomes wetter or drier. This alters its capacitance, and consequently, affects its charging time.

When the soil is dry, the capacitor has a smaller capacitance and therefore charges up quickly. Conversely, when the soil is wet, the capacitor has a larger capacitance and therefore charges up more slowly.

To better understand how this is implemented in the sensor, let’s examine the circuit diagram.

capacitive soil moisture sensor schematic

The sensor uses a 555 configured as an astable oscillator. The square waves generated by the 555 are fed into the RC integrator, of which the capacitor is formed by the soil probe. The signal from the integrator is more of a triangular wave, which is fed into the rectifier and a smoothing capacitor to produce a DC output.

This output is proportional to the moisture content of the soil. So if the soil is dry, the capacitor charges quickly, resulting in a greater amplitude of the triangular wave and subsequently producing a higher output voltage. Conversely, when the soil is wet, the capacitor charges more slowly, resulting in a smaller amplitude of the triangular wave, which in turn generates a lower output voltage.

Capacitive Soil Moisture Sensor Pinout

The capacitive soil moisture sensor features a 3-pin JST PH2.0 type connector. One end of the provided cable plugs into this connector, while the other end is a standard Dupont style 3-pin female connector. The cable is color-coded so you can easily identify which wire is which: black represents ground, red represents VCC, and yellow represents AOUT.

capacitive soil moisture sensor pinout

VCC is the power supply pin. It is recommended that the sensor be powered from 3.3V to 5V. Please keep in mind that the analog output will vary depending on the voltage supplied to the sensor.

GND is the ground pin.

AOUT pin gives an analog voltage output that is proportional to the amount of moisture in the soil. The output can be read using an analog input on your microcontroller. As the moisture level increases, the output voltage decreases and vice versa.

Usage Instructions

When using the sensor, keep in mind the following:

  • It‘s recommended that the probe should not be placed on the depth which crosses the limit line on the sensor.
  • The components on this board are NOT waterproof, so make sure they don’t come in contact with water or splashes. For additional protection, consider using a piece of wide heat shrink tubing around the upper section of the board.
  • Note that the edges of the PCB could absorb moisture over time, shortening the lifespan of the sensor. To increase its durability, consider applying a protective coating, such as clear epoxy, which won’t affect the sensor’s performance.

Wiring a Capacitive Soil Moisture Sensor to an Arduino

Connecting a capacitive soil moisture sensor to an arduino is a breeze. You only need to connect three wires.

Start by connecting the sensor’s red wire (VCC) to the power supply, 3.3V-5V is fine. Use the same voltage that your microcontroller logic is based off of. For most Arduinos, that is 5V. For 3.3V logic devices, use 3.3V. Now connect the black wire (GND) to ground.

Finally, connect the yellow wire (AOUT) to one of the analog input pins on your Arduino. In our case, it is connected to the A0 pin.

The following table lists the pin connections:

Soil Moisture SensorArduino

The wiring is shown in the image below.

wiring capacitive soil moisture sensor to arduino

Finding the Threshold Values

It is not possible to determine the actual percentage of moisture in the soil directly from the measurements taken. However, it is relatively easy to define basic ranges for what is considered “too dry,” “too wet,” and “just right.”

Simply run the sketch below and record your sensor output under three basic conditions:

  • When the soil is dry enough that the plant needs watering.
  • When the soil has been watered to its ideal moisture level for the plant.
  • When the soil has been heavily watered and is too wet, which is not ideal for the plant.
// Define analog input
#define sensorPin A0

void setup() {
  // Setup Serial Monitor

void loop() {
  // Read the Analog Input
  int value = analogRead(sensorPin);
  // Print the value to the serial monitor
  Serial.print("Analog output: ");
  // Wait for 1 second before the next reading

Upon running the sketch, you should expect readings similar to the ones listed below:

  • In open air: approximately 590
  • Dry soil that needs watering: approximately 380
  • Ideal soil moisture: between 277 and 380
  • Soil that has just been watered: approximately 277
  • In cup of water: approximately 273

This test may require some trial and error. Once you have the readings, you can use them as a threshold to trigger an action.

Arduino Example Code

The sketch below estimates the level of soil moisture using the following threshold values:

  • < 277 is too wet
  • 277 – 380 is the target range
  • > 380 is too dry
/* Change these values based on your observations */
#define wetSoil 277   // Define max value we consider soil 'wet'
#define drySoil 380   // Define min value we consider soil 'dry'

// Define analog input
#define sensorPin A0

void setup() {  

void loop() {
  // Read the Analog Input and print it
  int moisture = analogRead(sensorPin);
  Serial.print("Analog output: ");
  // Determine status of our soil
  if (moisture < wetSoil) {
    Serial.println("Status: Soil is too wet");
  } else if (moisture >= wetSoil && moisture < drySoil) {
    Serial.println("Status: Soil moisture is perfect");
  } else {
    Serial.println("Status: Soil is too dry - time to water!");
  // Take a reading every second

If everything is fine, you should see similar output on the serial monitor.

capacitive soil moisture sensor output