A soil moisture sensor Raspberry Pi setup needs an ADC if the sensor is analog. Wire an MCP3008 over SPI, read the raw values, then calibrate dry and wet readings for that sensor. A digital-output module skips the ADC but only gives a dry/wet flag.
- Analog sensor: the Pi has no analog-to-digital converter, so put an MCP3008 between the sensor and the SPI pins.
- Digital output: read the pin as high or low and set the switching point with the module’s onboard threshold control.
- Calibration: record your own readings in water and in air before trusting any number.
This guide sits alongside other raspberry pi gpio projects. It starts with the common failure, a probe wired straight to a GPIO pin that returns nothing useful, and works through the fixes in the order you will hit them.
Why a GPIO pin cannot read an analog moisture sensor
Raspberry Pi boards have no built-in ADC. According to the ANAVI Technology capacitive sensor write-up, no version or model of the Pi includes one, so an analog sensor needs an external converter. A GPIO input only distinguishes high from low, while an analog probe outputs a voltage that changes gradually with wetness. The ADC turns that voltage into a number the Pi can read over SPI.

That gives you a real choice about readout style:
- Analog plus ADC: suits you if you want trends, a logged history or a moisture percentage. It costs an extra chip and a calibration step.
- Digital output: suits you if you only need a “water me” flag. It needs no ADC, but it cannot tell you how dry the soil is, only which side of the threshold it sits on.
For a plant monitor that you want to learn from over weeks, the analog route is the better starting point. The rest of this guide assumes it, then returns to the digital pin for the simpler case.
Choosing a probe that survives in soil
A capacitive sensor is the better choice for anything left in a pot. The ANAVI write-up describes capacitive soil moisture sensors (v1.2 and v2.0) as measuring the volumetric water content of the soil, and gives the main benefit as the lack of corrosion and a longer lifespan.
That is the answer to why resistive probes are a poor long-term choice. A resistive probe is the design the capacitive type is set against, and the capacitive approach avoids the corrosion problem because it senses water through capacitance rather than resistance. A resistive probe can be fine for a quick one-off test. For a monitor that stays in the soil, its readings and its metal are the parts that will wear out first.
Wiring the MCP3008 to the SPI pins
Enable SPI first. The ANAVI guide opens a terminal and uses the raspi-config tool to switch SPI on, then reboots the Pi. Without this step the ADC will not respond, and you will see an error opening the SPI device or no data at all.
Then wire the ADC in this order:
- Power the chip as the Microchip MCP3008 datasheet specifies for supply and reference voltage. Check the datasheet rather than guessing, because the supply range and your sensor’s output level must match.
- Connect the SPI signals (clock, data in, data out and chip select) to the matching SPI pins on the Pi’s header. Use the official Raspberry Pi pinout for the exact pin positions.
- Connect the sensor’s analog output to one of the ADC’s input channels. Note which channel you used, because your code must read the same one.
- Join the grounds of the Pi, the ADC and the sensor.
The MCP3008 is a common choice, but it is not the only one that works, as the FAQ below explains. Whatever chip you pick, a breadboard layout with short wires makes it easier to trace a mistake.

Reading raw values in Python
Once the wiring is done, the first goal is simply to see numbers change. Keep the script minimal at this stage.
- Install a Python library that supports your ADC over SPI.
- Open the channel your sensor is connected to.
- Print the raw reading at a steady interval.
- Move the probe between dry air and a glass of water and watch the number respond.
If the value never changes, check the channel number and the shared ground before anything else. These raw numbers are not a moisture percentage. The ShillehTek capacitive-sensor tutorial states that calibration is required if you want moisture content values, and it notes that each sensor may need individual calibration. Any typical range you read online is therefore only a rough pointer. Your own measurements are the ones that count.
Using the digital output and adjusting its threshold
Many sensor modules include a second pin that goes high or low depending on whether moisture is above or below a set point. Connect that pin to an ordinary GPIO input, read it as on or off, and you have a dry/wet flag with no ADC and no SPI.
The set point is adjusted with the small trimmer potentiometer on the module. The right setting is specific to your build. A Seeed Studio forum build warns that your signal will likely differ from the author’s because of minor differences in the sensor and general setup, so copying someone else’s threshold does not work.

A practical way to set it:
- Use real soil: push the probe into the pot when the soil is at the dryness where you want the alert.
- Turn the trimmer slowly: stop where the digital pin just changes state and the module’s indicator flips.
- Test by watering: confirm the output switches back once the soil is wet. Whether high means dry or wet depends on the module, so read the pin and note which way it goes.
Choose this route when a simple yes/no is enough. If you later want a graph of soil drying out between waterings, the digital pin cannot provide it, and the analog channel can.
Calibrating dry and wet values
Calibration turns raw numbers into something meaningful. The Seeed forum build tests the sensor in water and in air first, because that gives the upper and lower bounds of the sensor output, and it records readings for 5–10 minutes at each state to see how stable they are.
The ShillehTek tutorial adds the direction to expect. In general, analog values are higher when moisture content is higher, so the high calibration point is the sensor in a cup of water and the low point is the sensor in dry air.
- Record the low value: hold the probe in dry air until the reading settles, then note it.
- Record the high value: put the probe in water to the level marked on the board and note the settled reading.
- Scale between them: map your live readings onto the range between your two recorded values to get a relative moisture figure.
- Repeat per sensor: do not reuse the numbers from one probe on another.
Water and air are the outer limits. Soil will normally read somewhere between them, so once you have those bounds, check the probe in your actual pot when it is freshly watered and when it is dry. Those two soil readings are usually more useful for deciding when to water than the extreme values. The raw numbers you record are specific to your sensor and setup, so write them down and keep them with your script.
Fixing common problems
| Symptom | Likely cause | What to do |
|---|---|---|
| Error opening the SPI device, or no readings | SPI not enabled | Enable SPI in raspi-config and reboot the Pi. |
| Numbers change but mean nothing | Raw values, not calibrated | Record readings in air and in water and scale between them. |
| Reading falls when you water the pot | Direction differs from the general rule that wetter soil reads higher | Check against your water and air readings and base the scaling on what you measured. |
| Readings degrade over time | Resistive probe corroding | Switch to a capacitive sensor. |
These fixes draw on the ANAVI Technology guide and the ShillehTek calibration tutorial.
If the digital pin switches at the wrong moment, that is a threshold adjustment rather than a wiring fault, so go back to the trimmer and set it again in your own soil.
Turning readings into a plant monitor
With calibrated values, a Raspberry Pi plant monitor becomes a short loop. Read the channel, convert it to your relative moisture scale, log it, and compare it with a dry threshold chosen for that plant. A succulent and a leafy houseplant will not want the same threshold, so set one per pot.
The same pattern scales up. AWS documents a moisture-monitoring tutorial in which a Raspberry Pi 3B or 4B reads an Adafruit STEMMA I2C capacitive moisture sensor, sends the data to the cloud and raises an alert when the moisture level falls below a threshold. The principle is identical to a local script: a measured reading is compared with a threshold you decided on.
To make the monitor noticeable, add an output. An audible alert is one option, and the raspberry pi soundboard project covers getting sound out of the Pi. If you want to see how a different kind of sensor is read, the mpu6050 raspberry pi guide is a useful comparison.
Frequently asked questions
| Question | Answer |
|---|---|
| Can I read a moisture sensor without an ADC? | Yes, with a timing method. In the Seeed Studio forum build, an RC circuit turns the sensor’s capacitance change into a charge time. GPIO pin 14 counts that time constant, which is the time to reach about 63% charge. The build used a 1 MΩ resistor that suited its own system, so you may need to change the value. |
| Is the MCP3008 the only ADC that works? | No. The ANAVI build uses an MCP3002, described as a dual-channel ADC on an SPI bus. A commercial Pi garden kit lists a 4-channel, 16-bit ADC. Pick a multi-channel part if you plan one sensor per pot. |
| What about sensors that connect over I2C? | They send digital readings over the bus, so no ADC is needed. The AWS tutorial uses an I2C capacitive sensor, and the garden kit attaches its I2C sensors to the Pi through a Grove connector board. |
| What does a capacitive sensor measure? | It measures the volumetric water content of the soil by capacitive sensing, not resistive sensing, which is why it avoids the corrosion that affects resistive probes. |



