ESP32 WiFi SOIL MOISTURE SENSOR

About: Hobbies: Raspberry PI, Electronics, Python, Drones , CNC router, Qualification: BCom with majors in Statistics and Economics

Cheap soil moisture sensors which send an electrical signal through soil to measure the resistance of the soil is all failing. Electrolysis makes this sensors of no practical use. See more about electrolysis here. The sensor used in this project is a capacitive sensor and no conductive metal is in touch with wet soil.

After loading the firmware (Arduino sketch), the sensor will create a web server on itself and log into your WiFi router. You can now access the web side on the ESP32 sensor. No data is send to the cloud.

Some familiarity with Arduino Programming, Soldering skills and HTML etc may assist. If you build this project, please upload photos via the upload link below. Enjoy the hacking.

This sensor can read:

  1. Soil Moisture (My code will calculate the gravimetric soil water content)
  2. Air temperature and relative humidity

Supplies:

  1. Wemos® Higrow ESP32 WiFi + bluetooth Battery + DHT11 Soil Temperature And Humidity Sensor Module
  2. For data logging (optianal)
    1. a Micro SD Card Module.

    2. Bread Board and OR

    3. Soldering Iron, solder paste.

    4. Six Female to Male jumper cables.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: INSTALL AND CONFIGURE THE ARDUINO IDE ON YOUR PC/MAC

This setup procedure should work on a Windows PC, MAC and LINUX (x86) system. Unfortunately for Raspberry PI users the LINUX (ARM) Libraries for the ESP32 Board is not available yet (although there was real clever people who compiled them from source) .

  1. Download and Install the Arduino IDE
  2. In the Preferences menu, add https://dl.espressif.com/dl/package_esp32_index.json to the Aditional Boards Manager URL.
  3. Install the ESP32 Libraries from Tools>Board>Boards Manager. Search for esp32 by espressif systems
  4. Select your Board in the menu: Tools>Board>"WeMos" WiFi & Bluetooth Battery
  5. Install the required DHT11 Libraries from Tools>Manage Libraries...
    1. You need to install DHT sensor library by Adafruit Version 1.3.7 (Or later?)
    2. You need to install Adafruit Unified Sensor by Adafruit Version 1.0.3

Step 2: ATTACH MICRO SD CARD FOR LOGGING (OPTIONAL)

If you need to log your data, attach a Pololu Micro SD Card Module. Other SD cards may have different wiring and code.

Step 3: DOWNLOAD THE ARDUINO SKETCH

  1. Download the applicable arduino sketch from GitHub and open it.
    1. Esp32_SoilMoisture_WebServer.ino should be use if no micro sd card module is attached.
    2. Esp32_SoilMoisture_WebServer_DataLog.ino requires an micro sd card and continues internet access to the NTP server. This option has very accurate time, but use large amounts of current and may deplete the battery.
    3. Esp32_SoilMoisture_WebServer_DataLog_Int_RTC.ino requires an micro sd card and internet access to the NTP server after reset. It uses the internal RTC of the ESP32 to update the date/time received at reset from the NTP server. This is the most power efficient solution, but the time may not be as accurate.
  2. Edit your Router SSID and Password in the sketch.
  3. Compile the sketch while pressing the boot button.
  4. If compiling is successful, press the EN button and immediately start the Arduino Serial Monitor (115200 Baud Rate)
  5. Wait for the Blue LED to go on and OFF
  6. Get the IP address printed in the serial monitor, enter it in your browser. You will now see the sensor data web page.
  7. If you added the micro sd card reader, and you compiled one of the applicable arduino sketches, you can access your data in /datalog.txt of your micro sd card.

Step 4: GRAVIMETRIC WATER CONTENT-CALIBRATION

How should I interpret the soil moisture reading from GPIO 32?

One method is to calculate the gravimetric water content of the soil. It is calculated as:

(Mass of Water in Soil Sample)/(Mass of Dry Soil in Sample)

I have collected dry soil out of my garden (It is Limpopo, South Africa, August month and the soil is dry, really dry). You can dry soil in a oven.

  1. Weight you dry soil
  2. pour the dry soil in a container, insert the sensor in the soil and take a raw sensor reading (use the web interface). Record the Water Mass (=0 at this stage) and the sensor reading.
  3. Remove the sensor, add 10 ml (gram) water, mix the soil and water properly and record your Water Mass (=10 at this stage) and the sensor value.
  4. Go on with this process as far as you like, or until adding water does not influence the sensor reading anymore.
  5. My results is in the attached excel sheet. GWC is calculated as gwc=exp(-0.0015*SensorValue + 0.7072)

Step 5: Future Developments

  1. Attach a external RTC (Real Time Clock). Currently, NTP (Network Time Protocol) is used to get the time for data logging. This requires WiFi and is current intensive
  2. Add push buttons to start and stop the WiFi and web server to save battery usage.
  3. Ad a GPRS module and disable WiFi. This will save power.
  4. And yes, make this project a Siphoning rain gauge (See Photo). See idea at https://www.instructables.com/id/PiSiphon-Rain-Gauge-Prototype/

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    4 Discussions

    0
    None
    ViktorJ

    Question 12 days ago on Step 3

    Hi,
    Thanks for the guide. I can't upload the sketch though, however I try. I keep getting timeout messages, while the module is plugged in and recognized on COM3.
    I have tried in ON/OFF state, pressing the boot button as you wrote, but nothing. The blue LED keeps blinking while the switch is ON and a green LED is on all the time except I guess during boot, when there's a red LED. I have the item from Aliexpress (DIY more).

    Upload settings:
    Wemos(Wifi&Bluetooth battery)
    Upload speed 115200
    CPU 80MHz
    This is what I keep getting.
    esptool.py v2.6
    Serial port COM3
    Connecting....
    Traceback (most recent call last):
    File "esptool.py", line 2959, in
    File "esptool.py", line 2952, in _main
    File "esptool.py", line 2653, in main
    File "esptool.py", line 460, in connect
    File "esptool.py", line 440, in _connect_attempt
    File "esptool.py", line 379, in sync
    File "esptool.py", line 322, in command
    File "esptool.py", line 285, in write
    File "site-packages\serial\serialwin32.py", line 323, in write
    serial.serialutil.SerialTimeoutException: Write timeout
    Failed to execute script esptool
    An error occurred while uploading the sketch

    Any ideas? Cheers!

    SOLUTION:
    Check Windows device manager if the CP2104 driver is correctly installed - if not, then just choose update driver and windows will sort it out. Then the COM port becomes available and you can upload as described.

    1 answer
    0
    None
    JJ SlabbertViktorJ

    Answer 4 days ago

    Is it possible to load any other ESP32 sketch like blink?

    0
    None
    JJ SlabbertDiver19

    Answer 24 days ago

    You are welcome to do it. I do not have any NB-IoT experience. What I do know is that it should be possible to connect a gprs module to the ESP32 and send data to the internet. I could not do it for know because I do not have a GPRS module and time . This is only my hobby and I do not do contract work. Adding a GPRS module (and disabling WiFi) may solve many of the power consumption problems the device currently have.

    If you build this instructable, please upload photos. I will apreciate.