• Stars
    star
    595
  • Rank 75,217 (Top 2 %)
  • Language
    JavaScript
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is the software of an open source automated irrigation system. The complete setup including hardware can be found in the README.

License: MIT PRs welcome!

Automated irrigation system

This is an open source application to water plants automatically. Up to now there is almost no free professional software and instructions available to build a DYI irrigation that is scalable, accurate and most importantly, durable. The app is also not only there to look good and for the love of data. Above all, it is a tool to tailor the sensors to the exact needs of the plants. This is where most irrigation systems with direct soil moisture measurement fail because every soil and plant is different and therefore manual calibration and possibly after some time also recalibration is essential.

The app contains the following features:

  • 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
App dark themed App light themed
App dark themed App light themed

Table of contents

  1. Part list
  2. Hardware Architecture
  3. Software Architecture
  4. Setup NodeMCU ESP8266
  5. Setup the Raspberry Pi with Docker (recommended)
  6. Setup the Raspberry Pi manually
  7. Usage
  8. Contributing
  9. License

Part list

Name Anmount Description
CHEAP ALL IN ONE OFFER 1 - n pump, tube, capacity sensor and relay
NodeMCU ESP8266 1 - n Wifi module for reading capacities and sending them to the backend (Raspi)
Raspberry Pi Zero 1 Running the whole software and triggering the pump(s)
Raspberry Pi SD Card 1 This is the data memory for the raspberry pi
Relay 1 - n To close or open the pump circuit on signal from the raspi
Capacitive Soil Moisture Sensors 1-n To measure the soil moisture. Capacitive sensors do not dissolve. Never use electrodical humidity sensors, as they wear out very quickly
Pump 1 - n Theoretically any pump can be used, as it is controlled by a separate power supply and the relay
Aquarium tube and irrigation nozzles - Water transfer to the plants and to distribute the water on the earth

*all product links are also affiliate links to exactly the same products I bought for the system. If you order via the link, I will receive a tiny commission.

The "n" in the anmount 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

Hardware Architecture

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

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 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. 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.

Setup the Raspberry Pi with Docker (recommended)

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 ARMv7, you need to adjust the image for the mongodb in the docker-compose file. Since this is only suitable for ARMv6.

Setup the Raspberry Pi manually

To set everything up we first have to burn an image to the SD card and connect to the Raspberry pi via an ssh connection. Follow this video to perform these steps.

After everything has worked out, connect to the raspberry pi and take the next steps

Installing Node

Node.js is an open source server environment with which we developed the backend and thus the logic for automated irrigation. The backend is the heart of the application and connects the sensor data, user interface, database and hardware (relay to the pump).

Execute the following commands on the raspi in oder to install Node:

wget https://nodejs.org/dist/v11.9.0/node-v11.9.0-linux-armv6l.tar.gz
tar -xvf node-v11.9.0-linux-armv6l.tar.gz
cd node-v11.9.0-linux-armv6l
sudo cp -R * /usr/local/

That the installation has worked can be checked with the two commands for version query of Node.js and NPM:

node -v
npm -v

Installing MongoDB

MongoDB is a universal, document-based, distributed noSQL database where we will store our settings and time series data.

Execute the following commands on the raspi in oder to install MongoDB:

sudo apt update
sudo apt upgrade

sudo apt install mongodb

sudo systemctl enable mongodb
sudo systemctl start mongodb

That the installation has worked can be checked with the command below:

mongo

Installing the Project

Download the project from this repository with the following command and go in the project directory:

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

After downloading the project you have to create environment files for the frontend and backend with the following commands:

sudo nano .env

If you are in nano edit mode, copy the following text into it and type in your raspi ip. You can find the ip with the command ifconfig. It should be something like 192.168.178.44

SKIP_PREFLIGHT_CHECK=true
PORT=4200
REACT_APP_BACKEND_URL="http://<YOUR-RASPI-IP>:3000"

You can save your input in the Nano editor with ctr + x, then type in yes, finally exit with enter.

We need to do the same for the backend environment:

sudo nano backend/.env

Copy the following line into the editor in order to set the database connection:

MONGO_DB="mongodb://localhost/irrigation"

In order to install all dependencies in the frontend and backend, you need to run the following

npm install
cd backend
npm install

If everything is installed, you are able to start the frontend and backend separately

npm run build
npm start &
cd backend 
npm start &

Usage

The frontend can be accessed at the following URL if you are in your home wifi network: http://<RASPI_IP>:5000

In order to get the Raspberry Pi IP-address, execute ifconfig on the Raspi. If everything worked out fine, you should see the measurements in the Last Minute view in the statistics and the default preferences (which do not equal to 0).

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT