Skip to content
AkerminMeasure. Monitor. Improve. Compare Products
Learning Center

How to Connect a Soil Moisture Sensor to a Raspberry Pi

You have a Raspberry Pi and a soil moisture probe and want real readings, not just wet or dry. The trick is that the Pi cannot read analogue voltages on its own, so you need one small extra chip.

A Raspberry Pi has digital GPIO pins only, with no analogue inputs, so the analogue output of a soil moisture sensor has to go through an analogue to digital converter, typically an ADS1115 on I2C or an MCP3008 on SPI. Power the sensor and the converter from the Pi’s 3.3 V pin so no signal can exceed 3.3 V, wire the sensor’s analogue output to an ADC input, enable I2C or SPI, and read the value with a Python library. Then record a reading in dry air or dry soil and one in water or saturated soil, and scale your readings between those two points.

Pick the sensor and the converter

Two kinds of cheap probe dominate hobby projects.

Part How it works Notes
Resistive fork probe Measures conductivity between two bare metal prongs Prongs corrode quickly with constant power; reading depends on salt content
Capacitive probe Measures how soil changes the capacitance of a coated electrode No exposed metal in soil, lasts much longer; preferred
ADS1115 ADC 16-bit, four inputs, I2C Simple wiring, plenty of resolution, slower sampling which is fine for soil
MCP3008 ADC 10-bit, eight inputs, SPI Cheap, more channels, coarser resolution
Comparator module D0 pin Gives only high or low against a threshold set by a trimmer Works without an ADC but gives wet or dry only

Many capacitive boards accept roughly 3.3 to 5 V. Check yours. The important rule is that a Pi GPIO pin is not 5 V tolerant, and while the ADC isolates the GPIO from the sensor, running everything at 3.3 V keeps every signal safely in range and avoids having to think about level shifting.

Wiring an ADS1115 step by step

Shut the Pi down and unplug it before wiring. Pin numbers below are physical header pins on the 40-pin header.

  1. ADS1115 VDD to Pi pin 1, 3.3 V.
  2. ADS1115 GND to Pi pin 6, ground.
  3. ADS1115 SDA to Pi pin 3, GPIO 2.
  4. ADS1115 SCL to Pi pin 5, GPIO 3.
  5. ADS1115 ADDR to ground, which sets the I2C address to 0x48 on most boards.
  6. Sensor VCC to 3.3 V, for example pin 17, and sensor GND to any ground pin.
  7. Sensor AOUT to ADS1115 input A0.

For a resistive probe, do not leave it powered all the time. Power its VCC from a GPIO pin set high only while you take a reading, then set it low; this slows corrosion dramatically. A GPIO pin can supply only a few milliamps, which is enough for the probe but not for heavier loads.

With an MCP3008 the idea is the same: VDD and VREF to 3.3 V, AGND and DGND to ground, CLK, DOUT, DIN and CS to the Pi’s SPI pins, and the sensor output to channel 0.

Turning on the bus and reading the value

  1. Boot the Pi and open the configuration tool, raspi-config, then enable I2C under the interface options. Reboot if asked.
  2. Install the I2C tools package and run i2cdetect on bus 1. You should see 48 in the address grid. If you see nothing, recheck SDA, SCL, power and ground.
  3. Install a Python library for the converter, such as the Adafruit CircuitPython ADS1x15 package, using pip in a virtual environment.
  4. In a short Python script, create the I2C bus object, create an ADS1115 object on it, create an analogue input on channel 0, and print its voltage and raw value in a loop with a pause of a second or so between readings.
  5. Dip the probe in water and pull it out. The value should change clearly. With most capacitive probes the output voltage is highest in dry air and falls as moisture rises, so wet reads lower than dry. Resistive probes vary by board.

If readings jump around, average ten or twenty samples per reading, keep the sensor cable short or use shielded cable, and keep it away from pump or mains wiring.

Calibrating raw numbers into moisture

The raw value is not a moisture percentage. You need reference points from your own sensor, ideally in your own soil.

  1. Dry point. Record the reading with the probe in dry air, or better, in a container of your soil that has been dried in a warm oven and cooled.
  2. Wet point. Record the reading in the same soil saturated with water, or in a glass of water as a simpler reference.
  3. Scale. Moisture percent = (dry value – reading) / (dry value – wet value) x 100, for a probe whose value falls as it gets wetter. For example, if dry reads 2.20 V, wet reads 1.10 V and the current reading is 1.65 V, moisture is (2.20 – 1.65) / (2.20 – 1.10) x 100 = 50 percent of the sensor’s range.
  4. Set thresholds from behaviour, not from the percentage alone. Water when the reading falls to the level where your plants start to need it, observed over a few cycles.

That percentage is relative, not volumetric water content. Proper lab instruments calibrate against weighed soil samples. Soil type changes the reading, just as moisture meter readings vary by material in building work, so recalibrate if you move the probe to different soil. Temperature and fertiliser salts also shift readings, especially on resistive probes.

Making it reliable outdoors

  • Waterproof the electronics. Many capacitive probes have exposed components at the top edge. Seal them with heat shrink, conformal coating or epoxy, and keep the line marked on the probe above the soil.
  • Keep the Pi dry in an enclosure with a cable gland, away from irrigation spray.
  • Insert the probe properly, with firm soil contact and no air gap, at root depth. Placement matters more than resolution; the piece on choosing a moisture meter explains why contact and depth drive the reading.
  • Log, then act. Write timestamped readings to a CSV file or a database before automating a pump, so you can see the real drying curve.
  • Separate power for pumps. Drive a pump through a relay or MOSFET module with its own supply; never power a motor from a GPIO pin. If you switch mains equipment, use a properly rated, enclosed relay or smart plug rather than open relay boards, and keep mains wiring to people qualified for it.

Wire one channel first

Connect a single capacitive probe to A0 of an ADS1115 at 3.3 V, confirm the 0x48 address with i2cdetect, and print voltages while you move the probe from air to a glass of water. Once you see a clean change, record your dry and wet points in real soil and only then add more sensors or a pump.

Frequently Asked Questions

Can I connect a soil moisture sensor directly to Raspberry Pi GPIO?

Only the digital output of a comparator module, powered from 3.3 V so its output stays within the GPIO limit, which tells you wet or dry against a threshold. For an actual moisture reading you need an analogue to digital converter, because the Pi has no analogue inputs.

Should I power the sensor from 3.3 V or 5 V?

If the sensor works at 3.3 V, use it, since every signal then stays within the Pi's safe range. If it needs 5 V, make sure its output cannot exceed what your ADC accepts at its supply voltage.

Why does my capacitive sensor read lower when wet?

On the common capacitive boards, more water raises the capacitance, which lowers the output voltage. That is normal. Calibrate with dry and wet points and invert the scale in your code.

How many sensors can one ADS1115 handle?

Four single-ended inputs per chip. You can add more ADS1115 boards on the same I2C bus by setting different addresses with the ADDR pin, up to four boards.

Why do my readings drift over weeks?

Resistive probes corrode and change their response. Capacitive probes drift less but can be affected by water reaching the electronics, soil settling around the probe and seasonal temperature changes. Recheck the dry and wet points occasionally.