How to build an automated DIY irrigation system controlled by an app

Patrick Hallek
6 min readJun 19, 2020

--

Author: Patrick Hallek
Support me:
Buy me a coffee

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:

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:

curl -sSL https://get.docker.com | sh
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

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:

systemctl start docker.service

Congratulations, you no longer have to water your plants by hand!

If you have installed the hardware and software correctly, you should now be able to see your first measurement data in the application.

To call up the application in your browser, you must enter the following URL: http://<RASPI_IP>:5000. Of course you have to replace <RASPI_IP> with the IP address of the Raspberry Pi.

Now you can enter under preferences in the application the signal pin to which you have connected the pump belonging to the sensor. Afterwards you should plug the capacity sensor into the ground and set a value for minimum soil moisture at which the PIN and thus the relay should be triggered. That’s it! After setting the other preferences, the pump will be activated according to the preferences you have set.

If you have several sensors connected, they are listed above as tabs. Select the appropriate tab to set and monitor all sensors individually.

3D Printed Box for the electronics

I designed and printed a magnetic box for the Raspberry Pi and the NodeMCU controller. You can download the STL files of the box here.

Help to improve the software!

I would be very grateful for any feedback you can give. Here you can set issues that might arise during the installation. I will try to solve them as soon as possible. You can also help with further development and create pull requests to improve the software. For further questions you can contact me on LinkedIn.

Thanks for reading and happy tinkering! I hope you enjoyed the article. In order to be able to continue such projects, I would be grateful for any support! Especially coffee helps me to stay focused :)

📝 Save this story in Journal.

👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.

--

--