Skip to content

Raspberry Pi Pico Capacitive Soil Sensor: Read Analog Values

October 22, 2023

Video Tutorial (Optional)

Watch first if you want to see the wiring and analog readings in real time.

Project Overview

Raspberry Pi Pico + capacitive soil moisture sensor: In this project, you wire a capacitive soil moisture sensor to a Raspberry Pi Pico and run code to read raw analog values so you can start building a moisture monitoring setup.

You will get analog readings from the sensor (not calibrated moisture percentage). Calibration is required if you want moisture content values.

  • Time: 10 to 20 minutes
  • Skill level: Beginner
  • What you will build: A Pico setup that reads raw analog values from a capacitive soil moisture sensor

Parts List

From ShillehTek

  • No ShillehTek product links were included in the original post.

External

  • Raspberry Pi Pico
  • Capacitive soil moisture sensor (analog output)
  • Jumper wires (and an optional breadboard)

Note: This tutorial focuses on reading raw analog values from the sensor. To convert those readings into moisture content, you will need to calibrate the sensor.

Step-by-Step Guide

Step 1 - Wire the sensor to the Pico

Goal: Connect the capacitive soil moisture sensor so the Pico can read its analog output.

What to do: Use the wiring shown in the photo. The key connection is the sensor signal wire (shown as yellow in the photo) to Pico pin 31, which is used for reading analog values.

Raspberry Pi Pico wired to a capacitive soil moisture sensor on a breadboard, highlighting the yellow signal wire connected to Pico pin 31 for analog readings
Wiring example: the sensor signal line connects to Pico pin 31 for analog input.

Expected result: Your sensor is physically connected and ready for the Pico to read analog values from its signal pin.

Step 2 - Copy and run the analog reading code

Goal: Run a script on the Raspberry Pi Pico that prints raw analog readings from the moisture sensor.

What to do: Open the code on GitHub and copy it into your local directory for your Raspberry Pi Pico, then run it:

https://github.com/shillehbean/youtube-channel/blob/main/capcitive_values.py

Expected result: With correct wiring, you should start receiving raw analog values.

Step 3 - Understand what the values mean (calibration)

Goal: Interpret the raw analog readings correctly and plan for calibration.

What to do: Treat the output as raw sensor values, not true moisture content. To estimate moisture, you must calibrate the sensor.

In general, analog values should be higher when moisture content is higher (moist soil). A simple approach is to calibrate by measuring a “high” value (for example, the sensor in a cup of water) and a “low” value (for example, dry air), then assume a linear trend between those points.

Expected result: You understand that each sensor may need individual calibration, and raw values alone are not yet a moisture percentage.

Conclusion

You now have a Raspberry Pi Pico reading raw analog values from a capacitive soil moisture sensor. Those readings can be converted into moisture content through a calibration process, but the raw values are the first step toward building a moisture monitoring project.

Want parts for your next build? Grab electronics and modules from ShillehTek.com. If you want help customizing this project or building a sensor-based solution for your product, check out our IoT consulting services.