Contact Sales & After-Sales Service

Contact & Quotation

  • Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
  • Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

Notes:
For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.

Soil Moisture Sensor Arduino: Complete Guide to Garden Monitoring

Keeping plants properly watered has always been more art than science for most gardeners. After integrating dozens of soil monitoring systems into automated greenhouse projects, I can tell you that a Soil Moisture Sensor Arduino setup transforms guesswork into precise data-driven irrigation.

These sensors measure the volumetric water content in soil and output signals that any microcontroller can interpret. Whether you’re protecting a single houseplant from neglect or managing an entire vegetable garden, understanding how to properly interface and calibrate these sensors makes the difference between thriving plants and disappointment.

This guide covers everything from basic sensor theory to building a complete automatic watering system. By the end, you’ll have the knowledge to select the right sensor for your application and implement reliable garden monitoring with Arduino.

How Soil Moisture Sensors Work

Soil moisture sensors exploit the relationship between water content and electrical properties of soil. Two primary measurement methods exist: resistive and capacitive. Understanding both helps you choose the right sensor for your project.

Resistive Soil Moisture Sensors

Resistive sensors use two exposed metal probes that function as electrodes. When inserted into soil, they measure electrical resistance between the probes. Water conducts electricity, so wet soil has low resistance while dry soil has high resistance.

The sensor module includes an LM393 comparator chip that processes the raw resistance measurement and outputs both analog and digital signals. The analog output provides continuous voltage proportional to moisture level, while the digital output triggers HIGH or LOW based on a threshold set by the onboard potentiometer.

The problem with resistive sensors is electrolysis. Current flowing between the probes causes the metal to corrode over time, especially when the sensor remains powered continuously. Most resistive sensors degrade noticeably within 6-12 months of regular use.

Capacitive Soil Moisture Sensors

Capacitive sensors measure the dielectric constant of surrounding soil rather than its conductivity. The sensor PCB has copper traces that form a capacitor, with soil acting as the dielectric material between them. Since water has a much higher dielectric constant than dry soil (~80 vs 2-6), moisture significantly affects capacitance.

A 555 timer circuit on the sensor board generates a square wave and measures how quickly a capacitor charges. Higher soil moisture means higher capacitance, which produces lower output voltage. The electronics remain sealed, with no exposed metal contacting the soil directly.

This design eliminates corrosion issues and typically lasts 2-5 years. The tradeoff is slightly higher cost and sensitivity to factors beyond moisture, including soil density, temperature, and nearby electromagnetic interference.

Resistive vs Capacitive Sensor Comparison

FeatureResistive SensorCapacitive Sensor
Price$2-5$5-15
Lifespan6-12 months2-5 years
Accuracy±5-10%±3-5%
CorrosionSignificant issueMinimal
Output TypeAnalog + DigitalAnalog only
Response TimeInstantInstant
Temperature SensitivityModerateLow
Salinity SensitivityHighLow
Power ConsumptionHigherLower
Best ForShort-term projects, learningLong-term installations

For hobby projects and learning, resistive sensors work fine. For any installation you expect to run more than a few months, invest in capacitive sensors.

Soil Moisture Sensor Arduino Specifications

Here are typical specifications for common sensor models:

Resistive Sensor (YL-69/FC-28) Specifications

ParameterValue
Operating Voltage3.3V – 5V DC
Operating Current~35 mA
Output Voltage0V – 4.2V (analog)
Digital OutputHIGH/LOW (adjustable threshold)
PCB Dimensions30mm x 16mm
Probe Dimensions60mm x 20mm
Detection DepthUp to 38mm
Interface4-pin (VCC, GND, AO, DO)

Capacitive Sensor (v1.2/v2.0) Specifications

ParameterValue
Operating Voltage3.3V – 5.5V DC
Operating Current~5 mA
Output Voltage1.2V – 3.0V (analog)
Output TypeAnalog only
PCB Dimensions98mm x 23mm
Insertion DepthUp to 70mm
Interface3-pin (VCC, GND, AOUT)
Onboard Regulator3.3V LDO

Note that some cheap capacitive sensors replace the voltage regulator with a resistor, causing output to vary with supply voltage. Check your sensor board before assuming stable operation.

Soil Moisture Sensor Arduino Wiring

Both sensor types connect easily to Arduino, though pin configurations differ slightly.

Resistive Sensor Wiring

Sensor PinArduino PinFunction
VCC5V or D7*Power supply
GNDGNDGround
AOA0Analog output
DOD8Digital output (optional)

*Powering through a digital pin allows you to turn the sensor on only when taking readings, significantly extending lifespan.

Capacitive Sensor Wiring

Sensor PinArduino PinFunction
VCC3.3V or 5VPower supply
GNDGNDGround
AOUTA0Analog output

For capacitive sensors, 3.3V power provides better ADC resolution since the output range (1.2V-3.0V) stays within the reference voltage.

Basic Soil Moisture Sensor Arduino Code

Here’s tested code for reading analog soil moisture values:

// Soil Moisture Sensor Arduino – Basic Reading

// Outputs moisture level to Serial Monitor

const int sensorPin = A0;

int moistureValue = 0;

void setup() {

  Serial.begin(9600);

  Serial.println(“Soil Moisture Sensor Arduino Ready”);

}

void loop() {

  // Read analog value from sensor

  moistureValue = analogRead(sensorPin);

  // Print raw value

  Serial.print(“Moisture Level: “);

  Serial.println(moistureValue);

  delay(1000);

}

Upload this code, open Serial Monitor at 9600 baud, and observe how readings change when you insert the sensor into dry versus wet soil.

Calibrating Your Soil Moisture Sensor

Raw analog values (0-1023) mean nothing without calibration. You need to determine what values correspond to “dry” and “wet” for your specific sensor and soil type.

Calibration Procedure

  1. Measure Dry Value: Hold the sensor in open air (completely dry). Record the reading.
  2. Measure Wet Value: Submerge the sensor in a glass of water (just the probe area for capacitive sensors). Record the reading.
  3. Calculate Range: Note minimum and maximum values for mapping.

For resistive sensors, dry readings are typically HIGH (800-1023) and wet readings are LOW (200-400). Capacitive sensors work inversely—dry produces higher values (~600) and wet produces lower values (~300).

Code with Calibration

// Soil Moisture Sensor Arduino – Calibrated Percentage

// Converts raw reading to moisture percentage

const int sensorPin = A0;

// Calibration values (adjust for your sensor)

const int dryValue = 620;   // Value in air

const int wetValue = 310;   // Value in water

void setup() {

  Serial.begin(9600);

  Serial.println(“Calibrated Soil Moisture Sensor”);

}

void loop() {

  int rawValue = analogRead(sensorPin);

  // Map to percentage (inverted for capacitive sensor)

  int moisturePercent = map(rawValue, dryValue, wetValue, 0, 100);

  moisturePercent = constrain(moisturePercent, 0, 100);

  Serial.print(“Raw: “);

  Serial.print(rawValue);

  Serial.print(” | Moisture: “);

  Serial.print(moisturePercent);

  Serial.println(“%”);

  delay(1000);

}

Multi-Level Moisture Indicator

This project uses three LEDs to display soil moisture status at a glance:

// Soil Moisture Sensor Arduino – LED Indicator

// Green = Wet, Yellow = Moderate, Red = Dry

const int sensorPin = A0;

const int greenLED = 2;

const int yellowLED = 3;

const int redLED = 4;

// Thresholds (adjust after calibration)

const int dryThreshold = 70;    // Below this = DRY

const int wetThreshold = 40;    // Above this = WET

// Calibration values

const int dryValue = 620;

const int wetValue = 310;

void setup() {

  Serial.begin(9600);

  pinMode(greenLED, OUTPUT);

  pinMode(yellowLED, OUTPUT);

  pinMode(redLED, OUTPUT);

}

void loop() {

  int rawValue = analogRead(sensorPin);

  int moisturePercent = map(rawValue, dryValue, wetValue, 0, 100);

  moisturePercent = constrain(moisturePercent, 0, 100);

  // Turn off all LEDs

  digitalWrite(greenLED, LOW);

  digitalWrite(yellowLED, LOW);

  digitalWrite(redLED, LOW);

  // Activate appropriate LED

  if (moisturePercent >= wetThreshold) {

    digitalWrite(greenLED, HIGH);

    Serial.println(“Status: WET – No watering needed”);

  }

  else if (moisturePercent >= dryThreshold) {

    digitalWrite(yellowLED, HIGH);

    Serial.println(“Status: MODERATE – Monitor closely”);

  }

  else {

    digitalWrite(redLED, HIGH);

    Serial.println(“Status: DRY – Water needed!”);

  }

  delay(2000);

}

Automatic Plant Watering System

Here’s a complete automatic watering system using a relay and water pump:

// Soil Moisture Sensor Arduino – Automatic Watering System

// Activates pump when soil moisture drops below threshold

const int sensorPin = A0;

const int relayPin = 7;

const int statusLED = 13;

// Calibration values (adjust for your sensor)

const int dryValue = 620;

const int wetValue = 310;

// Watering thresholds

const int wateringThreshold = 30;  // Start watering below 30%

const int stopThreshold = 60;       // Stop watering above 60%

// Timing

const unsigned long wateringDuration = 5000;  // 5 seconds per cycle

const unsigned long checkInterval = 60000;    // Check every minute

unsigned long lastCheck = 0;

bool isWatering = false;

void setup() {

  Serial.begin(9600);

  pinMode(relayPin, OUTPUT);

  pinMode(statusLED, OUTPUT);

  digitalWrite(relayPin, LOW);  // Pump OFF initially

  Serial.println(“Automatic Watering System Ready”);

}

void loop() {

  unsigned long currentTime = millis();

  // Check moisture at intervals

  if (currentTime – lastCheck >= checkInterval || lastCheck == 0) {

    lastCheck = currentTime;

    int rawValue = analogRead(sensorPin);

    int moisturePercent = map(rawValue, dryValue, wetValue, 0, 100);

    moisturePercent = constrain(moisturePercent, 0, 100);

    Serial.print(“Moisture: “);

    Serial.print(moisturePercent);

    Serial.println(“%”);

    // Decide whether to water

    if (moisturePercent < wateringThreshold) {

      waterPlant();

    }

  }

}

void waterPlant() {

  Serial.println(“Starting watering cycle…”);

  digitalWrite(relayPin, HIGH);

  digitalWrite(statusLED, HIGH);

  delay(wateringDuration);

  digitalWrite(relayPin, LOW);

  digitalWrite(statusLED, LOW);

  Serial.println(“Watering complete.”);

  // Wait before next check to let water absorb

  delay(30000);

}

Components for Automatic Watering

ComponentPurposeNotes
Arduino Uno/NanoMain controllerAny Arduino works
Capacitive Soil SensorMoisture detectionRecommended for longevity
5V Relay ModulePump controlUse optocoupler-isolated type
5V Submersible PumpWater delivery100-300 L/hr flow rate
Silicone TubingWater routing6mm inner diameter
9V Power SupplySystem powerOr USB power bank
Water ReservoirWater sourceAny container works

Extending Resistive Sensor Lifespan

If you’re using resistive sensors, these techniques significantly extend their usable life:

Power Control Method

Instead of keeping the sensor constantly powered, supply voltage only during readings:

// Soil Moisture Sensor Arduino – Power Control

// Powers sensor only when reading to reduce corrosion

const int sensorPin = A0;

const int sensorPower = 7;  // Control sensor power

void setup() {

  Serial.begin(9600);

  pinMode(sensorPower, OUTPUT);

  digitalWrite(sensorPower, LOW);  // Start with sensor OFF

}

void loop() {

  // Power ON sensor

  digitalWrite(sensorPower, HIGH);

  delay(100);  // Allow sensor to stabilize

  // Take reading

  int moistureValue = analogRead(sensorPin);

  // Power OFF sensor immediately

  digitalWrite(sensorPower, LOW);

  Serial.print(“Moisture: “);

  Serial.println(moistureValue);

  delay(60000);  // Wait 1 minute before next reading

}

This approach can extend resistive sensor life from months to years by minimizing electrolysis exposure.

Optimal Sensor Placement for Gardens

Proper placement dramatically affects reading accuracy and usefulness:

Plant TypeRecommended DepthPlacement Notes
Houseplants2-3 inchesCenter of pot, mid-root zone
Vegetables4-6 inchesBetween plants, not at edge
Lawn/Turf3-4 inchesMultiple sensors for coverage
Trees/Shrubs6-12 inchesNear drip line, not trunk
Raised Beds4-6 inchesCenter of bed, away from edges

Avoid placing sensors near irrigation drip points, in compacted soil, or where water pools. These locations give misleading readings that don’t represent the overall root zone moisture.

Troubleshooting Common Problems

Readings stuck at maximum or minimum: Check wiring connections. Verify sensor isn’t damaged. For capacitive sensors, ensure the probe portion (below warning line) is inserted into soil, not the electronics portion.

Erratic or jumping readings: Add a small delay after powering the sensor before reading. Average multiple readings:

int getAverageMoisture(int samples) {

  long total = 0;

  for (int i = 0; i < samples; i++) {

    total += analogRead(sensorPin);

    delay(10);

  }

  return total / samples;

}

Readings drift over time: For resistive sensors, this indicates corrosion. Clean probes with fine sandpaper or replace sensor. For capacitive sensors, recalibrate—temperature and soil composition changes affect baseline readings.

Capacitive sensor not responding to moisture changes: Some cheap sensors have manufacturing defects. Test by measuring output voltage directly—it should change between air and water. If not, the sensor is defective.

Different readings in same soil: Soil moisture varies significantly over small distances. This is normal. Use multiple sensors and average readings for better accuracy.

Useful Resources and Downloads

Datasheets and Documentation

  • FC-28/YL-69 Resistive Sensor Module Datasheet
  • Capacitive Soil Moisture Sensor v1.2 Documentation
  • LM393 Comparator Datasheet (for resistive sensors)
  • NE555 Timer Datasheet (for capacitive sensors)

Arduino Libraries

  • No special library required—sensors use analogRead()
  • LiquidCrystal: For LCD display projects
  • EEPROM: For storing calibration values
  • WiFi/ESP8266: For IoT monitoring projects

Project Resources

  • SparkFun Soil Moisture Sensor Hookup Guide
  • Last Minute Engineers Capacitive Sensor Tutorial
  • Seeed Studio Grove Soil Sensor Documentation

Recommended Sensors

  • DFRobot SEN0193 Capacitive Sensor
  • SparkFun Soil Moisture Sensor (SEN-13322)
  • Grove Capacitive Moisture Sensor (Seeed Studio)

Frequently Asked Questions

How often should I take soil moisture readings?

For most garden applications, reading every 30-60 minutes provides sufficient resolution without excessive data. Houseplants can be checked every few hours since their moisture changes slowly. For automated watering systems, check every 10-30 minutes during active watering periods, then reduce frequency. Taking readings too frequently wastes power and, for resistive sensors, accelerates corrosion.

Can I use multiple soil moisture sensors with one Arduino?

Yes, each sensor connects to a separate analog input pin. Arduino Uno has six analog pins (A0-A5), supporting up to six sensors. For more sensors, use an analog multiplexer (like CD4051) or upgrade to Arduino Mega with 16 analog inputs. When using multiple capacitive sensors, space them at least 6 inches apart to prevent electromagnetic interference between units.

Why do my sensor readings differ between different soil types?

Soil composition dramatically affects readings. Sandy soil drains quickly and has lower baseline capacitance than clay-heavy soil. Organic matter, fertilizer content, and mineral composition also influence electrical properties. Always calibrate your sensor in the actual soil you’ll be monitoring, and recalibrate if you change soil mix or add significant amendments.

Should I choose a resistive or capacitive soil moisture sensor?

For learning projects, classroom demonstrations, or installations lasting less than six months, resistive sensors work fine and cost less. For any long-term garden monitoring, automated watering systems, or outdoor installations, capacitive sensors are worth the extra cost. Their corrosion resistance and longer lifespan provide better value over time, and you won’t need to replace them mid-season.

How do I protect my soil moisture sensor from water damage?

For capacitive sensors, keep everything above the marked waterproof line dry. Apply clear epoxy or use heat-shrink tubing around the upper electronics portion. For resistive sensors, the probe is designed for soil contact, but keep the comparator module dry. In all cases, use weatherproof enclosures for the Arduino and route cables to prevent water ingress. For permanent outdoor installations, consider conformal coating on all exposed PCB areas.

Building a Reliable Garden Monitoring System

The Soil Moisture Sensor Arduino combination provides an accessible entry point into precision gardening. Starting with basic moisture readings and progressing to fully automated watering systems, these sensors enable you to understand exactly what’s happening in your soil rather than relying on guesswork.

Success depends on three factors: choosing the right sensor for your timeframe, proper calibration for your specific soil, and thoughtful placement in the root zone you care about. Get these right, and you’ll have reliable data that helps your plants thrive.

For permanent installations, invest in capacitive sensors despite the higher initial cost. For temporary projects or educational purposes, resistive sensors teach the same concepts at lower investment. Either way, the techniques covered here will help you build monitoring systems that actually work in real-world garden conditions.

Leave a Reply

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

Contact Sales & After-Sales Service

Contact & Quotation

  • Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.

  • Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.

Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

Notes:
For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.