Project:Plant Watering

From CoMakingSpace Wiki

Disclaimer: This page is work in progress! Right now, it is more or less a notepad for Martin.


Automated Plant Watering

Plantmonitoring RackTest.jpg
Status: in progress (since a looong time now)
Release Date: Most likely during dinner at the Milliways...
Initiator: Martin
Materials Used: Wood,Microcontroller
Software Used: Home Assistant

As many others, Martin is quite lazy. Unfortunately, he also likes to have fresh herbs and other plants on his balcony.

Since this combination led to many dead plants, it was pretty clear that there needs to be some automated solution for this.

Vertical Farming

On a normal balcony, space is a very limited resource. Therefore, a solution was needed which allows to make use of vertical space rather than using up a lot of horizontal space.

In addition, it should be possible to build it from standard components which you can get from your local hardware store.

Using jardinieres which are arranged on top of each other with a self-built rack was the perfect solution for this.
In my case, I am using 4 jardinieres to grow plants in and a 5th one on top which is just being used to store water (see the project picture)

Supplying Water

In a first tests of the system, I thought using water pumps would be a good idea. Therefore, I got these 12V pumps and tested them. While they worked, they were pretty loud, so there would need to be logic which prevents the system from watering during night hours. Therefore, a more silent system was needed.

When thinking of how to achieve this, the idea of vertical farming came up, which allows the water storage to be the highest point of the system. With this, I can just use valves and let gravity do the work (isn´t gravity awesome?). I found some random 12V magnetic valves in the internet which I got for my system. Unfortunately, I cannot find them anymore.

Soil Moisture Sensor

In order to control the whole system, sensors are needed which are able to measure the soil moisture in a reliable way. If you want to measure soil moisture, there are in general two ways:

Resistive Measurement

Resistive measurement of soil moisture is a very easy thing. In principle, you put two electrodes into the soil, put power on one of them and measure how much power arrives at the second one.

With this, you have a very basic measurement of the soils resistance. The more power arrives at the second electrode (and thus the lower resistance), the more water is in the soil.

There are very cheap sensors which can measure the moisture this way.

The "controller" board they come with is capable of either providing the analogue value or provide a digital value which indicates the moisture to be above/below a certain threshold (adjustable by a potentiometer).

While these sensors provide you with correct values, they have a big disadvantage which is unfortunately in their underlying priciple: The electrodes need have direct contact to the soil. Applying power to the electrodes leads to corrosion, which leads to the sensor not working anymore. While this would not be super critical (you could just get a new one, since they are so cheap), most of these electrodes consist of cupper. The cupper will make its way into the soil and thus into the plants. Since we are talking about herbs and other plants I am planning to eat, this is pretty bad.

Capacitive Measurement

Another possibility of measuring soil moisture is capacitive measurement. Basically you are measuring the capacitance of a capacitor consisting of your sensor and the soil. A more detailed explanation can be found here.

The big benefit of these sensors is that there is no corrosion. Therefore, there is no danger for the plants and the health of the person eating them.

When this project started (in 2014), these sensors were quire expensive. However, in the meantime they got a lot cheaper and are not much more expensive than the resistive ones. I am using these ones, which provide the moisture level as an analogue voltage. Dependent on the microcontroller / computer they get attached to, an analogue-digital-converter (ADC) might be needed in order to read them (the raspberry pi has no ADC, the ESP8266 has 1, but can only handle up to 1V input, the ESP32 has two ADC with multiple channels being able to get 3 volt input (though you cannot use the second ADC when Wifi is on..... )).

System Architecture Decision

As most projects, there are different possibilities in regards of the system architecture. These can mainly be differentiated by the integration with other automation projects and the degree of flexibility. Of course, the different possibilities require different implementation efforts.

Microcontroller Side

Description Pro Con
Microcontroller Only This means the microcontroller has to do everything: read the moisture, decide on when to water
  • No Server needed -> no single point of failure
  • Code Adjustments needed for each plant
  • No History
  • No remote control (e.g. water now)
Microcontroller plus central server Dumb microcontroller Microcontroller would just read the moisture, send it to the server, "business logic" on the server decides on watering time
  • No code adjustments needed
  • Logic adjustments could be done centrally
  • History available
  • Server controls everything --> single point of failure
"Smart" microcontroller Microcontroller would get config from the server, then read the moisture and decide on watering time itself. Server could be used for analytical purposes
  • No Server needed for core functionality --> No SPoF
  • No code adjustments needed
  • History could be available
  • Possibility for persistent storage of config needed

Server Side

Option Details Description Pro Con
Custom Server development Custom software which contains the business logic regarding when to water the plant. High level of DIY and flexibility, but also high effort (dev and maintenance)
  • Cool project
  • Quite some effort
Standard server Software OpenHab Less DIY, but more integrated with other automation projects. Are analytical features provided out of the box?
  • Less error prone
  • Software could be used for home automation in general
  • Most likely more resource intense than custom software
  • Less cool
  • Python
  • Very active development
  • Lots of other integrations available
  • No Version 1 yet

For this project, Martin decided to go for a smart microcontroller, which uses HomeAssistant as a server.

Software Setup

Since the decision on the server side was to use Home Assistant, the microcontroller can run ESP Home. ESP Home automatically creates a PlatformIO project based on a configuration file. As an example, the config file for this project looks as follows:

  name: test_platform_1
  platform: ESP32
  board: nodemcu-32s

  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Enable logging

# Enable Home Assistant API

  - platform: adc
    pin: GPIO36
    name: "Plant1"
    update_interval: 1s
    attenuation: 11db 
  - platform: adc
    pin: GPIO39
    name: "Plant2"
    update_interval: 1s
    attenuation: 11db 
  - platform: adc
    pin: GPIO34
    name: "Plant3"
    update_interval: 1s
    attenuation: 11db 
  - platform: adc
    pin: GPIO35
    name: "Plant4"
    update_interval: 1s
    attenuation: 11db 

  - platform: gpio
    pin: GPIO2
    name: "GPIO2 Switch"