PROTOTYPE OF AUTOMATED IRRIGATION SYSTEM USING RASPBERRY Pi AND SOLAR ENERGY

According to surveys and projections by the United Nations (UN), by the year 2100, the world population will reach about 11.2 billion people. Thus, the need arises to develop modern technologies for food production aimed at the future population. Irrigation performed correctly can increase crop productivity, and automated systems are an excellent alternative for controlling irrigation processes. Among the most varied forms of powering water pumping systems, photovoltaic solar energy has become a viable and sustainable alternative for energy generation. This work aimed to build and analyze a prototype of automated irrigation powered by photovoltaic panels, using Raspberry Pi, Arduino, ESP8266 and MQTT protocol to inform the user on a mobile device about the monitoring of the system. Despite being a low-cost system, approximately R$ 2.000.00, the results obtained through the sensors showed good accuracy. With the use of IoT technology, it was possible to monitor soil moisture information that impacts the production system instantly. In addition, using part of the prototype to obtain soil moisture by sending the information via the internet, without needing for a physical connection, proved effective in sending the data.


INTRODUCTION
According to surveys and projections by the United Nations (UN), it is estimated that in the year 2030, the world population will be equivalent to 8.6 billion people; by 2050, it will reach about 9.8 billion people and in the year 2100, about 11.2 billion people (United Nations, 2017). In this context, there is a need to produce food in quantity and nutritional quality to meet the demand.
With the use of technological solutions, it is possible to increase food production and reduce the number of inputs used in the production chain. Thus, it becomes essential to increase agricultural productivity, as well as promote the use of agricultural technologies that are ecologically sustainable and economically viable.
Over the decades, Brazilian agricultural production has changed and stands out in the national and global food production scenario due to its excellent production potential (Vieira Filho & Gasques, 2016). However, although large rural properties have technological implements that increase productivity for small and medium-sized producers, the scenario is different, with 70% of the food consumed by Brazilians from family farming.
Faced with several factors that may limit agribusiness productivity, one of the most relevant is rainfall. However, to reduce or eliminate the risk of losses in case of lack or poor distribution of rain, it is necessary to apply irrigation methods.
The use of electric energy has become indispensable nowadays; however, discussions about the consequences of energy generation by polluting sources have been raised. Thus, the energy market has sought solutions and alternatives promoting less environmental impact. Brazil is ahead in terms of the use of renewable energies, with the share of renewable energies in the energy matrix corresponding to 84.8%, a value higher than the participation of this type in the world electricity matrix, being 23% in 2018 (IEA, 2020) (Mesquita, 2022).
Photovoltaic solar energy stands out, faced with the most varied forms of feeding an irrigation system, with no undesirable waste emissions, in addition to being considered renewable energy by using solar irradiation (Barbosa et al., 2015).
In addition, due to the territorial characteristics of the intertropical zone, Brazil has great potential for solar incidence, allowing the use of solar energy as a source of supply (Pereira & Mendes, 2019). Campos and Alcantara (2018) point out that solar energy has become an essential source of electricity, especially for rural areas, used to pump water. According to the authors, small family farms suffer from the lack of technologies that help production. In this way, productivity is reduced, favouring the rural exodus.
Using photovoltaic solar technology in isolated communities without access to electricity may be viable to meet the energy needs of rural communities and activate water pumping systems (Mesquita, 2014).
Testezlaf (2013) reports that commercial automated irrigation saves water resources; however, he highlights such disadvantages, such as high implementation costs and the need for specialised labour, which often end up not being viable for small farmers.
The use of automatic systems at the agricultural level has become an irreversible process and has changed the activities performed by workers before acting directly in production processes and is now being applied to supervision and monitoring (Alvarenga et al., 2014). Although current irrigation systems have advanced technologies, such as automated systems, small and mediumsized farmers only sometimes have full access to these technologies due to financial problems or lack of knowledge.
In this sense, it is pertinent to use software and hardware tools to obtain an automated irrigation system using the internet of things (IoT) for the transmission of data regarding the operation of the system to the user. Thus, given the needs, the development of technological instruments must provide the agricultural producer with the necessary information, in a simple way, with easy access and low cost, minimizing energy costs and increasing productivity.
Thus, this work aims to develop and analyse an automated irrigation prototype using a Raspberry Pi 3 single-board computer in conjunction with Arduino Nano and ESP8266, powered by photovoltaic panels. With this prototype, it is possible to monitor, using a smartphone, the main quantities that can impact productivity.

MATERIALS AND METHODS
The prototype was developed and tested at the Electrotechnics Laboratory of the Agricultural and Environmental Engineering course at the Federal University of Rondonópolis (UFR). The primary materials used in the development of the work are presented in Table 1.
Two resistive soil moisture sensors, model HL-69 and two capacitive sensors, model HW-390, connected to the analogue ports of an Arduino Nano, were calibrated. The sensors were calibrated for two substrates: Substrate A is a commercial mixture used in gardening and vegetable production. The system was in operation for four days, during the daytime period. In contrast, substrate B is a simple substrate consisting only of fine construction sand.
The calibration method for the sensors was based on the methodology Oliveira (2018) used, in which deformed samples of substrate A were subjected to residual moisture removal in an oven for 24 hours and were later weighed. Air-dried samples containing residual moisture between 0.5% and 1.5% for substrate B were used. Amounts of water referring to 9% gravimetric moisture were added to the dry samples, and after 10 minutes (stabilization period), the analogue values recorded by the Arduino were obtained. Subsequently, we added amounts of water equivalent to 2.5% gravimetric moisture until reaching 29% to record analogue readings by the Arduino. With the analogue readings, trend equations correlate the analogue value with the actual gravimetric soil moisture value.
The INA219 voltage and current sensor were calibrated using a load with available power and voltage powered by a voltage source. A calibrated multimeter measured the load current and voltage, and the sensor readings were adjusted using a constant to adjust with the readings of the multimeter.
The water flow sensor, model YF-S201, was calibrated using a graduated container with a known volume. A constant was adjusted to suit the pulses generated by a sensor that corresponded to the volume obtained in the container.
The prototype was divided into three parts, as shown in Figure 1, and the Message protocol was used for communication between them -queue telemetry Transport (MQTT). MQTT is a simple and lightweight protocol for sending publish/ subscribe messages and is an ideal communication method for applications where bandwidth minimization and energy consumption are essential (MQTT, 2021). The Broker is an essential component of the MQTT protocol, as it concentrates and distributes published information. When there is a new post on a topic, the Broker distributes the post to all customers who have subscribed to this topic (Patel et al., 2015).
As exemplified in Figure 2 for a temperature sensor, users can have the role of publishers (sends data) and subscribers (receives data).
Exemplifying in a summarized way through the proposed system, the microcontroller connected to the sensors in part 1 of the system reads with  a predetermined time interval. It publishes these values in a topic on the server. The single-board computer in part 2 subscribes to the threads in part 1, gets these values, handles them, reads from other sensors, and publishes them to other threads on the server. Part 3, in turn, subscribes to topics published by part 2 and displays them to users. In Figure 1, S1 and S2 are the soil moisture resistive sensors, S3 and S4 are the capacitive sensors, and S5 and S6 are the INA219 and YF-S201 sensors, respectively. Links represented by solid lines mean connections made physically, while dotted lines are made using wireless communication.
Part 1 of the prototype was responsible for obtaining the values read by the soil moisture sensors and publishing them through a Wi-Fi connection in the MQTT broker. Part 2 was responsible for reading the values sent by part 1, converting them into gravimetric soil moisture, and then deciding whether to activate irrigation.
Part 2 was also responsible for sending the converted soil moisture values to the Broker server and the current and voltage values used for pumping.
Part 3 consisted of a Smartphone with an MQTT viewer application connected to the Broker. The application is configured to communicate with a free Broker available on the internet, subscribing to topics published in part 2 of the prototype.
For communication through the MQTT protocol to take place, some settings are required, such as the server's web/ IP address, port number and network protocol. This information is characteristic of the server used, and in addition to them, it is necessary to define names for the topics used to publish the desired information. All settings were similarly configured on both parts of the system.
For the assembly of part 1 of the prototype, we used: 1 Arduino Nano, 1 ESP-01, two capacitive soil moisture sensors HW-390, two resistive soil moisture sensors HL-69, one breadboard 170 holes, 1 ESP-01 adapter, 1 CCS-P1024 charge controller, 1 12V and 5Ah stationary battery, one 10W solar panel model KS10T and a styrofoam box for storing the components. The circuit assembly of this step is shown in the diagram in Figure 3.
Part 1 of the prototype was designed to allow modularity of soil moisture measurements, and the construction of more modules would allow the verification of moisture at various points without the need for wiring to connect the Arduino to the Raspberry Pi. For the incorporation, it would be enough to build similar modules, changing only in the programming, the Broker MQTT topic in which the module would publish.
For part 2 of the prototype, we used: 1 Raspberry Pi 3 B+, 1 1-channel 5 V relay module, 1 INA219 current and voltage sensor, 1 YF-S201 water flow sensor, 1 12V water pump model CF-220 110 PSI  The motor pump was connected to a 1000-litre reservoir, where function was to simulate a water body. In addition, it was connected to a structure made of ½" PVC pipes, in which 4 MF2 Inverted micro sprinklers with a flow of 112 L/h were installed.
In this way, the structure built for irrigation, the water reservoir, part 1 of the prototype and the power panel of part 2 were installed outside the laboratory. At the same time, the other components were accommodated internally in the laboratory, as shown in Figure 5.
The programming used in Arduino, in part 1 of the prototype, followed the logic described in the flowchart in Figure 6, while the programming performed in the Raspberry Pi, in part 2, followed the logic presented in the flowchart in Figure 7.
To simulation perform of the system in a similar way to what happens in practice, the prototype was tested in organic soil (substrate A), as shown in Figure 8. During the execution of the experiment, it was observed that substrate A has a large water retention capacity, and the time of year in which the experiment was carried out was a rainy season (month of November). The time between irrigations became large; in this way, prototype tests were carried out in sand (substrate B), as shown in Figure 9, which has a low water retention capacity.

INA-219 sensor calibration
The values obtained by comparing the values of current measured by the INA219 sensor, the bench source and the multimeter are expressed in Table 2.
The values obtained by reading the sensors through the "ina219" library without any modification showed an average error of 0.96% compared to the bench source and 1.32% compared to the multimeter, thus not being No modification to sensor code required for current measurements.
The sensor observed that the INA219 presented lower values than those read by the other components, and an adjustment ratio of 1.15 was found. After the modification, the readings were repeated, and the results obtained are shown in Table 3.
After adjusting the code, an average error of 0.25% was obtained compared to the bench source and 0.37% compared to the multimeter; thus, no other modification was made in the sensor programming for voltage measurements.

YF-S201 sensor calibration
Comparing the values defined in programming and the fundamental values pumped by the system, an average error of 16.59% was observed. Making a relationship between the results obtained and those expected with the initial conversion constant of the sensor, a new constant of 6.97 was found. Thus, the results of Figure 10 were obtained.

Calibration of soil moisture sensors
Tables 4 and 5 show a compilation of R² values for trend equations on substrate A and B, respectively, as well as the averages per equation.
When observing the correlation indices (R²) in substrate A, the best-fitting equation was the power equation with an average R² equal to 0.9574, while the linear one obtained 0.8955. When observing the correlation indices, the trend equation best fitted for substrate B and substrate A was the power equation with an average R² of 0.8663, while the linear trend equation had an average R² of 0.7367.
Although for substrates A and B, the trend equations that best fit the soil moisture values were the power equations, it was observed that this equation tends to overestimate moisture values outside the range in which the sensor was calibrated. Thus, the equation adopted for the system was linear.

Substrate a test
The irrigation test on substrate A is shown in Figure 11. In this substrate, it was programmed that irrigation should be activated if the humidity value was less than or equal to 20% and turned off otherwise. As can be seen, soil moisture regressed slowly over time. This fact occurred for two main reasons: the region's climate was rainy in the evaluation period. On the evaluated days, it either had rain or cloudy days with high air humidity. The second reason was the soil structure, which is organic soil with high moisture retention.     Although the climate did not allow the occurrence of several irrigation cycles for this substrate, it is possible to observe in Figure 11 that when the system identified that the soil needed irrigation, the pump was activated, raising the water content in the soil again. In addition, an increase in the volume of water used in irrigation is also observed, measured by the flow sensor and recording energy consumption by pump activation.

Substrate B teste
Because substrate B is made of fine sand, which has a low water retention capacity, it was possible to observe several irrigation cycles being performed by the prototype.
Three repetitions of the system activation were performed for the prototype tests on substrate B, with each repetition changing the humidity parameters. For the first test, the irrigation activation limit was used for humidity values less than 20% and for the shutdown, values greater than 20%, shown in Figure 12.
In Figure 12, it is possible to observe that although the shutdown limit was set to 20%, higher values were read after the shutdown. This is due to the distribution of water in the soil profile and the reduced size of the soil sample that even after shutdown from the motor pump, it continued to receive enough water to change its humidity.  In the second repetition, the system activation parameter was defined for values less than 18% and the shutdown parameter for values greater than 24%. The results obtained are shown in Figure 13.
After the third iteration, upper and lower limits were changed to the trigger threshold was set to 16% and off 26%. The results are displayed in Figure 14.
It is possible to verify that the system mostly managed to keep the humidity read by the sensors in the programmed range in all repetitions. The prototype also recorded values of water volume and electricity consumption used in pumping, in which the value was added each time the irrigation system was activated.

Remote monitoring
The prototype could read and write to Broker   With the settings made for subscription to the topics so that part 2 of the prototype was published, it was possible through part 3 (remote monitoring) to receive and display soil moisture values. Voltage and current, in addition to electricity consumption and water flow used for irrigation, as shown in Figures 15 and 16 received by the application at different times.
As with the results of Moro (2018) using the MQTT protocol and the IoT MQTT Panel application for developing an automated vegetable garden, this project stage is successful. The application configuration step was relatively simple, just entering the Broker address, the port (which in most cases is 1883), the desired device ID and adopting a name for the Broker publish and subscribe topic. The port (which in most cases is 1883) is the desired ID for the device and adopts a name for the topic for publication and subscription. Figure 15 (a) shows the instantaneous values of average soil moisture (average between the four sensors), voltage and current, and historical values of average soil moisture and electricity consumption. In Figure 15 (b), the screen capture 15 minutes after the first capture is shown, thus showing the evolution of the graphs that display the historical values of average soil moisture and electricity consumption.
In Figure 16, it is possible to see the application displaying instantaneous values of voltage, current and water flow when the need to activate irrigation was identified, in addition to the growth of the average soil moisture and electricity consumption  Finally, in the development of the system, a comparison of values against market equipment and data/characteristics is presented in Table 6. Bearing that this commercial equipment does not have the same operating characteristics used in the project, there is sufficient similarity for the comparation. During the tests, system part 1 operated with an average power of 0.6 W and part 2 with 5 W when the motor pump was not activated, and another 19.2 W when the pump was activated, as shown in Figure 16, which depicts the consumption of the motor pump.
The assembly of this system spent approximately R$ 2.000.00, and the system was able to obtain data on soil moisture, water consumption, and energy consumption, monitor irrigation and display them in an application on the smartphone, indicating that the current design meets the low-cost requirement. On the other hand, a commercial system that only obtains the values of soil moisture and sends it to a platform, which is the case of the HOBOnet RXW-SMC-900 of the HOBO brand, during the development period of this work, there was a cost of R$ 4.615.00.

DECLARATION OF INTERESTS
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

CONCLUSIONS
• Developing the prototype uses low-cost sensors and equipment. This type of proposed technology would be within reach of the small rural producer, which could be used to increase their productivity and reduce the waste of natural resources since the irrigation system is fully automated.
• Soil moisture, voltage, current and flow sensors were fundamental for the automation of the system. Although these sensors are low-cost, they showed good accuracy in readings.
• With remote monitoring using the IoT, the producer can instantly measure and monitor the resources spent on his production through his smartphone wherever he is.
• The use of photovoltaic solar energy for the electrical supply of the prototype proved to be efficient in fulfilling its assignment, supplying the motor pump and the electronic components. In addition, it can be an alternative source of electrical energy in places without access or far from the conventional electricity grid, thus contributing to developing sustainable systems.
• Using a separate part of the prototype (part 1) to obtain values related to soil moisture proved very effective. The part in question has mobility, dispensing the physical connection with the rest of the components. Thus, it can be used in various parts of the irrigated crop far from the system's command centre if it has an internet signal.