AaronMillOro / RPirrigo

watering system based on python using a RPi 3b+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RPirrigo - automated watering system

The motivation for this project was to put a Raspberry Pi in action in order to water the plants of my appartment. This with the aim to guarantee their survival during the summer break.

The developed system triggers two peristaltic pumps during a given period of time (seconds), mainly to control the amount of water. Then, the Pi camera module is activated and takes a picture of the plants. Enventually, an email is sent with the lastest picture recorded. At each action, a log file stores the different actions of the program.

This project has two main blocs: the hardware elecronics and the software logic.

Hardware

The reauired elements were:

  • Raspberry Pi 3b+ (RPi)
  • Two peristaltic pumps operated at 12 V
  • Power source of 12 V DC
  • A 2-channel relay module of 5V (very important to be triggered at 5 V)
  • Plastic tubes of 4 and 7 mm internal and external diameter, respectively
  • Simple aquarium air regulators to control the water flow
  • One gallon container to keep the water reservoir
  • Cables
  • (optional) Pi camera module 5M
  • (optional) Wood box to attach the elements, in this case a used a Porto wine box

Below the distribution of the GPIOs of the RPi model 3b+. For this project, I connected the following pins:

  • #2 (5 V) to power the relay
  • #4 to the ground of the relay
  • #16 and #32 to trigger the signals for the pumps

RPi 3b+ GPIO distribution

General Purpose Inputs/Outputs (GPIO) distribution of the RPi model 3b+

The circuits connections are detailed in the following picture.

hardware circuits

Connection of the RPi components with the relay, the peristaltic pumps and the Pi cam

pumps and Pi cam attached to a Porto wine wood box

Software

The logic was implement on python 3.8. The application requires the packages indicated on this file.

pip install -r requirements.txt

In addition, a directory named img/ must be created at the same level of the directory src/. The snapshots will be stored on that directory.

user@pc:~/RPirrigo$ ls

img  README.md  requirements.txt  src

Sensitive data

For the correct performance of the main script, a .env file should be placed on the src/ directory and should contain the following environment variables.

PORT = Number of port indicated by the SMTP server
SMTP_SERVER = SMTP server
SENDER_EMAIL = Email of the sender
RECEIVER_EMAIL = Email of the recipient
PASS = Password to access the SMTP server
IMG_DIR = Directory to store the cam images
LOGS = "/file.log"

Running the application

The following command runs the application on a terminal.

python3 watering.py

Alternatively, there is the possibility to run the application automatically at startup of the RPi. To do so, a cron task should be declared on a terminal by typing:

crontab -e

Then, add the following line at the end of the file. It is really important the last "&" for the correct functionning of the RPi.

@reboot cd /path/to/RPirrigo/src && python3 watering.py &

After reboot the following command allows to verify the declared cron task.

systemctl status cron

watering system in action

System in action

Enjoy! :shipit:

About

watering system based on python using a RPi 3b+


Languages

Language:Python 100.0%