Categories
TUTORIALS

Using a Capacitive Sensor to Measure Soil Moisture

Introduction

This tutorial covers how to use the Adafruit STEMMA Capacitive Soil Moisture Sensor. This sensor works using the same technology as capacitive touchscreens, which are so effective precisely because the human body contains a large amount of water; water is particularly good at altering the capacitance in the sensor, which makes using capacitance to measure moisture an effective tactic.

Pros and Cons

This sensor is an excellent choice for someone seeking to generally measure moisture over a long period of time; unlike resistive moisture sensors (commonly seen in Arduino projects), this sensor does not degrade quickly over time and should produce reliable readings for a long period. However, this sensor also comes with a major downside: because it only produces a capacitive measurement, it is not possible to calibrate it to a specific water quantity or moisture level, such as a volumetric water content (VWC). This lack of calibration ability means this sensor is best suited to environments in which you already know a lot about the water provision to a source, or projects where what matters is the binary presence/complete lack of water in a specific location.

Tutorial Use Case

The purpose of this tutorial is to introduce the sensor and some basic code that can be used to obtain and display measurements from the sensor. In addition, the code includes a “moving-window” approach to reporting data, where the current measurement is averaged with some number of previous measurements before reporting. This approach helps eliminate outliers and other “noise” in the raw sensed data. Thus, the tutorial code is best applied to situations where you are immediately reporting data readings with no additional, after-the-fact data processing or analysis. The code also includes a “wet/not wet” threshold of 400 and prints out the “wetness” status it is sensing based on that cutoff. This threshold can be adjusted based on the context in which you are using the sensor.

Parts List

  • Arduino UNO Board & Starter Kit
  • Adafruit STEMMA Capacitive Soil Moisture Sensor
  • JST PH 2mm 4-pin to Male Header Cable/I2C STEMMA Cable, 200mm

Circuit Diagram & Wiring

Attach the sensor directly to the Arduino board using the 4-pin cable with the following connections (shown in the diagram below as well):

  1. Red wire (V in) to 5V power supply pin
  2. Black wire (Ground) to GND pin
  3. Green wire (SCL) to A5
  4. White wire (SDA) to A4

Code

To use this sensor, first install the Seesaw library from Adafruit, which can be found by searching “seesaw” in the Sketch>Include Library>Manage Libraries dialogue box:

Once the library is installed, paste the below code into a new Arduino sketch file, and upload it to your board. Once the code is uploaded, open the Serial Monitor (make sure it is set to read data at a 115,200 baud rate), and check out your temperature and moving-window average capacitance readings. Because the sensor reports capacitance, you can test to see if it’s working by simply touching your finger to the sensor—it uses the same technology as many touchscreen devices.

NOTE: For purposes of demonstration, this code takes a measurement reading every second. When measuring soil moisture levels, it is likely unnecessary to measure this frequently, and the interval can be increased by changing the delay quantity at the very end of the code.

References:

https://cdn-learn.adafruit.com/downloads/pdf/adafruit-stemma-soil-sensor-i2c-capacitive-moisture-sensor.pdf

https://www.lionprecision.com/capacitive-sensor-operation-and-optimization-how-capacitive-sensors-work-and-how-to-use-them-effectively/

One reply on “Using a Capacitive Sensor to Measure Soil Moisture”

Hi, i have a problem the sensor work normally with the exemple and now i don’t know why he doesn’t work anymore i have every time “Error seesaw not found” do you have an idea what is the problem ?

Leave a Reply

Your email address will not be published. Required fields are marked *