How to build an automated DIY irrigation system controlled by an app
By: Patrick Hallek
Tags: Smart Home, Irrigation, Watering, Automated, DIY

In this article I will show you how to build an affordable automated irrigation system so you no longer have to water your plants by hand. The system can be used for house plants, raised beds, but also for plants in the garden or larger green areas, because the number of connected plants is scalable.

Here, the decision as to when to irrigate is not made according to a timer, but rather the soil moisture is measured directly and a decision is made on the basis of this whether irrigation is necessary or not.

Want to read this story later? Save it in Journal.

The system has the following features, which can be controlled via the web app:

Monitor and display time series data at the minute, hour, day, week and month levels

Setting the water level from which automatic watering should be triggered

Setting how long the pump works during an irrigation

Manual activation of irrigation with a button

Switching between different sensor profiles

Switching between dark and light theme

Part List

Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.

The “n” in the amount is due to the number of pumps or different plants. For example, in a raised bed it is usually sufficient to have one pump and one sensor. However, if you have different potted plants, they all need to be watered separately and therefor you have to get one pump and sensor for each potted plant.

Hardware Architecture

To measure the soil moisture, the NodeMCU ESP8266 microcontrollers read the analog signals of the capacitive sensors. The filtered and interpolated measured values are then sent through your local network to the Raspberry Pi. This is where you decide whether or not to trigger the relay associated with the sensor. When the relay is opened, the circuit to the pump is closed and the plants get watered.

The architecture was chosen so that pump logic and recording of measurement data is separate. This makes it possible to control up to 26 pumps with the Raspberry Pi (amount of default available GPIO pins). It is also not possible to read the analog signals of the capacitive sensor with the Raspberry itself, because the Raspberry can only process digital signals. Surely it is possible to read the sensors with an MCP3008 and the serial interface, but this requires more pins and the setup is not as clean as it used to be. The pumps are also separately connected to a power supply, whose circuit is controlled by the relay. So it is also possible to use 12V or higher pumps.

Software Architecture

For the software architecture the MERN Stack was used. The software consists of a Node.js backend with Express.js, a Mongo database and a React frontend. A C++ script runs on the NodeMCU ESP8266, which sends data to the REST interface of the backend. The data is processed in the backend, where it is decided whether to irrigate or not. In addition, the data is then stored in the MongoDB. With the frontend, this data can also be requested from the backend via REST.

Setup the NodeMCU ESP8266

To record the measurement data of the sensors with the NodeMCU, you must first install the software. In order to flash the NodeMCU microcontroller you have to follow the steps described in this video.

Before you upload the program you have to set your wifi password, wifi name (ssid), the ip of the raspberry pi (host) and the sensor name (this name need to be unique!). The sensor name will be the name that is displayed in the app. So it’s best to choose the name of the plant the sensor should be associated with.

If the Arduino IDE is successfully configured for the NodeMCU, you can upload the program you find in this repository under arduino-code/ESP8266_moisture/ESP8266_moisture.ino to the NodeMCU.

Installing the project on the Raspberry Pi

First you have to download the software on your Raspberry pi. You can find the source code on GitHub. The following command downloads the repository onto the Raspberry Pi:



cd automated-irrigation-system git clone https://github.com/PatrickHallek/automated-irrigation-system.git cd automated-irrigation-system

To avoid having to install the required programs manually, you can also run the application with Docker in containers. To do this, carry out the following steps:



sudo usermod -aG docker pi

sudo apt-get install -y libffi-dev libssl-dev

sudo apt-get install -y python3 python3-pip

sudo apt-get remove python-configparser

sudo pip3 install docker-compose curl -sSL https://get.docker.com | shsudo usermod -aG docker pisudo apt-get install -y libffi-dev libssl-devsudo apt-get install -y python3 python3-pipsudo apt-get remove python-configparsersudo pip3 install docker-compose

Now you have to pass the ip address of your pi into the REACT_APP_BACKEND_URL=http://<YOUR-RASPI-IP>:3000 environment variable in the docker-compose file:

sudo nano docker-compose.yml

You can find the ip with the command ifconfig . It should be something like 192.168.178.44. You can save your input in the Nano editor with ctr + x , then type in yes , finally exit with enter .

Now everything should be ready and you can start the application with the following command:

sudo docker-compose up

Attention: If you have a Raspberry Pi with a processor other than ARMv6, you need to adjust the image for the mongodb in the docker-compose file. Since the version of the image is only suitable for this type of processor.

To run the software at startup, you can execute the following command: