Water the garden with a Raspberry pi
You'll need:
- (1) Raspberry power supply (5V 2.5A) (8€)
- (2) Raspberry Pi 3 model B (35€)
- Raspberry case + heat sink (7€)
- (3) Relay board 5V - 220V (2€)
- (4) Relay board 220V - 220V (21€)
- SD card 16 Go (11€)
- (5) Vertical Tank Water Level Sensor (7€)
- (6) Water tank (60€)
- (7) Pump (60€)
- (8) Solenoid valve (12V 2A AC) (24€)
- Solenoid valve power supply 12V 2A AC (9€)
- Patience and passion (prices not yet available)
Total: 244€
Connect your devices like this:
Download the NOOBS OS : https://downloads.raspberrypi.org/NOOBS_latest
Extract the archive.
Copy past the files on your SD cart.
Insert the SD cart in your Raspberry Pi and start it.
Follow the installations steps.
nano /etc/apt/sources.list
Uncomment the line :
deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
apt-get update
apt-get install -t stretch php7.3 php7.3-curl php7.3-gd php7.3-fpm php7.3-cli php7.3-opcache php7.3-mbstring php7.3-xml php7.3-zip
Test by typing php -v
in your terminal. You should have something like :
PHP 7.3.16 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
Type in Raspberry terminal :
sudo apt-get install curl
Type in Raspberry terminal :
cd /usr/src
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Type in your terminal :
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
And append some thing like :
network={
ssid="Livebox-12345"
psk="123456789AZERTY"
}
Now when you will restart your Raspberry, it will automatically connects to this network.
Type in Raspberry terminal : sudo nano /etc/network/interfaces
and append this :
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Then type in Raspberry terminal sudo nano /etc/dhcpcd.conf
and append this :
# Configuration ip fix wlan :
interface wlan0
static ip_address=192.168.1.201/24 #replace 201 by your wish
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
More details on this step here (French link)
Check if your IP address is set well:
-
Reboot then check your local IP :
hostname -I
-
Reboot again and re-check your local IP
It should be the same.
To easily access to your Raspberry every time, you should use VNC. You have to enable VNC server on your Raspberry and install VNC viewer on you desktop.
Menu > Preference > Raspberry configuration > Interfaces > Enable VNC
https://www.realvnc.com/en/connect/download/viewer/
Launch VNC viewer and add a new connection to 192.168.1.201
, with the user pi
and password raspberry
.
Important note: be sure te be on same Wi-Fi network on both sides.
Follow this good tutorial:
https://hotfirenet.com/blog/1704-envoyer-mail-depuis-le-raspberry-pi/ (French link)
If, like me, you use gmail, this is a good configuration :
hostname=anexistingwebdomain.com
root=monLogin@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=monLogin@gmail.com
AuthPass=monbeauPaSsWoRd
FromLineOverride=YES
UseSTARTTLS=YES
Copy all this project files to your Raspberry in /home/pi/Raspberry-water-the-garden/
by typing :
cd /home/pi/
git clone https://github.com/Thaldos/Raspberry-water-the-garden.git
Copy .env.dist
to .env
and customize the constants in the .env
file as your wish.
Then type in Raspberry terminal :
cd /home/pi/Raspberry-water-the-garden/
composer install
On your Raspberry, in terminal, type crontab -e
and add the lines:
0 15 * * * sudo php /home/pi/Raspberry-water-the-garden/storecurrenttemperature.php 2>&1
0 23 * * * sudo php /home/pi/Raspberry-water-the-garden/waterthegarden.php 2>&1
Your Raspberry pi will check every day at 23pm if your garden need to be watered, and if it is needed, the Raspberry will water your garden during the appropriate delay.
You can run manually the watering by typing in your Rapsberry Pi terminal :
sudo php /home/pi/Raspberry-water-the-garden/waterthegarden.php now
The garden will be watered during the delay defined by DELAY_MIN
in .env
.
You can reset the relay by typing in your Rapsberry Pi terminal :
sudo php /home/pi/Raspberry-water-the-garden/waterthegarden.php reset
Special thanks to my lovely wife for the logic contained in the function getDelayForWatering($temperature)
.