phone or tablet with operating systems Android 4 and above. Reactions and .... UART communication [23]. .... Android application uses custom scripts for loading.
Implementation of Microcontroller Arduino in Irrigation System Štefan Koprda(&), Martin Magdin, and Michal Munk Faculty of Natural Sciences, Department of Computer Science, Constantine the Philosopher University in Nitra, Tr. a. Hlinku 1, 949 74 Nitra, Slovakia {skoprda,mmagdin,mmunk}@ukf.sk
Abstract. The aim of this article is the design and implementation of intelligent irrigation devices using the Arduino microcontroller. The control interface of the irrigation system was created as a mobile application. The currently existing various similar solutions are all from the perspective of money unprofitable. The present solution is very cheap and effective especially for home usage. Following the extension it can also be applied on a larger scale e.g. for buildings greenhouse, intelligent garden and others. We used these hardware components for realization: the microcontroller Arduino Yun, real-time clock DS1302, two humidity sensors, relays and solenoid valves. The application for controlling irrigation device using mobile technology was created in the programming language Java. This easy smart irrigation system can be controlled by smartphone or tablet with operating systems Android 4 and above. Reactions and all functions of proposed intelligent system were verified with statistical surveyes. The results were evaluated by using technics of explorating analysis and non parametric Levene’s test. By analysis we can determine the reliability of the irrigation equipment and so clarify the behavior of the system for the existence of systematic and random errors. Keywords: Automatization Intelligent system Arduino YUN PHP Java Reliability evaluation
1 Introduction All human beings, animals and plants need water for survival. It is one of the basic needs for everyone. Most of the agriculture systems face water wastage as the major problem [1]. Agriculture, “The backbone of Indian economy” as quoted by MK Gandhi is defined as an integrated system of techniques to control the growth and harvesting of animal and vegetables. This statement is true and they should take an example from it and other countries [2]. Today agriculture uses for irrigation purposes 85 % of water [1]. Monitoring soil water content at high spatio-temporal resolution and coupled to other sensor data is crucial for applications oriented towards water sustainability in agriculture, such as precision irrigation or phenotyping root traits for drought tolerance [3]. The paper [4] shows that there are some technologies that benefit both farmers and the industry. ICT has certainly had a big impact on agriculture. One example that shows the successful use © Springer International Publishing Switzerland 2016 D.-S. Huang et al. (Eds.): ICIC 2016, Part I, LNCS 9771, pp. 133–144, 2016. DOI: 10.1007/978-3-319-42291-6_13
134
Š. Koprda et al.
of ICT in agriculture are mobile telephones, in currently – smartphones [5]. This has been used to access information on weather and many other aspects. According to the work [6], ICT provide farmers with the opportunities for communication with other farmers, or options controlling their production. In current development and implementation of ICT in the form of mobile devices, more of them support greater processing power, more vivid display, and higher efficient information collecting method, which enhances interaction possibilities between human and machines. This technology can be used not only as consumer electronics products, but also considered as great assistants in the industry area. These products are then part of intelligent systems. A number of local studies [7–9] have agreed with findings by [4] which accentuated on factors such as education, negative perceptions, lack of capital, small land areas, ineffective infrastructure facilities, and limited capacity of extension workers as the main drivers that led to low technology adoption. Therefore we in this paper propose a design for home automation system using ready-to-use, cost effective and energy efficient devices including Arduino microcontrollers, and relay boards. Today we are living in 21st century where automation is playing important role in human life. Automation allows us to control appliances using automatic control. It not only provides comfort but also reduces energy, efficiency and time saving [10]. The requirement of building an automation system for an office or home is increasing day-by-day. Industrialist and researchers are working to build efficient and economic automatic systems to control different machines like lights, fans, air conditioners based on the requirement. Automation makes an efficient use of the electricity and water and reduces much of the wastage. Drip irrigation system makes the efficient use of water and fertilizer. Water is slowly dripped to the roots of the plants through narrow tubes and valves.
2 Automatic Irrigation System Using Arduino and OS Android The concept of intelligent system is often used in research literature and popularizing magazines. Realization of intelligent systems is a complicated task [11, 12]. Main problems is monitoring of measured variables, static values as well as dynamic processes with different Dynamics [13]. Each variable has the ability to detune the character of the measured system and thereby put the system in a constant regulatory process or even non-controllable state [14–18]. In this paper we want point out the creation of a smart irrigation system, which creates one of the research areas of intelligent systems. Determining factors in the development of the concept of a higher level of automatization intelligent systems (similarly as in industrial processes) are: properties of object control, properties of information, control and communication systems, aims of control and optimization [19]. This simple irrigation system allows the user to control irrigation in the home. The system is fully controlled using online interface and requires an active internet connection. In case of failure of internet connections, irrigation system works on the basis of the previously saved settings. Irrigation system consists of several modules, which can be divided into three parts: Control part, Regulation part and Server part. The
Implementation of Microcontroller Arduino in Irrigation System
135
control part consists of an Android application which is the front end of the complete irrigation system and can be implemented on any smartphone or tablet with OS Android 4.0.3 or higher. The regulation part consists of hardware elements, where the basis is the core of microcontroller Arduino Yun and ensures switching solenoid valves according to the requirements coming from the control unit. The server part is used as an interface between the control and regulation part, thus allowing communication across the Internet without the need for IP public addresses (or in case if the regulation part at some has been part of the local network).
3 Regulation Part of Smart Irrigation System The regulation part of the irrigation system includes a description of the hardware design as the design and programming of software part. Module of regulation part is responsible for the correct interpretation of the values which are contained in the database, processing and representation at the physical layer. It consists of the control electronics and power electrical parts [20] (Fig. 1). The core of the regulation module is a microcontroller Arduino Yun, which is based
Fig. 1. Control irrigation system
on the chip ATmega32U4 and processor Atheros AR9331. Arduino is ideal for similar types of non-industrial automation [21, 22]. Primarily its modularity and sophistication facilitates the design and implementation of the final solution [18]. Arduino requires a supply voltage of 7–12 V (or 5 V in case of programming via USB) for it to run properly. USB also serves as a means for transmitting information to the terminal via UART communication [23]. Processor Atheros supports Linux distribution based on OpenWrt called as OpenWrt-Yun.
136
Š. Koprda et al.
4 Concept of Communications In design of the concept of communication, we have taken into account the requirements that have been required for realization of ideal irrigation system. The main requirement is wirelessly control of irrigation system, not only from local network, but virtually anywhere on Earth, in case if a smartphone (as control unit) has available internet connections. For this reason we designed for the solution Client-Server-Client. The microcontroller Arduino and the smartphone represent in this case clients who are connecting to a central server. This style of communication is a slightly complex but brings us benefit, if we want to create multiple irrigation systems for households, greenhouse and other. Data would be stored not only in irrigation units but also in the central database. The following figure shows the communication between microcontroller Arduino and OS Linux (first client), web server and Android application (second client). When communicating, the Linux OS sends queries in the time interval of 5 s to the Web server. In the case that in the database has been a change, it gets a response in the form of list of changes. Consequently, is realized a synchronization of the local database with the database on the Web server. Microcontroller Arduino in periodically intervals measures the current humidity and sends this data to the database on the server in time interval, which is stored in the settings. Microcontroller Arduino sends a per second request to local database and reads the current state of manual and planned irrigation and evaluates which irrigation loop is on or off. An Android application is used for creating an irrigation plan and entering commands for irrigation unit. The application saves the commands to the database using PHP scripts. Any changes to the database are recorded in the table new_events. With using the table irrigation unit detects whether is a database synchronization needed. Update and deleting data works on the same principles.
5 Description of the Main Features The basic scheme of code for microcontroller Arduino consists of two main functions. After the start is automatically launched initialization method setup(). This method is launched only once, thereafter followed by method loop(). The method loop() is designed as infinity loop (main thread of program). The method setup() in our case initiallizes basic variables and sets actual time for OS Linux (after power interruption Linux does not remember this settings). The function setCurrentTimeToLinux() reads actual set time in RTC module and sets time for OS Linux. In method loop() is repeated measurement of humidity of land (measureHumidity(sensor)), settings state of solenoid valves in accordance of values, which is stored in database (getValuesFromDB(valve)), sending humidity values to the database on a Web server (sendHumidityToDatabase()) and synchronization of time by Internet (synchronizeTime()). Other important method is measureHumidity(sensor). This method measures humidity by using sensor, which is connected to the analog input port of microcontroller Arduino. Value that is read from input port is needed to be converted to the percentual units.
Implementation of Microcontroller Arduino in Irrigation System
137
The method getValuesFromDB(valve) requires values from local database. These values determine the states of manual and planned irrigation. After is conducted evaluation on the basis of priorities – whether the system is in the mode active or no active. Top priority is manual irrigation, this priority can put the system into forced off or on state. In this state is realized the measurement of humidity of land and also sending the data to the web server, but when crossing the humidity settings, this parameter is ignored. If the manual mode is not activated, then irrigation unit works by using the planned mode. The planned mode of irrigation takes into account and also previous settings of humidity. If this value is exceeded, the system automatically switches off the irrigation loop (independently of the irrigation cycle). Irrigation is again automatically activated in the decrease of humidity. The method sendHumidityToDatabase() connects to a web server and sends the actual measured value of humidity. This is realized in regular cycles according to the value of the interval that is specified in the configuration settings. The method processes with humidity for each humidity sensor in the system separately. In the database is the record containing the ID number of the sensor, the measure value of humidity and time when the measurements were realized. The method synchronizeTime() is realized every 24 h and requires the current time from a Web server. This time is setting of the module of real time clock (RTC module). At the same it updates the time in OS Linux. In this way, we removed time deviation in module of real-time clock. Therefore is not necessary to adjust the time manually. If replacing the batteries in the clock module, you only need to restart the Arduino. After restart the time is synchronized.
6 Control Part As the regulation part has no display and no keyboard, we decided that for control of the whole system is a suitable an application for smartphones. The solution we have chosen also because of low financial demands. Another advantage of this solution is the fact that most users have the smartphone or tablet always at hand. Datamodel: This class is programmed according to the design pattern “Singleton”. This solution ensures that in memory is always only one instance of the class for data consistency. Classes “PlanItem”, “ManualItem”, “SettingItem” are connected to the class DataModel and they are the images of SQL database on the server. DBHandler: Another important part of the application is class DBHandler that provides communication between application and server. In order to obtain fast communication, subclasses are used: “GetManualDataFromServer”, “GetPlanDataFromServer”, “Get SettingDataFromServer”, “PostDataToServer”. These classes have its own thread. This thread is working in the background of the main thread. Main thread provides correct rendering of the GUI. User Interface: User interface of application consists of 4 basic screens: Screen of manual control, Screen of week schedule, Screen of settings and Screen for control week of schedule.
138
Š. Koprda et al.
Manual Control: On-screen for manual control is a slider bar to activate manual mode. In this mode, the system ignores the weekly schedule and is working according to the values that you entered manually. In this screen are also two buttons for control of solenoid valves. Screen of Week Schedule: This screen consists of individual items of week schedule and button to add a new item. Individual items of the week schedule shows the day and time when the irrigation system is activated for a particular irrigation loop. In the system we can set the desired time and amount of cycles of the day (Fig. 2).
Fig. 2. Screen for settings of manual control (left figure) and week schedule (right figure).
Screen for Control Week of Schedule: Screen for control week of schedule includes a combobox on the selected day of the week, one combobox to select the start of watering, and one combobox for setting the ending of irrigation and combobox for select the irrigation loop. Settings: Screen of settings is very simple and contains only two sliders. First slider is for settings of humidity at which the irrigation system is not active and the other to set how often information on the current humidity will be saved in the database (Fig. 3). Server Part: We rented a Web server as free hosting (hostinger.sk). Hosting provides us with PHP and MySQL without restrictions. PHP engine has all the features enabled. We can use any version of PHP. For managing the databases is used phpMyAdmin. MySQL Database: The database consists of four basic tables: manual, plan, settings and humidity. Table with a name Manual consists of two columns (valve, valve_status) and record data of the manual control. Column valve represents the identification of the specific valve and valve_status indicates its current status. Table with a name plan consists of five columns (id, day, time_from, time_to and valve) and provides to record the planning cycles. Column day identifies the relevant day of the week, columns
Implementation of Microcontroller Arduino in Irrigation System
139
Fig. 3. Screen for control of week schedule and settings for humidity and interval.
time_from and time_to reserve the time period when the system is active and column valve provides a particular solenoid valve. Table settings consists of three columns (id, setting_name, settings_value) and contains system settings. Column setting_name denotes a particular item of settings and column setting_value its value. Table humidity is determined for collection of information about humidity of irrigation land and it contains four columns (id, timestamp, value, and sensor). Column timestamp is time of record, column value contains the measured percentage of humidity and column sensor is a label of given irrigation loop. Table new_events provides as notification table for microcontroller Arduino. From this table Arduino receives information about which table has been changed. On the basis of the records in this table can microcontroller Arduino synchronize its local database. For complete administration of database, its integrity and control of the parameters of incoming requests were used PHP scripts. Android application uses custom scripts for loading data that is stored in the database. An integral part is the script logger.php, which allows you to record all operations and store the messages in the log table. On the basis on data from the log table we can create time-based graphs. These graphs show the performance of the entire system and system accesses to the central database. The simple script time.php is used for irrigation unit to synchronizate every 24 h or in case when we are changing battery.
7 Reliability Evaluation of the Irrigation System For evaluation of the reliability and behavior of the irrigation system was used technics of explorating analysis and non parametric Levene’s test for the purpose of observation of humidity in individual week schedule irrigation. For correct function of the irrigation system, we examined system behavior whether in the measurement process occurred errors. In the measuring, we focused on determining of systematic and random errors. Smart irrigation system has been tested in the laboratory conditions at the Department
140
Š. Koprda et al.
of Computer Science (FNS CPU in Nitra). The irrigation system was tested for one month. During testing we determined correct functions of solenoid valves (on/of switching) depending on the value set in the system. For analysis of correct function irrigation system we chose short time interval from irrigation period between 13.11.2015 to 16.11.2015. The irrigation system was turned on automatically without intervention during the day in three time intervals. When using the system, the following conditions can occur: • Solenoid valve 1 and solenoid valve 2 is closed – humidity at this time exceeded the set value, • Solenoid valve 1 and solenoid valve 2 is opened - humidity at this time has been below the set value, • Solenoid valve 1 is opened and solenoid valve 2 is closed, • Solenoid valve 2 is opened and solenoid valve 1 is closed, For evaluation of the reliability of the system we have created a data matrix. The matrix of data we have created on the basis of recorded values of measurement. On the basis of the measured data, we were able to determine the correct function of closing and opening of solenoid valve according the settings in the week schedule. In the following text, we present the results for one watering day (13.11. 2015) with a closed solenoid valve 1. For the following days (closed valve 1 and valve 2), the data was processed in the same way. The irrigation plan (ID PLAN: 1#2, 7#8, 9#10) was: • (1#2) to 60 % humidity, the valve is open, if humidity is exceeded, the valve 1 is closed, • (7#8) to 65 % humidity, the valve is open, if humidity is exceeded, the valve 1 is closed, • (9#10) to 70 % humidity, the valve is open, if humidity is exceeded, the valve 1 is closed. On the basis of values from Levene’s test were identified statistically significant differences in variability of humidity between observed irrigation plan (MS Effect = 3693.626; MS Error = 44.218; F = 83.532; p = 0.0000). Table 1. Descriptive characteristics of irrigation plan (13.11.2015) with closed valve 1 ID Valid PLAN N
Median Minimum Maximum 25th 75th Average percentile percentile deviation
Dispersion coefficient
Range Quartile Range
1#2 7#8 9#10
82.0 68.0 74.0
0.457 9.582 0.170
1.0 71.0 1.0
384 264 282
81.0 4.0 73.0
82.0 75.0 74.0
81.5 68.0 74.0
82.0 71.0 74.0
0.375 6.516 0.126
0.5 3.0 0.0
From the table of descriptive characteristics (Table 1), we can see that the median of humidity exceeds specified limits, but the variability in the case of the plan 7#8 is high, it reaches almost 10 % variability, whereas in case of the remaining plans is variability less than 0.5 %. The lower limit of quartile ranges, goes over the specified limits (60 %, 65 %, and 70 %) for all three irrigation plans. The high value of variability in case of the plan 7#8 could be caused by only a few extreme values.
Implementation of Microcontroller Arduino in Irrigation System
141
The Box plot (Fig. 4) shows the state when the valve 1 is closed. This Graph shows the median, quartile range - middle 50 % of the values and the minimum and maximum of humidity level. On the axis y is illustrated the humidity and on the axis x specific irrigation plan for the day and time.
Fig. 4. Box plot of irrigation plan (13.11. 2015) with closed solenoid valve 1
Fig. 5. Sequence graph of irrigation plan (13.11. 2015) with closed solenoid valve 1 (Color figure online)
142
Š. Koprda et al.
From this graph we can clearly show greater variability of humidity in case of the irrigation plan 7#8. Moreover, in this irrigation plan we can identify only three cases with humidity below 65 % in the moment, when the valve 1 is closed. Following graph (Fig. 5) represent process of behavior solenoid valve 1, which is closed in the given sequence of irrigation plan. On the basis of this graph, we can determine whether in the system occured errors and if so whether it is a system error or a random error. On the axis y is illustrated the humidity and on the axis x is sequence of irrigation plan (in this case, when solenoid valve 1 is closed). The blue curve represents irrigation plan, which was set using application on smartphone. The red curve represent real values of humidity.
8 Conclusion In the two years have been developed similar systems of irrigation. The low-cost and energy efficient drip irrigation system serves as a proof of concept by [24]. The design can be used in big agriculture fields as well as in small gardens via just sending an email to the system to water plants. The use of ultrasound sensors and solenoid valves make a smart drip irrigation system. Designed irrigation system allows the user to control irrigation in the household. The system is fully controlled using the online interface and requires an active internet connection. In case of internet connection failure, the system works on the basis of the previous saved settings. The advantage of the irrigation system is autonomously operated solenoid valves that ensure delivery of media to irrigation. The accuracy of the irrigation system was greatly influenced by the used type of sensors for solenoid valve 1. For this reason, in sequence to 60 % humidity solenoid valve 1 (Fig. 5) worked reliably and was closed. The sequence to 70 % humidity solenoid valve 1 (Fig. 5) worked correctly and was closed. In a sequence 65 % humidity (Fig. 5) an error occurred, which could be caused by unpredictable changes in humidity in irrigation loop and solenoid valve 1 hasn’t been opened. In an irrigation system occurred error, which can be considered after comparison of individual watering days as random, in regularly the watering sequence this error was not repeated. Random errors can be eliminated when we increase the number of humidity sensors in irrigation loop, or by replacing analog sensors for digital. The user can fully control the entire irrigation system using his/her mobile device. Other advantages of the irrigation system are: • possibility of operation in the event of internet connection failure, • management of irrigation equipment using the web interface, • possibility of supplementing the system with additional sensor elements. On the other hand, disadvantages of the irrigation system are: • created application is supported only on the Android OS 4 and above, • higher input costs, • the need to calibrate the humidity sensors, to achieve the highest possible efficiency of the irrigation system.
Implementation of Microcontroller Arduino in Irrigation System
143
References 1. Nallani, S., Hency, V.B.: Low power cost effective automatic irrigation system. Indian J. Sci. Technol. 8(23), 1 (2015) 2. Narechania, A.: An android-Arduino system to assist farmers in agricultural operations. In: IRF International Conference, New Delhi, India, pp. 19–26 (2015) 3. Bitella, G., Rossi, R., Bochicchio, R., Perniola, M., Amato, M.: A novel low-cost open-hardware platform for monitoring soil water content and multiple soil-air-vegetation parameters. Sensors 14(10), 19639–19659 (2014). (Switzerland) 4. Truong, T.N.C.: Factors affecting technology adoption among rice farmers in the mekong delta through the lens of the local authorial managers: an analysis of qualitative data. Omonrice 16, 107–112 (2008) 5. Pickernell, D.G., Christie, M.J., Rowe, P.A., Thomas, B.C., Putterill, L.G., Griffith, J.L.: Farmers market in Wales. Making the network? J. Brit. Food 106, 194–210 (2004) 6. Abdullah, F.A., Samah, B.A.: Factors impinging farmers’ use of agriculture technology. Asian Soc. Sci. 9(3), 120 (2013) 7. Sadaf, S., Javed, A., Luqman, M.: Preference of rural women for agriculture information sources: a case study of District Faisalabad. Pak. J. Agric. Soc. Sci. 2, 145–149 (2006) 8. Shaffril, H.A.M., Hassan, M.S., Samah, B.A.: Level of agro-based website surfing among Malaysian agricultural entreprenuers: a case study of Malaysia. J. Agric. Soc. Sci. 5, 55–60 (2009) 9. Samah, B.A., Shaffril, H.A.M., Hassan, Hassan, M.A., Ismail, N.: ICT contribution in increasing agro-based entrepreneurs productivity in Malaysia. J. Agric. Ext. Soc. Sci. 5, 93–98 (2009) 10. Kumar Sahu, C., Behera, P.: A low cost smart irrigation control system. In: 2nd International Conference on Electronics and Communication Systems, ICECS, pp. 1146–1151 (2015) 11. Pies, M., Hajovsky, R., Ozana, S.: Autonomous monitoring system for measurement of parameters of heat collection technology at thermal active mining dumps. Elektronika Ir Elektrotechnika. 19(10), 62–65 (2013) 12. Pies, M., Hajovsky, R., Latocha, M., Ozana, S.: Radio telemetry unit for online monitoring system at mining dumps. Appl. Mech. Mater. 548–549, 736–743 (2014) 13. Behan, M., Krejcar, O.: Modern smart device-based concept of sensoric networks. EURASIP J. Wirel. Commun. Netw. 1, 155 (2013) 14. Luo, H., Yang, P., Li, Y., Xu, F.: An intelligent controlling system for greenhouse environment based on the architecture of the Internet of Things. Sens. Lett. 10(1–2), 514– 522 (2012) 15. Olvera-Olvera, C.A., Duarte-Correa, D., Ramírez-Rodriguez, S.R., Alaniz-Lumbreras, P.D., Lara-Herrera, A., Gómez-Meléndez, D., Herrera-Ruiz, G.: Development of a remote sensing and control system for greenhouse applications. Afr. J. Agric. Res. 6(21), 4947–4953 (2011) 16. Lee, R.O., Suh, B.Y., Bae, Y., Yang, J.Y., Jeong, Y.Y., Nakaji, K.: Development of an integrated greenhouse monitoring and control system at province level. J. Fac. Agric. Kyushu Univ. 56(2), 379–387 (2011) 17. David, J., Jančíkoyá, Z., Frischer, R., Vrožina, M.: Crystallizer’s desks surface diagnostics with usage of robotic system. Arch. Metall. Mater. 58(3), 907–910 (2013) 18. Bajer, L., Krejcar, O.: Design and realization of low cost control for greenhouse environment with remote control. IFAC Proceedings Volumes (IFAC-PapersOnline) 48(4), 368–373 (2015)
144
Š. Koprda et al.
19. Kachňák, A., Holiš, M., Belanský, J.: Optimization of continuous processes using hybrid neuro-fuzzy systems. In: 7th World Multiconference on Systemics, Cybernetics and Informatics, ORLANDO, pp. 107–111 (2003) 20. Koprda, Š., Magdin, M.: New trends and developments in automation in agriculture. Compusoft: Int. J. Adv. Comput. Technol. 4(2), 1492–1494 (2015) 21. Fuentes, M., Vivar, M., Burgos, J.M., Aguilera, J., Vacas, J.A.: Design of an accurate, low-cost autonomous data logger for pv system monitoring using Arduino™ that complies with IEC Standards. Sol. Energy Mater. Sol. Cells 130, 529–543 (2014) 22. Agudo, J.E., Pardo, P.J., Sánchez, H., Pérez, Á.L., Suero, M.I.: A low-cost real color picker based on arduino. Sensors (Switzerland)14(7), 11943–11956 (2014) 23. Horalek, J., Horalek, J., Sobeslav, V.: Datanetworking Aspects of Power Substation Automation. Communication and Management in Technological Innovation and Academic Globalization, pp. 147–153. World Scientific and Engineering Academy and Society, Athens (2010) 24. Agrawal, N., Singhal, S.: Smart drip irrigation system using raspberry pi and Arduino. In: International Conference on Computing, Communication and Automation, ICCCA, pp. 928–932 (2015)