- 2,8W Class D AmplifierPosted 7 days ago
- An Electronic LED Roulette you can self buildPosted 2 weeks ago
- An Open Source Sprinkler System powered by YúnPosted 3 weeks ago
- LED MATRIX: giant & stand-alone panelsPosted 4 weeks ago
- A 32-BIT FISHINO! WiFi, SD card, RTC, audio codec, LiPo and more…Posted 1 month ago
- A full featured mp3 DemoboardPosted 1 month ago
- A 32-BIT FISHINO board for your powerful IoT!Posted 2 months ago
- FairWind: when marine electronics, open source and the University meetPosted 2 months ago
- The Discovery of the Future: Stretchable integrated circuitPosted 2 months ago
- Robots are going to replace developers quicklyPosted 2 months ago
An Open Source Sprinkler System powered by Yún
A control unit for the garden sprinkler that can be controlled via web and smartphone thanks to Arduino Yún.
With summer approaching, our plants and our gardens need some regular watering in order to stay lush and green as we like them. It’s not easy to always remember to water plants and gardens and try to always be at home at the same time every day, so we asked ourselves, instead of taking some time every day to water plants and flowers, wouldn’t it be better to take advantage of our passion for electronics and realize an automatic system to do this for us? This is the idea at the base of the project we are going to show you in this article, which consists of a control unit for a garden sprinkler based on Arduino Yùn and a relay board that can interconnect with it. Control unit can manage a configurable number of outputs, a rain sensor and it can be programmed through a web interface reachable from any PC or smartphone connected to your home network. By adequately configuring the router where the sprinkler will be installed, you will even be able to control the system from the Internet.
But why did we employ a Yùn, instead of a common Arduino? The answer is that this allows us, thanks to its hardware which natively support wireless connections and Internet protocols, to manage the sprinkler via web and smartphone, thanks to an interface that is also designed for mobile devices.
Arduino Yún is the soul of our control unit. The project takes full advantage of the main characteristics of this Arduino, that is the possibility to simultaneously run a Linux distribution (thanks to Atheros’ System on Chip) and sketches (on the ATMega32u4 microcontroller it features). Linux operating system is in charge of managing graphic interface, memorization of programming and activation of outputs at set times, while the sketch executing on the microcontroller will take care of the interface with the external hardware: rain sensor, command panel with deviators (optional) and relay which activates the electrovalves.
The PHP pages, therefore, communicate with the sketch through the Bridge library (used for bridging the Atmega-based Arduino hardware and the Atheros SoC) while programming and events are saved in an SQLite database. Some PHP scripts are executed periodically by the crontab (the scheduler) of Linux OS and they take care of activating programming and to periodically cleanout events and log. The sketch manages the control panel, reads the status coming from the rain sensor and activates outputs (electrovalves, pumps…) through external relays.
In order for the sprinkler to be able to manage our irrigation system, we have to connect it to some external elements. To simplify these connections, we have prepared a shield that allows us to manage a system with a maximum of four electrovalves, one rain sensor and one external command panel with four switches and four status LEDs. The circuit for the shield is composed by a voltage regulator which is crucial in order to power Arduino (via Vin) and by a certain number of outputs for LEDs and outputs for managing the electrovalves, besides four inputs for the command panel’s deviators, which are optional.
PWR is the power jack connector, and it needs a continuous voltage ranging between 8 and 15 V, which is filtered by the C1 and C2 capacitors and stabilized at 5 V by the integrated regulator U1. The OUT-pin of U1 provides its 5 V in relation to GND to the left side of JP5V bridge, which is used in order to decide the power source for the system: if we want to power Arduino Yún through the shield we have to close the jumper between the central contact and the left contact (in this case 5 V come from the Schottky D1 diode), while if we want to power everything using the Yún, this has to be powered with a dedicated adapter and the jumper must be closed to the right. In this case we must not power the PWR Jack of the shield, because the shield itself is powered by the Arduino’s 5 V, also via D1. Power source notwithstanding, the 5 V’s line also powers the pull-up resistors R2, R4, R6, R8 on the outputs which are linked to deviators and R9, connected to the dedicated input for RAIN sensor. In the next pages, we are going to explain how to use the latter.
The outputs are on OUT1, OUT2, OUT3 and OUT4 (D2, 3, 4, 5 of Arduino respectively) and provide the high logic level when the electrovalves must be opened; they are designed to pilot the relay board’s accepting TTL signals and independently powering the relays’ coils.
Setting up Arduino
In order to use the sprinkler, we first have to install some software packages in Linux operating system.
Using an SSH client (you can use PuTTY on Windows, on Linux and the Mac OS you have the ssh command) we connect to the console of Arduino Yún and insert our login info (by default, root is the user and arduino is the password). We also make sure the Yún is connected to the Internet.
First, we execute the comments to refresh the list of packages available for installation, which is:
opkg is the package manager of our Linux distribution; through this command, we can install or uninstall applications and programs. In order to install the PHP interpreter (version 5) we can then input the comment opkg install php5. The package manager will download the latest version available – along with possible prerequisites – and it will install it in the figure.
We use opkg once again to install all other necessary packages for the sprinkler:
opkg install php5-cgi php5-cli php5-mod-curl php5-mod-json php5-mod-pdo php5-mod-pdo-sqlite zoneinfo-core zoneinfo-europe
We now activate the PHP interpreter in the uhttpd Web server by editing its configuration file with the command:
We have to erase the hashtag (#) at the beginning of the line relative to the .php extension as illustrated in figure.
We then press CTRL and X at the same time, then we enter Y to confirm the change. Lastly, we reboot the web server with the command:
To check if our Yún is now able to execute php pages, we can create a sample one by typing the following comments:
echo “<?=phpinfo(); ?>” >phpinfo.php
Now, if we open a browser on our computer and we enter the IP address of Arduino Yùn in the URL bar followed by /phpinfo.php, we should be able to see the info page of the php interpreter as shown in the figure.
Now we are going to download the last version of the software from the Github repository. Let’s go on https://github.com/lucadentella/irrighino and click on the Download ZIP button: after a few moments we’ll have a compressed archive on our PC with all we need to install our sprinkler.
Let’s take a microSD card and insert it in our PC; we are going to create a folder called arduino on it and, inside the folder, we are going to create a folder called www. Now we copy the website folder which can be found inside the archive we have downloaded from Github, inside the www folder; finally, we rename the website folder to sprinkler. If we did everything correctly, the microSD card will have a content similar to what is shown in the figure and we’ll be able to insert the memory card into the dedicated slot of our Arduino.
While still connected to Arduino via SSH, we type the crontab command and, in order to edit the scheduler configuration, after pressing the “I” button we input three lines, as shown in figure. We press ESC to save the configuration, then we type :wq and press ENTER. The three lines activate, every minute (* * * * *), the script that controls if there is a scheduled event to activate and once a day (from 00:05 to 00:10) the script to cleanout events and logs.
We are left with just one more step: loading the sketch contained in the Sketch folder inside the Github archive. Then, using the Arduino’s IDE, we open the sprinkler.ino sketch and we upload it on our Yún.
In order to pilot the electrovalves we have to use functioning external relays powered by 5 V and piloted by the output pins of the Arduino. To this purpose, the shield makes use of the OUT connector, with a +5 V power source, ground and four digital pins of Arduino to activate as many relays. The connector is designed to pilot the 4 relays 5vdc module. This board is equipped with 4 relays with 5 V-powered coils and exchange allowing to commute electric loads functioning with a maximum of around 240 V and absorbing up to 10 A (max); each relay is activated by bringing the command input to high logic level (from 1,6 to 5 Vcc), therefore this board is ideal in order to actuate logic signals provided by the shield, also because its power absorption, on each input, is just a few milliamps, which is compatible even with CMOS and CMOS HC logics. All the inputs on the 4-relay board are optoisolated, so that we can make a galvanic separation between the board and the command circuit, should such a need arise; in each optoisolator, the anode of the input emitter diode (1-pin) is connected to its respective input through a current limiting resistor and the cathode is common to all the LEDs’ cathodes and the other optocouplers’ and it is connected to the input COM. If you want to give up insulation, you have to make a bridge between GND and COM.
Each relay is also provided with a status LED placed on the board’s edge.
The electrovalves commonly used for garden watering systems are powered by 24 V; therefore we will need a power transformer with a “secondary” which will provide such voltage and current needed to power all the electrovalves. One of the secondary terminals will be connected to the electrovalves, and one to the relays’s common node, as shown by the diagram on this page (connections). If you have just one electrovalve, you can use the connection shown in the figure, where you can find an example of valid connection for an electrovalve piloted by a single relay board.
If electrovalves are buried in a sump, you will always have to use waterproof connectors or junction boxes (IP65).
The rain sensor is usually composed by inter-digitized contacts that are grounded and everytime it rains, water connects them thus determining a strong decrease in resistance; the sensor is connected to the RAIN input and then, when it’s dry, it lets the Arduino’s D10-pin go to logic 1, while in wet conditions, water resistance acts as a partition with R9 and D10 presents such a low voltage that it corresponds to logic zero.
Some sensors, on the other hand, work thanks to a porous material which expands when wet and pushes the lever of a microswitch, while it relieves the lever when it dries out; these sensors are very accurate and adjustable, because you can use a screw to increase or decrease the microswitch’s distance so that it could be pushed only with a certain expansion and therefore with a set water volume absorbed.
Anyway, the sensor can be directly connected to one of Arduino’s digital pins through a pull-up resistor; if you chose to use the shield we have proposed in this article, all you have to do is connect it to the terminal box labeled RAIN.
Finally, you can also equip your sprinkler with a physical control panel, in order to operate it manually without the need of a computer: the set panel is composed of a switch with three stable positions (ON, AUTO, OFF) and a status LED for each output. The switch’s position is read through an analog pin of Arduino Yún, as shown in the related box, thanks to the particular connection of two resistances allowing to obtain a voltage value for each position.
Each panel switch, therefore, is used to manually force a condition on the corresponding output and therefore in the corresponding electrovalves; this condition is signaled by the specific LED. SW1 refers to OUT1, which is status is signaled by LD1, SW2 to OUT and LD2 and so on.
If we turn the switch to ON position, the related output is activated, while if we turn it to OFF position, the output is disabled. If we leave it in an intermediate position (AUTO) the output will follow the programming set by us. The panel has higher priority than the graphic interface, therefore if we set an output OFF on the panel this will result as disabled on the graphic interface and we won’t be able to modify its state.
The shield is already equipped with the terminal boxes to which we can connect the four switches and the pins to which we can connect the LEDs: for the LEDs, you must pay attention and correctly connect anode and cathode to the pins as shown in the serigraphy (the anode normally corresponds to the longer end).
The shield is also equipped with a voltage regulator (5 V) that allows you to power every external component independently in respect to Arduino. Through the JP5V jumper, you can choose whether to use power coming from Arduino or from an external adapter (9-12 V DC) connected directly to the shield.
Using the sprinkler
Let’s see now how we can use our watering control unit in remote mode: from a PC, open your Internet browser and, in the URL bar, type in the web address http://<ip_arduino_yun>/sd/sprinkler; from that page will be able to access the control screen of our unit.
The interface is divided into three tabs: Runtime, where you have the ability to manually pilot the outputs, Setup, where you can program weekly activations, and Events, where you can view a list with the most recent events (activations, configuration edits…).
Every output can be configured in three states: ON – output is activated; OFF – output is disabled or AUTO – output follows the programming. If the output is configured using the external panel, the corresponding commands on the web interface will be disabled, the panel has, in fact, a higher priority.
Programming phase is very simple, events are gathered in a table where columns represent days of the week and the single outputs (V1…). Each row represents a 5-minute interval: by clicking on a cell you can define an activation event. You can resize and move events using your mouse (in order to modify its duration), you can also move it on another output. By clicking on an event, this is selected and you will see a darker edge around it to highlight your selection.
You can select or deselect multiple events by clicking again on them while pressing Shift.
Finally, you can delete all selected events by pressing DEL.
Customizing the sprinkler
Although the project you can download from Github is configured to work out of the box along with the shield we have realized, the sprinkler is designed to be easily customizable in order to suit any needs.
By opening the include.php file, which can be found inside the PHP folder, you can edit the number of outputs, their name and the respective color, as shown in the figure. You can also add the behavior in case of rain (immediate stop of scheduled actions and/or no new activation) or completely disable it in case your system does not include it.
Connections between Arduino and the external devices can also be customized using the sketch. All the mapping between devices and pins which devices are connected to has been defined in a specific file, called config.h, which we have reported in List 1. You can, therefore, edit the pins that are connected to relays, switches, LEDs and to the rain sensor simply by indicating within the config.h file the desired Arduino pins. Remember, in case you are going to apply other shields to Arduino besides the sprinkler’s, always check that they are not already used by the respective applications before assigning I/O’s in config.h.
Always make sure the number of configured outputs in the web interface corresponds to the number of outputs (OUT_x) defined in the sketch and also remember to update the main sketch.
Finally, if you are not going to install an external control panel you can also inhibit functions associated with manual control by putting the USE_SWITCHES constant to false.
Very well, with that said, we have finished, we really hope you enjoyed this project!