Read Capacitive Soil Moisture Sensor DFROBOT Gravity on the Raspberry Pi

In the field of Raspberry Pi soil moisture measurement, there are resistive and capacitive sensors, which each have advantages and disadvantages. The innovative Raspberry Pi casting machine / DFROBOT Gravity or “Giess-o-Mat” sensor provides a permanently accurate capacitive measurement, which a.o. in our Raspberry Pi greenhouse can be very interesting.

This tutorial is about the structure of the Raspberry Pi casting machine as well as the reading of the frequency, with the help of which the relative soil moisture can be calculated.

Since I have been asked by several users and there is not much material on the subject (in terms of the Raspberry Pi), I hope that this tutorial will make using it a bit easier.


Required Hardware Parts

For this I have taken the following hardware parts or components:

I recommend to take the coated version of the board right away, otherwise, it will anyway have to be manually sealed by hand. The supplied components of the board/sensor (listed below) are in SMD format and therefore not really suitable for beginners. With a little skill, the size should not be a problem.

The frequency divider can also be replaced by a resistor. In this case, the 100kΩ resistor at position R3 (see below) is replaced by a larger one: If the frequency is halved, a twice as large resistance is taken, etc. It is, of course, possible to combine several resistors.


Advantages over Resisitive Moisture Sensors

Resistive earth moisture sensor

Resistive earth moisture sensors often do not last long.

In a previous tutorial, we connected and read out a very low-priced soil moisture sensors on the Raspberry Pi. However, this design has a problem that occurs over time: corrosion. After prolonged use with the same polarity, the sensors often partially decompose. This is not good for the measuring behaviour nor for the soil values.

This danger does not exist with capacitive sensors. In this case, however, no analog signal is output, which can be read with an MCP3008 ADC, but a frequency that varies in height – depending on the humidity of the earth (the wetter, the lower).

The output frequency (up to 450kHz) is too much for the Raspberry Pi, which is why we either use a frequency divider that divides it by a certain dividend, or simply a bigger resistor. The disadvantage of a frequency divider is the price because a simple resistor costs almost nothing.


Assembly of the Raspberry Pi casting machine

The Giess-o-Mat usually does not come assembled, which is why the individual SMD components have yet to be soldered onto the board. Since these are very small, a look on the label helps. I also tried to document each step with pictures, so nothing goes wrong.

The DFROBOT Gravity sensor is easier to handle: There is no soldering required, so you can ignore this step.

The following help sheet can be found in the bag of the components:

Description Type Label Function
T1 BC847B 1Ft od. 1FW Transistor
C1 10μF 10V Condenser
IC1 74HC14D HC14 IC
D1 BZX84B5V6 T12 or Z3 Zener diode 5v6
R1 1k 102 od. 1001 Resistor 1k
R2 100R 101 od. 1000 Resistor 100R
R3 100k 104 od. 1003 Resistor 100k

Let’s start with the IC. It is important that the side with the “up” mark shows where the little round notch can be seen on the PCB.

The capacitor (C1) has no label and it does not matter which side is soldered where:

With the resistors (R1, R2, R3) you must be careful since the SMD inscription does not correspond to the actual size. On this page, you can simply enter the imaged value of the SMD resistor and get the real size calculated.

If you do not have a frequency divider, you can also use a larger resistor instead of R3 (as described above).


Subsequently, the only transistor (T1) and Zener diode (D1), which have the same shape, are missing. Here again, helps the label from above:


Assemble Frequency Divider (optional)

In the same way as the casting machine, we also build the frequency divider if we have one.

First the table:

Description Type Label Function
T1 BC847B 1Ft, 1F-, 1FW Transistor
C1 10μF 10V Condenser
IC1 74HC4040 HC4040 IC
D1 BAS40 43t, 43-, 43p, 43W Schottky Diode
R1, R2 2k2 222, 2201 Resistor 2k2

Again, we start with the IC, the capacitor and the resistors. The size of R1 and R2 is identical.

frequency divider

Still missing transistor (T1) and the diode (D1). Pay attention again to the label, as the design is identical:

frequency divider 2


Last but not least, the two contacts of “: 16” are soldered together, resulting in a 16 times lower frequency.

In addition, I have soldered the two boards together and soldered to the frequency divider a few contacts for the jumper cable.

Raspberry Pi Giessomat



A Script for reading the Frequency

First connect V + and 3.3V from the Raspberry Pi, GND to GND and OUT e.g. at GPIO21.

To read the frequency on Raspberry Pi is the PiGPIO library, which brings libraries for C (++), Python, etc. It is already preinstalled on ordinary Raspbian versions (not Lite), otherwise we can install it afterwards:

sudo apt-get update
sudo apt-get install pigpio python-pigpio python3-pigpio


Then we create a new C-file, which is there to read the frequency:

sudo nano freq_count_1.c

This file gets the following content (example from here). Save with CTRL + O and return CTRL + X to the terminal.

Then we compile the files:

gcc -Wall -pthread -o freq_count_1 freq_count_1.c -lpigpio -lrt

Now the program can already be called. Only the corresponding GPIO pin must be specified, to which “OUT” is connected (eg 21):

sudo ./freq_count_1 21

Then the number of the GPIO followed by the frequency (in Hz) will be displayed. As a test, you can put the sensor in a glass of water and watch the frequency decrease.

In a project like the Raspberry Pi greenhouse, it is now important to find out the optimal value. However, this depends on the soil, the irrigation and the plants and therefore can not be answered clearly. For me, full wetness (glass of water) gave a frequency of about 1000Hz, with total dryness (no conductive material) about 10kHz (with a frequency divider of 16).

If you use a Python script, you can also extend/shorten the upper C program and integrate it into your Python script.


Further information on Giess-o-Mat

Further information about the casting machine is available a.o. on the following pages, most of which are for use with Arduino and/or ESP8266 and less with the Raspberry Pi. Nevertheless, I think that it can be worth reading links for those interested:

If you know another good source, you can post it as a comment so I can expand the list.

Leave a Comment

Your email address will not be published.

Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!