Github

Project on github : https://github.com/Thaldos/Raspberry-solenoid-valve

Prerequisites

To build this project, you’ll need:

Prerequisites

Total: 97€

Hardware

Connect your devices like this :

Hardware

Raspberry Pi installation

Installation of Raspbian

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.

Installation of PHP 7

Solution 1

On your Raspberry, open a terminal and type :

apt-get install apt-transport-https lsb-release ca-certificates

wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

echo “deb https://packages.sury.org/php/ $(lsb_release -sc) main” > /etc/apt/sources.list.d/php.list

apt-get update

apt install –no-install-recommends php7.1 libapache2-mod-php7.1 php7.1-mysql php7.1-curl php7.1-json php7.1-gd php7.1-mcrypt php7.1-msgpack php7.1-memcached php7.1-intl php7.1-sqlite3 php7.1-gmp php7.1-geoip php7.1-mbstring php7.1-redis php7.1-xml php7.1-zip

Test by typing php -v in your terminal.

An other solution if the first failed

If an error occurred, try this :

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.0 php7.0-curl php7.0-gd php7.0-fpm php7.0-cli php7.0-opcache php7.0-mbstring php7.0-xml php7.0-zip

Test by typing php -v in your terminal. You should have something like :

PHP 7.0.4-7 (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

Installation of Curl

Type in Raspberry terminal :

sudo apt-get install curl

Installation of Composer

Type in Raspberry terminal :

cd /usr/src  
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Wi-Fi autoconnecting

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.

Fixing of the Raspberry pi IP

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.

Installation of VNC server on the Raspberry

To easily access to your Raspberry every time, you should install VNC. You have to install VNC server on your Raspberry and VNC viewer on you desktop. Follow this good tutorial:

https://www.raspberrypi.org/forums/viewtopic.php?t=123457

Installation of VNC viewer on your desktop

https://www.realvnc.com/en/connect/download/viewer/

Launch VNC viewer and add a new connection to 192.168.1.201:1

Important note: be sure te be on same Wi-Fi network on both sides.

Project installation

Setting of the project files on your Raspberry pi

Copy all this project files to your Raspberry in /home/pi/Raspberry-solenoid-valve/.

Customization

Customize the constants in the config.php file.

Download of the the library vendors

Then type in Raspberry terminal :

cd /home/pi/Raspberry-solenoid-valve/library 
composer install

Setting of the cron tab

On your Raspberry, in terminal, type crontab -e and add that line:

0 23 * * * sudo php /home/pi/Raspberry-solenoid-valve/openthenclosethevalve.php 2>&1

Enjoy!

Your Raspberry Pi will open every day at 23pm the valve during the appropriate delay, then will close it.