Soil moisture sensor for monitoring indoor plants.

Providing ideal water to plants can be a challenge. An electronic soil moisture sensor ensures that the plants are watered on time.

This tutorial describes the construction of an Arduino-based soil moisture sensor.

On the one hand, this indicates directly on the sensor via a flashing LED if the plant has too little water. The exact humidity value is also transmitted to the smart home center (e.g. Home Assistant) via MQTT. The programming is designed so that the LED display also works when the MQTT server is offline.

In order to enable operation independent of sockets (via power bank or batteries), the LOLIN32 development board was deliberately chosen, which consumes less power in DeepSleep mode than the D1 Mini. To save electricity, LOLIN32 goes into DeepSleep for 60 minutes after each successful measurement (and if the soil moisture is at least 50%).

Requirements:

  • The setup requires certain electronics and PC knowledge. A computer with an installed Arduino IDE is required to install the software.
  • In addition, an MQTT-compatible smart home system (e.g. Home Assistant) is required.

hardware

Components

The following components are required for assembly:

  • Capacitive soil moisture sensor, version 1.2
  • LOLIN32, V1.0.0
  • 5mm LED, red
  • 1 x 220 ohm resistor
  • Breadboard, 400 pin
  • 40 x jumper cable 10 cm, male male

The complete set of components in our shop:

soldering

So that the LOLIN32 can be soldered to the circuit board, it must first be soldered to the PINs. Please make sure that the PINs are soldered on at right angles so that they later also fit the circuit board.

Put

In the next step, all components are placed on the breadboard. The following Fritzing diagram gives a good overview.

 

For the soil moisture sensor, it is best to use three additional jumper cables, which are plugged into the breadboard on the one hand and into the plug of the cable of the soil moisture sensor on the other (see illustration at the beginning of this tutorial).

Arduino programming

Download and install the Arduino IDE

We need the Arduino IDE, which can be downloaded for free here: https://www.arduino.cc/en/Main/Software

It's even easier on Windows PCs, where the Arduino IDE can be installed via the Microsoft Store.

Add LOLIN32 board

First, add the following "Additional Board Administrator URL" to the default settings: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

To do this, we proceed as follows:

1. We call up the default settings:

2. We add the URL: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Install "ESP32" board

To do this, we navigate to "Tools -> Board -> Board Manager".

Now we search for "ESP32" and install the board.

Select "WEMOS LOLIN32" as the board

To do this, we proceed as follows:

1. We navigate via "Tools -> Board -> ESP32 Arduino"

2. We select "WEMOS LOLIN32" as the board

Select upload speed

Under "Tools -> Upload Speed" we select 115200.

Copy the Arduino sketch for calibration from GitHub

Due to the design, each capacitive soil moisture sensor delivers slightly different values. Therefore, we first determine the calibration values of our soil moisture sensor. 

To do this, we call up the following Arduino sketch from GitHub and use "Copy / Paste" to copy it into a new sketch in our Arduino IDE:

https://github.com/NEOE-IO/NEOE-IOT-Kit-4/blob/master/Kalibrierung_Bodenfeuchtesensor.ino

Upload Arduino sketch for calibration to LOLIN32

Now we're closing ours Soil moisture sensor to our computer via a USB cable.

Then we select the relevant USB interface (e.g. COM3 or COM4) via "Tools -> Port".

Now we click on "Sketch -> Upload".

Perform calibration

Now we start the serial monitor and set the baud rate to the defined value of 9600. This is the only way to display the data in the serial monitor

The calibration value is now output on the serial monitor of the Arduino IDE.

Now we note the value when the soil moisture sensor is completely dry and we do not touch it. This is the higher value. We need this value in the next step for the parameter "const int airValue".

Then we carefully put the soil moisture sensor into a glass of water so that the marking line is exactly at the level of the water surface. Please do not immerse yourself deeper and make sure that the electronics are never immersed in the water. Otherwise there is a risk that the sensor will break. We need this value in the next step for the parameter "const int waterValue ".

Copy the Arduino sketch for normal operation from GitHub

Now we call up the following Arduino sketch from GitHub and copy it into a new sketch in our Arduino IDE using "Copy / Paste":

https://github.com/NEOE-IO/NEOE-IOT-Kit-4/blob/master/NEOE-IOT-Kit-4.ino

Now we have to add individual information to the Arduino sketch (see comments in the sketch), e.g. for

  • Previously determined values for "const int airValue" and "const int waterValue"
  • WLAN access data
  • MQTT server data

Please read all comments in the sketch carefully.

Upload the Arduino sketch to LOLIN32 for normal operation

Now we connect our soil moisture sensor to our computer via a USB cable.

Then we select the relevant USB interface (e.g. COM3 or COM4) via "Tools -> Port".

Now we click on "Sketch -> Upload" and if there are no more errors in the sketch, it can be successfully uploaded and we can now use our "soil moisture sensor".

CONNECTION TO SMART HOME SYSTEM

The NEOE IOT kits are developed and tested for home assistants, as this is the smart home system we currently prefer due to the extensive and well-engineered functionalities. For more information on Home Assistant, see https://www.home-assistant.io.

Home Assistant

For the basic setup of Home Assistant, see https://www.home-assistant.io/getting-started/.

We designed the Arduino Sketch to support Home Assistant's MQTT Discovery functionality. As a result, the sensor is automatically recognized by Home Assistant and the data transmitted via MQTT can be displayed directly in the dashboards. To activate the MQTT Discovery function in Home Assistant, see https://www.home-assistant.io/docs/mqtt/discovery/.

The sensor data can be displayed in the Home Assistant dashboards in different ways.

Sensor Card:

 If you click on the sensor card, a history is displayed:

 

Expansion stage: autonomous operation with NiMH batteries and solar cells

If there is no socket for a USB power supply unit nearby and no power bank at hand, battery operation with three Mignon (AA) NiMH rechargeable batteries is recommended. Complete independence from the power grid is possible if you add a solar cell and a solar charge controller.

We have developed our "NEOE Solar Extension Kit" for this application scenario.

For more information, see the following entry: 

NEOE solar expansion kit in our shop:

Further possible expansion stages

If you add one water pump and a relayso a fully automatic irrigation system can be developed.

 

 

Disclaimer - all information without guarantee:

The information contained in this tutorial (contribution) has been researched and compiled to the best of our knowledge and belief. However, mistakes can happen to us too. And something can also go wrong during the implementation of the tutorial or the content can be misunderstood. We cannot therefore accept any liability for any damage caused by following this tutorial. We are continuing to develop our tutorials. If something is inconsistent or unclear, please let us know so that we can correct or add to the point concerned. Thanks very much.

Leave a comment

Please note, comments must be approved before they are published