Soil Moisture Monitoring System

author Andrei Simion ACES 2022
source code : Soil Moisture Monitoring System Gitlab
youtube demo : YT DEMO

I Description

The idea from which I started this project would be that we always forget to water the flowers, and in agriculture or even in the flower garden (or even the few flower pots in everyone's apartment) monitoring the soil moisture is imperative. If we want to have good crops or flowers that are healthy and grow beautifully. Due to the fact that IoT is becoming more and more present in our lives, in order to simplify this routine, of regular watering / irrigation, I decided to create a system for monitoring and tracking soil moisture. The system picks up soil moisture with a sensor and will publish the data to the feed in my dashboard on where a real-time graph is drawn. At the same time, the current soil value will be displayed locally on an LCD screen. All the time, different events that are fulfilled in the operation of the system will be displayed on the serial. In addition, the system will send a daily warning email at a certain time with the current value of soil moisture.
The purpose of this project is to have good irrigation management that will provide better crops or healthier plants.

II Hardware

As hardware components for the realization of this project I used:

  1. Development board ESP-WROOM-32
  2. Display LCD I2C
  3. Resistive Soil Moisture Sensor
  4. WiFi Router

1. Development board ESP-WROOM-32

The core of this module is the ESP32-D0WDQ6 chip. The built-in chip is designed to be adaptable and scalable. It has a processor with 2 cores that can be controlled individually and the clock frequency can be adjusted from 80MHz to 240MHz.


  • Protocol: 802.11 b/g/n/e/i (802.11n up to 150 Mbps)
  • Security: WPA/WPA2/WPA2, WPS
  • Wi-Fi Direct / SoftAP
  • Encryption: AES/RSA/ECC/SHA
  • Frequency: 2.4 GHz ~ 2.5 GHz
  • Bluetooth: 4.2
  • NZIF receiver with -97 dBm sensitivity

2. Display LCD I2C

This LCD 1602 screen has IIC / I2C mode which needs only two connections, SDA / SCL data, Vcc and ground connection. This display is perfect for projects where we do not have many pins available from the microcontroller.

3. Resistive Soil Moisture Sensor

A soil moisture sensor can read the amount of moisture present in the soil surrounding it. It's an ideal for monitoring an urban garden, or your pet plant's water level. This is a must have component for a IOT garden / Agriculture! The new soil moisture sensor uses Immersion Gold which protects the nickel from oxidation. Electroless nickel immersion gold (ENIG) has several advantages over more conventional (and cheaper) surface platings such as HASL (solder), including excellent surface planarity (particularly helpful for PCB's with large BGA packages), good oxidation resistance, and usability for untreated contact surfaces such as membrane switches and contact points.


  • Power supply: 3.3v
  • Output voltage signal: 0~4.2v
  • Current: 35mA
  • Pin definition:
    • Analog output
    • GND
    • Power
  • Size: 60x20x5mm(2.36×0.79×0.2”)
  • Surface finish:Immersion Gold

4. Router WiFi

Access point to WAN. We need to be able to make different requests to various servers (MAIL (SMTP), NTP, MQTT etc).

  Soil Moisture Monitoring System HW Diagram

III Software

 Software Diagram

In this part of the code I have defined macros and declared global configuration variables specific to the operation of peripherals, connections to servers and APIs that will allow us to make various setup function calls in the next step.

At this step all the initializations of peripherals, services, etc. that we need are done:

  1. the serial is initialized with the boudrate of 115200
  2. the LCD screen initializes
  3. trying to connect to the network via WiFi by calling the try_connect_WiFi() function
  4. initialize connection to NTP server and test requesting current date via print_localtime_test()
  5. SMTP is initialized with smtp.debug(1) to print the debug mode of the service on the serial and with smtp.callback(smtpCallback) the callback function is set to obtain information about the status of the email being sent
  6. the SMTP session is initialized with the call of the set_session_config(ESP_Mail_Session*) function and the header of the message to be transmitted, by the call of the set_message_header(SMTP_Message*) function

This is the main loop. Once you reach this stage, the code described in the loop() function will run indefinitely(endless). Basically here is a description of the functionality of the entire system. The following main operations are performed here:

  1. the call of the compute_moisture_percentage() function is made and the soil moisture sensor is read and the obtained value will be transformed into percentages.
  2. the information is displayed on the screen.
  3. by calling the MQTT_connect () function we connect to the feed in the dashboard on
  4. data is published calling SoilMonitoring.publish(moisturePercentage)
  5. by calling the get_time_hour() function I request the NTP server for the current hour and minute and then I check if they are the ones I specified. if this condition accomplished i will call send_message(String)

 Soil Moisture Monitoring System


iothings/proiecte/2021/soilmoisturemonitoringsystem.txt · Last modified: 2022/01/27 14:01 by andrei.simion1707
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0