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.
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
- 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.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →| 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
- 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.
Recommended Free Tools
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);
}
- Connect
VCC,GND, andAO. - Insert the probe into soil at a repeatable depth.
- Verify that the selected board and port are correct in the Arduino IDE.
- Upload the sketch.
- Open Tools → Serial Monitor and select 9600 baud.
- 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
- Place the sensor in the actual soil at its intended depth and position.
- Record several readings when the soil is dry enough that the plant needs watering. This is your practical dry reference.
- Water thoroughly, allow excess water to drain, and record readings again. This is your practical wet reference.
- Average the readings from each condition.
- Use those measured values as
DRY_VALUEandWET_VALUE. - 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.
Rank #3
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.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →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.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #4
- 【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.
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
AOto 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
AOis 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
- 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.
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.
Quick Recap
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.

