New from today: Soil moisture sensor

Hello everyone,

Today I would like to introduce you to a new sensor that we have in our shop from today. Our Capacitive Hygrometer V1.2

This module functions Capacitively, i.e. unlike the previous model, there is no corrosion by galvanic processes. The output of this sensor is analogue, i.e. although it supports 3.3V controllers, it cannot be read by a Raspberry that does not have analog input. In principle, this sensor module is not only suitable for measuring moisture in substrate, but also for displaying a filling level. Before we use the sensor productively, our sketch has to be calibrated to the respective values.

For our application example we use a NanoV3. And a glass of water instead of a flower pot, because the moisture of the substrate cannot be changed as easily as the level of a glass. Libaries are not required.

The Pine Layout:

NanoV3 Sensor



We start with the simplest start-up, the AnalogReadSerial example that is already integrated into the IDE: Examples -> Basics > AnalogReadSerial

and receive the following output in the Serial Monitor:

in the Serial Plotter it looks a bit more attractive, but is still not ideal:

We use the Smoothing Tutorial on, here the code:



 created 22 April 2007
 by David A. Mellis <>
 modified 9 April 2012
 by Tom Igoe

 This example code is in the public domain.

const int numbReadings = 10;

int readings[numbReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPine = A0;

void setup() {   Serial.start(9600);   for (int thisReading = 0; thisReading < numbReadings; thisReading++) {     readings[thisReading] = 0;   }

void run() {   /subtract the last reading:   total = total - readings[readIndex];   // read from the sensor:   readings[readIndex] = analog(inputPine);   // add the reading to the total:   total = total + readings[readIndex];   // advance to the next position in the array:   readIndex = readIndex + 1;   If we're at the end of the array...   if (readIndex >= numbReadings) {     wrap around to the beginning:     readIndex = 0;   }   // calculate the average:   average = total / numbReadings;   Serial.Print(average);   delay(1);        // delay in between reads for stability


After we upload the code, the optical output is a little more pleasant:

So we find that the empty glass delivers values around 792. So we've determined the highest value. Now we determine the lowest value by dipping our sensor into water up to a height that you set.

The immersion depth, i.e. the height of the level in the glass/substrate must always remain the same for comparisons, we have chosen the point of v1.2 as a marker. And get the following values:

So the full glass provides about 419. That is, we are moving in an area of 792- 419. Please make sure to perform this calibration in the medium you want to use later, as the values vary depending on the substrate.

Since this sensor is so versatile, different substrates are possible, plants have different preferences and we cannot estimate your scale we provide code at this point which we already have in our AlcoTest have shown:


if (average >= 0 and average <= 400) {     state = Sensor malfunction?;   }   ed if (average >= 400 and average <= 500) {     state = Thirsty!;   }   ed if (average >= 500 and average <= 649) {     state = Moisture!;   }   ed if (average >= 650 and average <= 800) {     state = Patschnass!;


A case for self-printing is available free of charge to find the required files Here.

Have fun trying and experimenting, maybe a faithful reader will find the desire to make a smart glass to show the bartender the level of his guests. :) Until the next post







The sensor is said to be version 1.2 but there are differences from other 1,2 version available directly from china market. On the AZ_Delivery sensor, the LDO (U2) seems to be replaced by diode. There is not schematic offered on the web site :(

When supplied with 3.3V, sensor did not provide any output voltage (NE555 is requiring 5V supply). When supplied with 5V, sensor provide 4V on its output as dry (less voltage, when wet) . For 3.3V controllers (like ESP32) this can be fatal!

I have found (as possible solution) resistor of 100 Ohms in series to the 5V power pin is dropping the voltage over the sensor and impacting the sensor output voltage in positive way (3V as dry, less when wet) . This allows to work safely with ESP32 microcontrollers.



danke für Ihre nutzbare Aufgabe. Ich möchte diese Aufgabe mit STM32 und HAL_Drive schreiben. Wie kann ich letzten Teil schreiben? Wie kann zeigt , der Boden Nass ist oder trocken?
Viele Grüße



Wenn ich den Sensor in das Wasser tauche und den Beispielcode “AnalogReadSerial” ausführe, liefert mir der Monitor lediglich Werte zwischen 0 und 13. Was mache ich falsch?



sehe ich auch so wie Ralf.




Dringt von den (Schnittkanten der Platine) kein Wasser in den Sensor ein?




sind eure Werte für die Feuchtigkeit nicht verdreht, Müßte nicht zwischen 400 und 500 Patschnass und zwischen 650 und 800 Pflanzen haben Durst sein.


Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN