Skip to main content

Sensor Calibration

Correct calibration of the Capacitive Soil Moisture Sensor

Capacitive Soil Moisture Sensor is essential for predictable watering. On this sensor type, higher ADC
Analog-to-Digital Converter - converts analog voltages into digital values that microcontrollers can read.
value means drier soil
.

This page shows a simple procedure to determine realistic thresholds for your soil and pot.


0. Prepare the system

Install a proper IDE (e.g. Thonny

) and set it up to work with your Development board of choice
A printed circuit board (PCB) that includes a microcontroller or microprocessor, along with necessary components and interfaces for prototyping and development.
Development board
.

1. Connect the sensor

Wire the sensor to the Development board of choice

Development board:

  • VCC → 3.3 V or 5 V (according to sensor rating)
  • GND → GND
  • OUT → ADC
    Analog-to-Digital Converter - converts analog voltages into digital values that microcontrollers can read.
    input (refer to the GPIO pinout for the board you are using)

Make sure the firmware is not running yet so you can use the REPL

Read-Eval-Print Loop - an interactive environment that executes commands immediately and prints the result.
for manual testing.

⚠️ Before plugging in the Development board make sure the valve is disconnected, since accidental current surge may damage your computer!


2. Run a simple ADC
Analog-to-Digital Converter - converts analog voltages into digital values that microcontrollers can read.
test script

Use this short script in the MicroPython

REPL
Read-Eval-Print Loop - an interactive environment that executes commands immediately and prints the result.
to print the raw ADC
Analog-to-Digital Converter - converts analog voltages into digital values that microcontrollers can read.
value once per second:

from machine import Pin, ADC
from time import sleep

adc = ADC(Pin(26)) # Change this to the GPIO pin connected to the sensor

while True:
print(adc.read_u16())
sleep(1)

3. Record values for different conditions

Measure and note the ADC

Analog-to-Digital Converter - converts analog voltages into digital values that microcontrollers can read.
values for:

  1. In air (probe not touching anything)
  2. Dry soil (inserted in your pot, soil as dry as you consider acceptable)
  3. Wet soil (after watering the pot thoroughly and letting water soak in)

You will typically see something like this (example only):

ConditionExample ADC
Analog-to-Digital Converter - converts analog voltages into digital values that microcontrollers can read.
value
Air~50 000
Dry soil~31 500
Wet soil~23 000

Your values will differ; what matters is the relative spacing.


4. Choose thresholds

Use the dry and wet readings to set two thresholds:

  • DRY_THRESHOLD - above this value, the soil is considered too dry → watering starts.
  • WET_THRESHOLD - below this value, the soil is considered wet enough → watering stops.

Example based on the table above:

  • DRY_THRESHOLD = 30000
  • WET_THRESHOLD = 25000

This gives some Hysteresis

A control technique that uses separate thresholds for turning something on and off to avoid rapid oscillation.
so the system does not rapidly toggle on every tiny fluctuation.

Edit these constants in your main.py file and redeploy it to the board.


5. Verify in real use

Let the system run for a few days and watch:

  • How often it waters
  • Whether the soil is staying too wet or too dry
  • The printed ADC
    Analog-to-Digital Converter - converts analog voltages into digital values that microcontrollers can read.
    values around each watering event

Fine-tune DRY_THRESHOLD, WET_THRESHOLD, WATER_TIME_SEC and MEASURE_INTERVAL until it behaves the way you want for that plant and soil.