Home > Microcontroller >Microcontroller Production > Make a capacitive soil moisture sensor using ESP32

Make a capacitive soil moisture sensor using ESP32

Source: InternetPublisher:走马观花 Keywords: Humidity sensor ESP32 Updated: 2023/12/25

In order to make it easier to water the plants maintained in the greenhouse in winter, I am going to set up a system in case of emergencies.

After much thought, I came to the conclusion that I was going to make a sensor myself, because for my plant watering project (coming soon), I needed several sensors for several plants.

I chose the ESP32 as the microcontroller because it has multiple 12-bit ADC inputs and is capable of generating PWM signals at higher frequencies than, say, an ArduinoUno. In this project, a 600kHz signal will be generated for each sensor.

The sensor is made from simple, low-cost materials that are widely available and can be used as a capacitive humidity sensor.

Step 1: Make the Humidity Sensor

DIY sensors are made from simple materials:

some audio cables

Two hot pot forks

Terminals

Plastic seat leg covers

Silicone paste

poYBAGJ2PdqACLNhAALvpLHHuDU056.png

The pins are cut from the fondue fork and chrome plated to help avoid corrosion. Construction with terminal blocks allows easy connection of copper cable wires to chrome-plated pins. The pin (not bent) facilitates insertion into the plant's soil.

As an indicator of moisture content, I'm reusing a water level indicator developed for a previous project of mine:

poYBAGJ2PdaASRpRAAHNctbKMpw670.png

Step 4: Electronic Setup

In the breadboard setup I used ESP32s (node ​​MCU). The reasons for this choice are stated in the introduction.

My plan is to expand this setup to have the functionality of making a complete plant watering system, with online monitoring and warnings. (ESP32 has onboard WiFi and Bluetooth).

The circuit diagram (made with Fritzing) is as follows:

pYYBAGJ2PdKAPF4zAATgiZAVkTY871.png

The sensor circuit diagram is as follows:

pYYBAGJ2Pc6AYTOpAAJq5APF2Qw966.png

The actual setup on the breadboard looks like this:

poYBAGJ2PcqAP9zpAAQP6ehs6nw388.png

ESP32 provides 5V power from the USB port and has an onboard 3, 3V voltage regulator. One output GPIO pin is connected to one side of the humidity sensor through a 10KOhm resistor and sends a 600kHz signal to the sensor during 5 measurements (lasting 5 seconds). One input pin of the ESP32 (12-bit ADC) is connected via a diode and R/C network (1MOhm and 1uF). The other leg of the sensor is connected to GND.

The sensor is powered only during measurements to avoid electrolytic effects on the chrome pen.

In my experiments I determined the minimum and maximum values ​​of the sensor by placing it in water (lowest measurement) and in the open air (highest value). Placing the sensor in a flower pot will produce values ​​intermediate between the minimum and maximum values, depending on the soil moisture level. The scale of the intermediate values ​​seems to be fairly linear.

Step 3: Make the Software

The loop function in ArduinoSketch is very simple and only consists of calling 2 functions:

pYYBAGJ2PcaATviJAAA12Z6gUHw856.png

The 1 second delay between measurements is for experimental and demonstration purposes only. In practical applications this frequency would be much less (usually a few times a day, depending on how thirsty the plant is)

ARDUINOIDE's drawing monitor and serial monitor are very useful during experiments. The view of the Drawing Monitor graph looks like this:

poYBAGJ2PcKALHBXAAFXqkvn6OA429.png

The reading on the plotmonitor shows the value measured by the 12-bit ADC. The ESP32's full 3.3V scale is divided by 4096, which is: 0.8mV per step.

Use the following code to measure moisture content:

poYBAGJ2Pb6ARMHcAAGnPpUuAwM877.png

The brackets for the average values ​​are then determined based on the table above and the humidity levels are indicated with colors on the humidity indicator, thanks to the "Adafruit_NeoPixel.h" library:

pYYBAGJ2PbeAf1MvAACUdBrv_nI924.png

To download the sketch to the ESP32 via the USB port, you need to hold down the Boot button.

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号