Soil Moisture Sensor Arduino
The SparkFun Soil Moisture Sensor is a simple breakout for measuring the moisture in soil and similar materials. The soil moisture sensor is pretty straight forward to use. The two large exposed pads function as probes for the sensor, together acting as a variable resistor.
Many publications exist about moisture sensors for applications, e.g. plant watering systems. Making a DIY Sensor is fun and cost-saving.
- 6,226 views
- 4 comments
- 3 respects
Components and supplies
| × | 1 | ||
| × | 1 | ||
| × | 1 | ||
| × | 1 | ||
| × | 1 | ||
| × | 1 | ||
| × | 1 | ||
| × | 1 | ||
| × | 1 |
Necessary tools and machines
Apps and online services
|
About this project
With the aim of building a system for watering a significant number of plants that are stored in a shed during the winter season, I searched the www to see what moisture sensors are available in the market. You will find many solutions. Most helpful was the publication from Andreas Spiess (I like his Swiss accent) on YouTube:
After seeing this, my conclusion was to make a sensor myself, because for my plant watering project (upcoming), I will need a few sensors for several plants.
I selected the ESP 32 as microcontroller, because of its multiple 12bits ADC inputs and the capability to generate PWM signals at higher frequencies than e.g. an Arduino Uno can do. In this project a 600 kHz signal will be generated for each sensor.

The Sensor is made of simple low cost materials that are widely available and it will be functioning as a capacitive moisture sensor.
Here you see the result:
Step 1: Making the Moisture Sensor
The DIY Sensor is made with simple materials:
- some audio cable
- two fondue forks
- a terminal block
- a plastic seat leg cover
- silicone paste
The pins are cut from fondue forks, that are chromium plated which will help to avoid corrosion. The construction with a terminal block enables easy connection of the copper cable wires to the chromium plated pins. The pins (that do not bend), facilitate easy insertion into the soil of the plant.
How simple can it be!
Funduino Soil Moisture Sensor
As an indicator for the measured moisture levels, I am reusing the water level indicator developed for my previous project :
For making this indicator, see my previous project: https://create.arduino.cc/projecthub/Pedro52/arduino-esp32-diy-water-level-sensor-and-diy-level-indicator-3d513d?ref=user&ref_id=328463&offset=0
Step 4: The Electronic set up
In the breadboard set up, I used an ESP 32s (Node MCU). The reasons for this choice are as stated in the introduction.

My plan is to expand this set up with functionality for making a complete plant watering system with on-line monitoring and warnings. (the ESP 32 has WiFi and Bluetooth on board).
The circuit diagram (made with Fritzing) is as follows:
The practical setup on the breadboard looks as follows:
The ESP 32 is powered with 5 V from the USB port and has a 3, 3V regulator on board. One output GPIO pin is connected via a 10KOhm resistor to one side of the Moisture Sensor and sends a 600 kHz signal to the sensor during the 5 measurements (for a period of 5 seconds). One input pin of the ESP32 (12 bits ADC) is connected via a diode and an R/C network (1MOhm and 1 uF). The other leg of the sensor is connected to GND.
The sensor is only powered for the duration of the measurements to avoid electrolysis effects on the chromium plated pens.
During my experiments, I established the minimum and maximum values of the sensor by putting the sensor in water (lowest measurement) and in open air (highest value). Putting the sensor in the plant pot results in intermediate values between the minimum and maximum, depending on the soil moisture level. The scale of the intermediate values appears to be quite linear.
Step 3: Making the Software
The loop function in the Arduino Sketch is simple and consists only of the calling 2 functions:
The 1 second delay between measurements are just for experimentation and demonstration purposes. In practical applications this will be far less frequent (normally a few times per day, depending on how thirsty your plants are)
The plot monitor of the ARDUINO IDE as well as the serial monitor have been very useful during experiments. A view of the plot monitor graph is given below:
The readings on the plotmonitor show values as measured by the 12 bits ADC. The complete 3.3V scale of the ESP 32 is devided by 4096, i.e.: 0.8 mV per step.
Measuring the moisture levels is done with the following code:
Hereafter the bracket in which the average value falls is determined in accordance with the above table and the moisture level is indicated on the Moisture Indicator with a color, which is very easy thanks to the <Adafruit_NeoPixel.h> library:
For downloading the sketch through the USB port onto the ESP 32, it is required to hold down the Boot button.
NOTES:
I am interested to hear if someone is actually going to reproduce this project.
Developed and produced by Pierre Pennings (December 2018).
Code
Schematics
Author
Pedro52
- 4 projects
- 15 followers
Additional contributors
- Very good tutorial about testing different sensors and showing how they work by Andreas Spiess
Published on
December 24, 2018
Members who respect this project
and 2 others
See similar projectsyou might like