Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
BETTESWORTHConstruction
Arduino

Interfacing a Soil Moisture Sensor with Arduino: Wiring, Code, and Calibration

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To interface a soil-moisture sensor with an Arduino Uno, connect the sensor’s power and ground, connect its analog output to A0, upload a sketch using analogRead(), and calibrate the readings in the soil where the sensor will be used. The Arduino Uno normally returns a 10-bit value from 0 to 1023, but that raw value is not automatically a universal moisture percentage.

For a short demonstration, an inexpensive FC-28-style resistive sensor is adequate. For a sensor that will remain installed in a plant pot, an analog capacitive sensor is generally the better choice because it avoids the exposed-electrode corrosion mechanism of basic resistive probes.

As an Amazon Associate I earn from qualifying purchases.

Choose the right type of soil sensor

Most Arduino projects use one of two sensor types. They may look similar in online listings, but their limitations are different.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

FC-28 or YL-69 resistive sensor

A resistive probe has two exposed metal electrodes. Soil conductivity changes as its water content changes. Common modules include VCC, GND, AO or AOUT, and DO or DOUT. The analog output varies with the measured condition, while the digital output comes from an adjustable comparator.

#1 Best Overall
HiLetgo 5pcs LM393 3.3V-5V Soil Moisture Detect Sensor Soil Moisture Sensor Soil Hygrometer Detection for Arduino Automatic Watering System Robot Smart car
  • This is a simple moisture sensor can be used to detect soil moisture, when the soil water shortage, the module outputs a high level, whereas the output low.
  • Use this sensor to make an automatic watering device that will keep your garden of plants unmanaged.
  • Module dual output mode, digital output is simple, more accurate analog output.
  • Sensitivity adjustable (Figure blue digital potentiometer adjustment)
  • Comparator using LM393 chip, stable job

These modules are cheap and simple, but continuously powering an exposed resistive probe can accelerate electrochemical corrosion. They are best suited to experiments, demonstrations, or short-term measurements.

Capacitive analog sensor

A capacitive sensor detects changes in capacitance near its sensing area rather than relying on exposed conductive electrodes. It normally has three connections: power, ground, and analog output. It avoids the basic exposed-electrode corrosion mechanism, although its coating, electronics, wiring, and calibration can still fail or drift.

For example, Arduino’s Gravity analog capacitive sensor is specified for 3.3–5.5 V operation and compatibility with 3.3 V and 5 V logic; the official listing’s availability can change, so check the product page before purchasing: Arduino Gravity capacitive sensor.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Requirement Better choice
Lowest-cost classroom experiment Resistive FC-28-style module
Repeated plant monitoring Capacitive analog sensor
Validated agricultural measurement A documented, calibrated soil-moisture instrument

Parts required

  • Arduino Uno Rev3 or compatible Uno board
  • Soil-moisture sensor
  • USB cable and Arduino IDE
  • Jumper wires and, optionally, a breadboard
  • The actual soil and pot in which the sensor will operate
  • Optional: LED with a 220–330 Ω resistor, buzzer, relay module, MOSFET driver, or display

The classic Uno Rev3 has six analog inputs, and its default analog reference is 5 V. Its official documentation describes the analog inputs as 10-bit, producing readings from approximately 0 to 1023: Arduino Uno Rev3 documentation.

Wire the sensor for analog readings

Use analog mode when you want a changing reading that can be logged, displayed, or converted into a project-specific moisture estimate.

Rank #2
MTDELE 10Pcs 3.3V Capacitive Soil Moisture Sensor Module
  • Capacitive Soil Moisture Sensor: Compatible with for Arduino Raspberry Pi
  • Size:98*23mm
  • Operating Voltage:3.3V DC;Output Voltage:0-3.0V DC
  • Interface Type:PH2.54 3Pin
  • Commodities include:10Pcs Soil Moisture Sensor;10Pcs connecting wire
Sensor connection Arduino Uno Purpose
VCC 5V, or the sensor’s specified supply Power
GND GND Common reference
AO or AOUT A0 Variable analog signal
DO or DOUT Leave disconnected Not needed for analog mode

Do not assume that every board marked “Arduino-compatible” has the same voltage limits. A 5 V analog output must not be connected directly to a 3.3 V-only analog input unless the circuit is designed to reduce the voltage.

Upload a raw-reading test first

Start with raw data. This separates wiring and sensor faults from later calibration problems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const byte SENSOR_PIN = A0;

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

void loop() {
  int rawValue = analogRead(SENSOR_PIN);

  Serial.print("Raw soil sensor value: ");
  Serial.println(rawValue);

  delay(500);
}
  1. Connect VCC, GND, and AO.
  2. Insert the probe into soil at a repeatable depth.
  3. Verify that the selected board and port are correct in the Arduino IDE.
  4. Upload the sketch.
  5. Open Tools → Serial Monitor and select 9600 baud.
  6. Record the reading in dry soil, then add water gradually and allow the reading to settle.

A working Uno setup should produce values roughly between 0 and 1023. The value should change between dry and damp conditions, although some fluctuation is normal. The direction is not universal: depending on the sensor and module circuit, wet soil may produce either a higher or lower number. Test it rather than assuming. A comparable analogRead() example is shown in Arduino Project Hub’s soil-moisture project.

Calibrate the reading for your soil

A raw ADC number is an electrical reading, not automatically a scientific volumetric water-content percentage. It changes with soil composition, salinity, fertilizer, temperature, probe depth, compaction, sensor orientation, supply voltage, and placement.

Practical plant-monitoring calibration

  1. Place the sensor in the actual soil at its intended depth and position.
  2. Record several readings when the soil is dry enough that the plant needs watering. This is your practical dry reference.
  3. Water thoroughly, allow excess water to drain, and record readings again. This is your practical wet reference.
  4. Average the readings from each condition.
  5. Use those measured values as DRY_VALUE and WET_VALUE.
  6. Test an intermediate condition and adjust the watering threshold for the plant.

“Wet” should usually mean the desired post-watering condition after drainage, not a probe submerged in a glass of water. Plain-water calibration does not reproduce the electrical properties of soil.

Calibrated Arduino sketch

const byte SENSOR_PIN = A0;

// Replace these with measurements from your own soil and sensor.
const int DRY_VALUE = 780;
const int WET_VALUE = 360;
const byte SAMPLE_COUNT = 10;

int readAverage() {
  long total = 0;

  for (byte i = 0; i < SAMPLE_COUNT; i++) {
    total += analogRead(SENSOR_PIN);
    delay(10);
  }

  return total / SAMPLE_COUNT;
}

int moisturePercent(int rawValue) {
  int result = map(rawValue, DRY_VALUE, WET_VALUE, 0, 100);
  return constrain(result, 0, 100);
}

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

void loop() {
  int rawValue = readAverage();
  int percentage = moisturePercent(rawValue);

  Serial.print("Raw: ");
  Serial.print(rawValue);
  Serial.print("  Relative moisture estimate: ");
  Serial.print(percentage);
  Serial.println("%");

  delay(1000);
}

If dry soil produces a lower value than wet soil, enter the measured values in that order. The map() function does not know what “dry” or “wet” means; its endpoints must come from your measurements. The percentage should therefore be labelled a relative moisture estimate, not a laboratory-grade volumetric percentage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For more serious measurement, use a sensor with a documented calibration model and validate it against the relevant soil type, bulk density, temperature, and reference method.

Use the digital threshold output

Common FC-28-style modules also provide a digital output. The onboard potentiometer sets the comparator threshold. Digital mode is useful when the project only needs a yes/no decision, such as switching an indicator or triggering an alert.

Sensor connection Arduino Uno
VCC 5V or specified supply
GND GND
DO or DOUT D2, for example
AO Optional
const byte DIGITAL_SENSOR_PIN = 2;
const byte LED_PIN = LED_BUILTIN;

void setup() {
  pinMode(DIGITAL_SENSOR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int state = digitalRead(DIGITAL_SENSOR_PIN);

  Serial.print("Digital state: ");
  Serial.println(state);

  // Verify polarity with the actual module.
  bool soilIsDry = (state == HIGH);
  digitalWrite(LED_PIN, soilIsDry ? HIGH : LOW);

  delay(500);
}

Do not assume that HIGH always means dry. Turn the potentiometer slowly while testing known dry and damp soil, observe the module’s indicator LED, and confirm the logic in the Serial Monitor. Digital mode cannot provide a continuous moisture estimate.

Reduce noise and sensor wear

Averaging several readings can make the displayed value steadier and reduce random noise. It does not correct poor calibration, bad placement, sensor drift, or a faulty connection. A short settling delay after powering a sensor can also help.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Stemedu 5PCS Capacitive Analog Soil Moisture Sensor Module 3.3~5.5V Corrosion Resistant Humidity Detection Sensors DIY Electronic for Arduino for Raspberry Pi
  • 【Version】This capacitive analog soil moisture sensor is V1.2
  • 【Voltage】Working voltage: 3.3~5.5 VDC, output voltage: 0~3.0 VDC
  • 【Interface】Interface: PH2.54-3P, Pin: Analog signal output, GND, VCC
  • 【Feature】Capacitive humidity sensor has good linearity, good repeatability, small hysteresis, fast response, small size, and can be used at - 10 ℃ - 60 ℃ humidity environment
  • 【Comparision】This capacitive soil humidity sensor is different from most of the resistive sensors. It uses the capacitive sensing principle to detect soil humidity, avoiding the problem that the resistive sensor is easily corroded, and greatly extending its working life.

For a resistive probe that will remain installed, avoid leaving it energized unnecessarily. A typical switched-power arrangement is:

Arduino digital pin → transistor or MOSFET control
External supply → sensor VCC through the switched power path
Arduino GND ↔ external supply GND
Sensor AO → Arduino A0

Power the sensor briefly, wait for the output to settle, take several samples, and switch it off. Choose the transistor or MOSFET for the sensor’s actual current and supply voltage; do not use an Arduino GPIO pin as a pump power source.

Extend the project to automatic watering

A pump requires a separate load-driving circuit. Use a relay module or suitably rated MOSFET driver, a separate pump supply, and appropriate protection. A bare DC motor controlled by a transistor or MOSFET requires a flyback diode. Keep pump wiring away from sensor wiring and provide an enclosure appropriate to the voltage and environment.

const int START_WATERING_AT = 25;
const int STOP_WATERING_AT  = 45;
const byte PUMP_CONTROL_PIN = 7;

bool pumpOn = false;

void updatePump(int moisture) {
  if (!pumpOn && moisture <= START_WATERING_AT) {
    pumpOn = true;
  }

  if (pumpOn && moisture >= STOP_WATERING_AT) {
    pumpOn = false;
  }

  digitalWrite(PUMP_CONTROL_PIN, pumpOn ? HIGH : LOW);
}

The two thresholds provide hysteresis, preventing rapid on/off switching near one boundary. A practical irrigation controller should also include a maximum pump runtime, cooldown interval, manual override, and low-water cutoff. Never connect a pump directly to an Arduino output pin.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

The reading is always 0

  • Check VCC, GND, and the analog signal wire.
  • Confirm that the sketch reads the same analog pin used in the wiring.
  • Inspect for a short from AO to ground.
  • Measure the sensor supply and output with a multimeter.
  • Test another analog input or a known variable voltage source.

The reading is always 1023

  • Check whether AO is disconnected or floating.
  • Verify the sensor output is within the Arduino’s analog-input voltage range.
  • Confirm that the board is not a 3.3 V-only model receiving a 5 V signal.

The reading changes in the opposite direction

This is usually a polarity difference, not necessarily a fault. Measure known dry and wet conditions, then reverse the calibration endpoints if necessary.

Best Value
AITRIP 10 Pack Capacitive Soil Moisture Sensor Corrosion Resistant for Arduino Moisture Detection Garden Watering DIY Electronic for Arduino and Raspberry Pi (10PCS)
  • This capacitive soil moisture sensor is distinguished from most resistive sensors on the market and uses capacitive sensing to detect soil moisture. The problem that the resistance sensor is easily corroded is avoided, and its working life is greatly extended.
  • The sensor has a built-in voltage regulator chip that supports a 3.3-5.5V working environment, which means it works even on a 3.3-5.5V Arduino control board. A miniature PC such as the Raspberry Pi only needs an external ADC (analog to digital signal) conversion module to work.
  • With an external screen and a motherboard, you can talk to your plants! See if it is thirsty and you don't need more water to moisten.Garden plants, Moisture detection, Intelligent agriculture
  • Interface: PH2.54-3P, Size: 98 x 23mm (LxW)
  • Package Includes: 10pcs Capacitive Soil Moisture Sensor

The readings fluctuate heavily

Use shorter wires, improve breadboard connections, average samples, add a settling delay, and keep sensor wiring away from motors, relays, pumps, and switching regulators. Insert the probe at a consistent depth and avoid testing in a single unusually wet pocket of soil.

The sensor works in air but not in soil

Insert it deeper and consistently, ensure the soil is in contact with the sensing area, and test in known damp soil. Very loose, dry, or unevenly compacted soil can prevent repeatable contact.

The digital output never changes

Adjust the module’s potentiometer slowly, verify the selected digital pin, test both dry and wet conditions, and confirm whether the module uses the opposite output polarity. Check the analog output separately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The sensor corrodes

This is principally a resistive-probe problem. Reduce powered-on time, replace the damaged probe, or use a capacitive sensor. Capacitive construction reduces the exposed-electrode corrosion mechanism but does not make the sensor immune to water ingress, physical damage, or drift.

An LCD example will not compile

An LCD is optional and should be added only after the Serial Monitor test works. Compilation problems commonly result from a missing LiquidCrystal_I2C library or an incorrect display address. On the Uno Rev3, I2C uses A4/SDA and A5/SCL; see the official Uno documentation.

Placement and maintenance

Readings can vary substantially with probe depth, distance from the stem, pot size, soil texture, fertilizer, compaction, and sensor contact. Mark the intended insertion depth and position. Recalibrate after changing the soil, pot, sensor, supply voltage, or installation location.

Use a resistive module for a quick experiment, a capacitive sensor for a longer-term hobby plant monitor, and a documented calibrated instrument when the measurement must be defensible. No inexpensive Arduino module should be treated as an accurate moisture percentage without soil-specific validation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
HiLetgo 5pcs LM393 3.3V-5V Soil Moisture Detect Sensor Soil Moisture Sensor Soil Hygrometer Detection for Arduino Automatic Watering System Robot Smart car
HiLetgo 5pcs LM393 3.3V-5V Soil Moisture Detect Sensor Soil Moisture Sensor Soil Hygrometer Detection for Arduino Automatic Watering System Robot Smart car
Module dual output mode, digital output is simple, more accurate analog output.; Sensitivity adjustable (Figure blue digital potentiometer adjustment)
$7.89
Bestseller No. 2
MTDELE 10Pcs 3.3V Capacitive Soil Moisture Sensor Module
MTDELE 10Pcs 3.3V Capacitive Soil Moisture Sensor Module
Capacitive Soil Moisture Sensor: Compatible with for Arduino Raspberry Pi; Size:98*23mm
$12.99
Bestseller No. 4
Stemedu 5PCS Capacitive Analog Soil Moisture Sensor Module 3.3~5.5V Corrosion Resistant Humidity Detection Sensors DIY Electronic for Arduino for Raspberry Pi
Stemedu 5PCS Capacitive Analog Soil Moisture Sensor Module 3.3~5.5V Corrosion Resistant Humidity Detection Sensors DIY Electronic for Arduino for Raspberry Pi
【Version】This capacitive analog soil moisture sensor is V1.2; 【Voltage】Working voltage: 3.3~5.5 VDC, output voltage: 0~3.0 VDC
$8.98
Bestseller No. 5

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.