Переключить тему.

Automatic plant watering and collecting soil moisture data, a simple device.

30 Sep 2023

На Русском
[This is the translation of my original post. Please excuse me for any grammatical errors. English is not my native language.]

This is the device I build myself by using electronic components. This is my hobby project. Device checks soil moisture once an hour and if moisture less than 20% pours 300 ml of water to the plant tray. Device also sends soil moisture data to MQTT server via WiFi. Device works autonomously, device is powered by using small sollar pannel and accumulator.

If you interested, I published all project files in github repository: https://github.com/BigIskander/PlantWatering/tree/main

Collecting data and monitoring soil moisture.

After I build the device, I collected data during the perion of three months. All this time device worked autonomously (i.e. without using external power source). Accumulator slightly charged from sollar pannel during day time and slightly discharged during night time.

At the beginning, the purpose was: to determine the soil moisture level, in which it will be better to water the plant. For that reason at the beginnig the watering function of the device was disabled and I just monitored the data sent by the device. In that period, I watered the plant manually when needed. Then, by analysing collected data (graphs of soil moisture changes), I decided that, it will be the best if I will water the plant when the moisture level drops below 20%. That way, after prelininary observation, the device was programmed to water the plant (i.e. pour 300 ml of water) if soil moisture drops below 20%. After that I continued observations.

The plant was only watered to plant tray (for all the period of observation).

The data was collected this way: 1) device once an hour via WiFi sent data to MQTT server; 2) program in my computer minitored messages from MQTT server and write them to log file.

Then the data from log file was processed and displayed in easier to understand fomat (like graphs).

Observation results.

Below is the graphs of soil moisture [Влажность почвы] and voltage levels (on the battery) [Напряжение]. The graphs build based on observations for the time period of 3 months (2327 observations). Small red squares [Полив] denominates time points when the plant was automatically watered by the device.

Soil moisture level plot for the period of 3 months.

Voltage level plot for the period of 3 months.

For better clarity, below is the graphs built based on observation period of 1 week.

Soil moisture level plot for the period of one week.

Voltage level plot for the period of 3 months.

On the graphs you can see how soil moisture and battery voltage changes depending from the time of day. In hot days, after watering the plant, soil moisture rised pretty slowly. For that reason some days the device watered the plant twice with time break of 1 hour.

About MQTT server.

MQTT server was used to collect the data from the device. MQTT is the protocol used to send the data between smart devices. For this project I used MQTT server provided by service https://www.wqtt.ru. If you want, you can use any similar service or set up your own local MQTT server (in case you have appropriate scills).

On MQTT server, 3 topics was created:

  • voltage - voltage of the battery
  • moisture - soil moisture level
  • water - watering (0 - plant was not watered, 1 - plant was watered)

The feature of MQTT technology is that MQTT server gets data from devices and send this data to subscribed (to these messages) devices, MQTT server usually do not store this messages. Server can only retain the last message in the topic if this message was sent with parameter retain equal to true. For that reason, I used script written in python (https://www.python.org). This script was monitoring messages from MQTT server and saving them to separate file on the computer.

To process saved MQTT messages and present collected data in more easy to read way I write a small program working inside jupyter notebook https://jupyter.org.

Script used to collect the data and small programm used to process collected data:
https://github.com/BigIskander/PlantWatering/tree/main/MQTT_Data

In order to use this script (and to collect data) you need to write MQTT server credentials in file credentials.py.

To watch messages from MQTT server in real time I used MQTT Explorer program http://mqtt-explorer.com. Unfortunatelly this program can’t export data and to save (collected data), i.e. the data is only available inside the program until you close it.

Circuit diagram.

Electronic components:

  • U1 - Wemos D1 mini (microcontroller)
  • U2 - Capacitive soil moisture sensor V1.2 (built on NE555 chip)
  • U3 - 5V DC motor (submersible water pump)
  • U4 - 1 watt small solar pannel
  • U5 - push button switch
  • U6 - battery charge indicator
  • J1 - battery charger module 03962A
  • J2 - 18650 Li-Ion battery
  • R1, R2, R3, R4, R5 - 10K Ohm resistors
  • C1 - 16V 100µF capacitor
  • T1, T2, T3, T4, T5 - FQP30N06 MOSFET transistors
  • + prototyping board and wires with diameter 24 AWG

Circuit diagram of the device.

Recommendations on how to build the device and write programm in to microcontroller.

For more comfort (while building the device) it is better to prepare well lit place, it is necessary to better see small details, because some components quite small in size. I would recommend to use soldering iron with adjustable temperature and good solder, because electronic components can get broke if you overheat them while soldering.

You need to write programm in to mictocontroller before you connect it to the board, because if someting is connected to microcontroller program can not be written to mictocontroller.

To write the program in to the mictocontroller I used Arduino IDE (https://www.arduino.cc/en/software). The program for microcontroller was written in C++ programming language. Before writing programm in to the mictocontroller you need to write credentias (used to connect to WiFi and MQTT server) in credentials.hpp file. If you want you can modify the device and the programm.

Programm for the microcontroller:
https://github.com/BigIskander/PlantWatering/tree/main/PlantWatering

Some technical details.

Most electronic components was bought from these internet stores: https://amperka.ru , https://mcustore.ru and https://aliexpress.ru. Flexible tube for watering was bought from https://www.ozon.ru. Some part I already had at home.

The device is build by using Wemos D1 mini microcontroller. This is the microcontroller using small amount of electricity. However, the battery still won’t last long if microcontroller will be active all the time. For that reason, in order to decreasy electricity consumption, the microntroller was programmed so that in time periods between measurements it will be in deep sleep mode (that is the mode when the electricity consumption of the device is minimal).

In order to measure soil moisture Capacitive soil moisture sensor V1.2 was used. This is the analog sensor, the voltage on the output pin depends from soil moisture. Unfortunatele the voltage on the output pin also depends from voltage of power source used to power the sensor. In order to acoont for this feature, I needed some method to measure the voltage on the power source.

The difficulty was that selected microcontroller only have one analog pin, which can measure voltage in range from 0 to 3.3 volt, and I need to measure voltage from two sources. Also 18650 Li-Ion accumulator voltage (which is also necessary to measure) is usually in range from 3.7 to 4.2 volts, this is beyond the measurement range of 3.3 volt maximum. For that reason, in order to consecuently measure voltage from two sources I bult circuit by using transistors, to measure the voltage of accumutor (battery) I built voltage divider circuit.

After the device was built, I made a calibrations. I measured values when the sensor is dry (0% moisture) and when sensor is in water (100% moisture). I measured values for different voltage levels (of power source). Then, based on measurements, I wrote a formula which will be used by programm (in microcontroller) to calculate soil moisture level.

In practice, the device first measures the voltage level of the power source (accumulator), then measures the voltage level in out pin of soil moisture sensor. Then calculates soil moisture level and if soil moisture less than 20%, pours 300 ml of water (in the plant tray). After that the device via WiFi sends data to MQTT server. After the data was sent the device switches to deep sleep mode for 1 hour and after 1 hour the cycle repeats.

The amount of water to pour for one watering was decidend depending on volume of plant tray. I decided that in my case 300 ml of water will be appropriate amount to water the plant. If you want you can change the amount of water used for watering inside the programm.

In order to determine how long the pump needs to be on to pour necessary amount of water, at first I measured the amout of water which pump pumps in time period of 10 second. Then based on that I calculated how much secons pump needs in order to pour necessary omount of water and programmed microcontroller so that when watering will be need the pump will be turned on for set amount of secons and then turned off.

Photos of the device:

Photo of the divice.
Photo of the divice.
Photo of the divice.
Photo of the divice.
Photo of the divice.

Video demonstration of device working (watering the plant):

На верх!
Close. Open image in new tab.