It's easy to use the Simple Soil Moisture Sensor with CircuitPython, and the analogio core module module. This module allows you to easily write Python code to read analog input data from the soil sensor.
CircuitPython Microcontroller Wiring
First wire up the breakout to your board exactly as follows. The following is the sensor wired to a Circuit Playground Express with alligator clips:
- Board 3.3V to sensor 3V (red wire)
- Board GND to sensor GND (black wire)
- Board A0 to sensor OUT (white wire)
Here is a Metro M0 Express wired up using a 3-pin JST-SH cable:
- Board 3.3V to sensor JST-SH 3V (red wire)
- Board GND to sensor JST-SH GND (black wire)
- Board A0 to sensor JST-SH OUT (white wire)
CircuitPython Usage
To use with CircuitPython, you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder will be empty since the example is only using core modules that are built into the CIRCUITPY drive.
Example Code
Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
from analogio import AnalogIn
analog_in = AnalogIn(board.A0)
while True:
print(f"Soil Moisture: {analog_in.value}")
time.sleep(5)
The soil moisture data is read as a 16-bit analog value. If the reading is below 2000, the soil is dry. Above that, it is moist.
Advanced Sensing
One disadvantage to the soil sensor is that the soil probes can oxidize over time. There is a "hack" you can do to prolong the life of the probes. You can connect the sensor 3V pad to a digital pad on the microcontroller and turn it "on" only when you're getting an analog reading.
Advanced Wiring
First wire up the breakout to your board exactly as follows. The following is the sensor wired to a Circuit Playground Express with alligator clips:
- Board D5 to sensor 3V (red wire)
- Board GND to sensor GND (black wire)
- Board A0 to sensor OUT (white wire)
Here is a Metro M0 Express wired up using a 3-pin JST-SH cable:
- Board D5 to sensor JST-SH 3V (red wire)
- Board GND to sensor JST-SH GND (black wire)
- Board A0 to sensor JST-SH OUT (white wire)
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
from analogio import AnalogIn
from digitalio import DigitalInOut, Direction
sensor_power = DigitalInOut(board.D5)
sensor_power.direction = Direction.OUTPUT
analog_in = AnalogIn(board.A0)
while True:
sensor_power.value = True
print(f"Soil Moisture: {analog_in.value}")
sensor_power.value = False
time.sleep(5)
The soil moisture data is read as a 16-bit analog value. If the reading is below 2000, the soil is dry. Above that, it is moist. Before a reading, pin 5 is set to True, turning on the sensor. After the reading, pin 5 is set to False, turning the sensor off.
Page last edited July 14, 2025
Text editor powered by tinymce.