Hydroponic Nutrient Control System Based on Internet of Things

The human population significantly increases in crowded urban areas. It causes a reduction of available farming land. Therefore, a landless planting method is needed to supply the food for society. Hydroponics is one of the solutions for gardening methods without using soil. It uses nutrient-enriched mineral water as a nutrition solution for plant growth. Traditionally, hydroponic farming is conducted manually by monitoring the nutrition such as acidity or basicity (pH), the value of Total Dissolved Solids (TDS), Electrical Conductivity (EC), and nutrient temperature. In this research, the researchers propose a system that measures pH, TDS, and nutrient temperature values in the Nutrient Film Technique (NFT) technique using a couple of sensors. The researchers use lettuce as an object of experiment and apply the k-Nearest Neighbor (k-NN) algorithm to predict the classification of nutrient conditions. The result of prediction is used to provide a command to the microcontroller to turn on or off the nutrition controller actuators simultaneously at a time. The experiment result shows that the proposed k-NN algorithm achieves 93.3% accuracy when it sets to k = 5.


I. INTRODUCTION
T HE population of the world has increased almost 2000 times from the past 12-millennium population [1]. Population increases significantly in big cities [2]. The increasing population causes the decreasing of open land, which is required as media to grow plants and maintain the world population's food supply. Therefore, a landless planting method is needed in rural and urban areas. Hydroponics is one of the solutions to gardening methods without using soil as planting media. It uses nutrient-enriched mineral water as a nutrient solution for plant growth [3]. In general, maintaining the quality of hydroponic plants is done manually by monitoring the nutrition such as acidity or basicity (pH) value, the value of total dissolved solids (TDS), electrical conductivity (EC), and water temperature. Using the Internet of Things (IoT) concept, monitoring and controlling can be done remotely through the Internet in real-time. According to Ref. [4], IoT can increase plant growth due to maintaining the nutritional value and reducing plant maintenance costs by around 23%-70%. Some studies are done by employing IoT on the hydroponic nutrient control system. Reference [5] applies IoT to monitor pH and nutrient temperature on hydroponic with the NFT method. It can show the condition of nutrients, send a notification through a text message gateway, and control the actuator pH and oxygen pump. Reference [6] builds an IoT for the hydroponics system. It is divided into two parts: the automatic part and the manual part. It allows users to manually control the nutrient such as light, temperature, and humidity. The system runs automatically to check and refill nutrients by self-regulating and displays the graphics of nutrients to the users.
In another hydroponic research [7], IoT is combined with Deep Neural Networks (DNN) to predict nutrient control. The DNN predicts the label based on table control, which has eight labels. The system output shows the sensor value and predicts the control labels with the prediction of accuracy percentage.
Moreover, Ref. [8] predicts the soil using machine learning and IoT. The study is a soil-based system and predicts the soil condition. The irrigation system is fully automated and uses k-Nearest Neighbor (k-NN) as a machine learning classification to predict the soil condition.
The k-NN is known as a simple and easy to use. It can also be used in various applications [9]. The k-NN is also known as a lazy algorithm, in which the calculation of the classification of the test sample is Cite this article as: Herman, D. Adidrana, N. Surantha, and Suharjito, "Hydroponic Nutrient Control System Based on Internet of Things", CommIT (Communication & Information Technology) Journal 13(2), 105-111, 2019. large. It uses a large amount of memory, so the scoring is slow [10]. Moreover, Ref. [11] uses k-NN to predict water quality by comparing to Random Forest (RF) method results and testing several water conditions. The k-NN classification has higher accuracy than the RF with the same data samples. It indicates that k-NN can be used for water quality prediction and management.
Similarly, Ref. [12] proposes the uses of fuzzy logic and IoT for monitoring and controlling system. IoT devices are used to monitor plant conditions and water needs. Meanwhile, fuzzy logic is used to control the supply of water and nutrition precisely. This research also uses lettuce and bok choy and compares them by using smart control with a traditional method. The result shows that using intelligent control, plants can grow better by validating through the visual look of the plants.
In this research, the researchers propose a system design of the Nutrient Film Technique (NFT) for a hydroponic nutrition control system using the k-NN method and IoT. This system design is expected to provide accurate calculation results to command the microcontroller to turn on or off the nutrition controllers more than one at a time, such as pH down, pH up, AB nutrition, and filter pump. The k-NN algorithm is used for predicting the classification of nutrient conditions so the system can provide information on nutrition conditions to the user. pH and TDS values are controlled using pH (Up and Down) solution, nutrients (A and B) to increase the TDS value, and nutrient filter to reduce the TDS value obtained from the pH sensor and TDS sensor.
II. RESEARCH METHOD NFT method is selected for the hydroponic system. It has three holes of plant net pot and two levels of the gutter. It is divided into 12 parts. Those are nutrient tank, IoT module (sensor module and actuator module), sensors (pH, TDS, Temperature probe), pH up liquid tank, pH down liquid tank, nutrient A liquid, nutrient B liquid, TDS down pump, TDS down filter, nutrient circulation pump, gutter, and net pot. The NFT system can be seen in Fig. 1.
This NFT system is equipped with a sensor probe. It is controlled by Arduino Leonardo. Moreover, five pumps are controlled by NodeMCU. It is shown in Fig. 2.
This system is divided into three main modules. The first module is an Arduino board. It acts as a sensor module that gathers and sends sensor data to the ThingSpeak platform using esp8266 as a wireless communication module. The second module is the k-NN Server (local PC), which gets the sensor data to 6) Nutrient A liquid 7) Nutrient B liquid 8) TDS down pump 9) TDS down filter 10) Nutrient circulation pump 11) Gutter 12) Net pot The water to the c) k-NN   The water to the c) k-NN classify the nutrient condition and sends the result to the third module. The third module is a NodeMCU as the control module side to give an actuator command.
Data collected from ThingSpeak is about 5750. Those are labeled using lettuce parameters to create the dataset for k-NN classification. Data labeling refers to three sensor values and lettuce standard values based on research by Ref. [13]. Each of the sensor has three probability conditions. It is normal if the values of the sensor are between the range of the parameter. It is low if the values of the sensor are lower than the range of the parameter. Then, it is high if the sensor's values are higher than the range of the parameter. If the sensors are three and the probability conditions are three too, the nutrient system condition should have 33 = 27 labels probability classification. With 27 labels of probability classification, the researchers define it in Table I. Moreover, this system has three evaluation phases, as seen in Fig. 3.
First, it evaluates the sensor module. It is evaluated by comparing the values of normal pH and TDS meter. The data sensor is sent by Arduino to ThingSpeak and checks whether it is updated every 15 seconds. Second, it is the actuator module. The actuator module is examined by measuring the water flow by the pump according to the specified time. Third, it is the k-NN server. Testing the k-NN prediction with sensor data is Cite this article as: Herman, D. Adidrana, N. Surantha, and Suharjito, "Hydroponic Nutrient Control System Based on Internet of Things", CommIT (Communication & Information Technology) Journal 13(2), 105-111, 2019. This system divided into three main modules, the first module is an Arduino act as sensor module which gather and sends sensor data to the thingspeak platform using esp8266 as a wireless communication module, the second module is the k-NN Server (local PC) which gets the sensor data to classify the nutrient condition and sends the result to the third module which is a NodeMCU as the control module side to give actuator command.
Data collected from thingspeak is about 5,750 and labeled using lettuce parameters to create the dataset for k-Nearest Neighbor classification. Data labeling refers to 3 sensor values and lettuce standard values based on research [13], each of these sensors have 3 probability condition such as normal if the values of the sensor are between parameters range, low if the values of the sensor are lower than parameters range, and high if the sensors values are higher than parameters range. Then, if the sensors are 3 and the probability conditions are 3 too, so the nutrient system condition should have 33 = 27 labels probability classification, then with thus 27 labels probability classification, we define it with table 1.
This system has 3 evaluate phase, as can be seen in  based on 27 conditions of nutrient using real-time test data from ThingSpeak. Then, the researchers calculate the accuracy with different k-value to get the optimal k-accuracy with the Eq. (1). The accuracy result shows the percentage of tests that are correctly classified by classifier [14]. The equation can be seen as follows:

A. Proposed Hardware Design
A sensor module consists of several tools and sensors. Those are Arduino, breadboard, pH sensor, TDS sensor, DHT11 sensor, DS1B820 sensor, HC-SR04 Sensor, and ESP8266. Figure 4 is a schematic description of the Arduino pin connection to the pin sensor and ESP8266. There are three sensors with digital pins connected to the 3.3v pin and ground pin, and two analog sensors (pH sensor and a TDS sensor) that are connected with 5v pin and ground pin. Furthermore, ESP8266, as a wireless communication media, is connected to D10 and D11 pins, which are connected serially and given a 5v and ground voltage.
Moreover, the actuator module consists of NodeMCU, breadboard power supply, 8-chanel relay, and five water pumps with the scheme in Fig. 5. The relay connects with five digital pins from NodeMCU to exchange data from pump 1 to pump 5. The relay is connected with a 3.3v and GND pin from NodeMCU. Meanwhile, the pump gets voltage and GND from the 5v power supply. Figure 6 is the result of the sensor and actuator module that have been arranged and installed inside the box. Once it is assembled, the sensor and actuator modules are installed on the NFT hydroponic system. It is shown in Fig. 7.  The relay connects with 5 digital pins from NodeMCU to exchange data from pump 1 to pump 5. The relay connected with a 3.3v and GND pin from NodeMCU while the pump gets voltage and GND from the 5v power supply. Fig 6. is the result of the sensor and actuator module that have been arranged and installed inside the box.    The relay connects with 5 digital pins from NodeMCU to exchange data from pump 1 to pump 5. The relay connected with a 3.3v and GND pin from NodeMCU while the pump gets voltage and GND from the 5v power supply. Fig 6. is the result of the sensor and actuator module that have been arranged and installed inside the box.   The first phase before building the actuator control saves the sensors data from the database with CSV format as a dataset as follows in table 2.   Figure 8 shows the actuator control design flowchart. The first phase before building the actuator control is saving the sensors data from the database with CSV   format as a dataset. It is shown in Table II. Then, this dataset is classified and labeled manually using a spreadsheet-based on 27 probability classifications. Thus, the labeled dataset is created and shown in Table III.

4) Windows 7 32bit
After a dataset is labeled, actuator control is built, as shown in Fig. 8. First, the researchers take the previously made dataset and divide it into attributes as x and label as y. The y is dependent data. The attribute is independent data, which is pH, TDS, and temperature sensor data. Second, the researchers normalize the x data using the MinMaxScaler function to transform dataset values between 0-1. Third, the researchers get the last updated sensors data from ThingSpeak. Fourth, the researchers calculate the last updated data using Euclidian distance with each sensor data from the dataset. Fifth, the researchers rank the Euclidian result from the lowest to highest distance. The lowest result indicates the closest distance to the last updated sensors data. Sixth, the researchers classify the result data by counting the majority uses optimal k, which is determined later. The classification result is shown in Fig. 9. Figure 9 shows the label of [1], so the k-NN server sends a command to NodeMCU to control the actuator based on the solution from Table I as "Normal Condition". Thus, the actuator will turn the chiller and all pumps off.

III. RESULTS AND DISCUSSION
The k-NN evaluation uses real-time data from ThingSpeak. It is done by retrieving real-time data for every 25 minutes of data collection from ThingSpeak. Each dataset is calculated by using k-value to get the majority rank. The initial range of k-values is by dividing the dataset into 80% data train and 20% test data. Then, calculating accuracy is done by the k-NN classification. Figure 10 shows the four test results to get the initial k-value range. It shows that the highest k-value is k = 5. It decreases on the higher k-value, so the test stops at k = 11. The next test is retrieving real-time data from ThingSpeak and giving several conditions on hydroponic nutrition. Then, the researchers use the

IV. ACTUATOR CONTROL DESIGN
The actuator controlled by using the results of the k-NN classification runs on k-NN Server in local PC with specification:  The first phase before building the actuator control saves the sensors data from the database with CSV format as a dataset as follows in table 2.
This dataset then classified and labeled manually using a spreadsheet-based on 27 probability classifications, so the labeled dataset created and shown in table 3.    Fig 9 shows the label is " [1]", so the k-NN server sends a command to NodeMCU to control the actuator based on solution from table 1 as "Normal Condition" so the actuator will turn the chiller and all pump off.  k-value range between 1-11. Table IV shows  The actuator module uses it as a command. Then, Fig. 13 shows the actuator module action sample.

IEEE TRANSACTIONS ON EDUCATION
k-NN evaluation uses realtime data from thingspeak by retrieving realtime data for every 25 minutes of data collection from thingspeak. Each data calculated uses k value to get the majority rank. The initial range of k values defines by dividing the dataset into 80% data train and 20% test data, then calculating accuracy by carrying out the k-NN classification. shows the highest k value is k = 5 and decreasing on higher k value, so the test stops at k = 11. The next test is retrieving realtime data from thingspeak and give several conditions on hydroponic nutrition then use k value range between 1 -11. Table 4    k-NN evaluation uses realtime data from thingspeak by retrieving realtime data for every 25 minutes of data collection from thingspeak. Each data calculated uses k value to get the majority rank. The initial range of k values defines by dividing the dataset into 80% data train and 20% test data, then calculating accuracy by carrying out the k-NN classification. shows the highest k value is k = 5 and decreasing on higher k value, so the test stops at k = 11. The next test is retrieving realtime data from thingspeak and give several conditions on hydroponic nutrition then use k value range between 1 -11. Table 4     Those indicate that the actuator module receives the command from the k-NN server and turns on the nutrition A pump, nutrition B pump, and pH down pump. Figure 13(B) shows two lights in the actuator. It implies that the actuator module turns the pH up, pump on, TDS down, pump on at a time. From previous studies [7,12], a comparison between DNN, fuzzy logic, and k-NN method can be seen in Table V    uses a closed-loop, which is divided into more detail on each sensor value. However, it has a weakness because the closed-loop process will carry out the next task if the first task is completed. So, only one actuator can turn on at the time. Meanwhile, in the k-NN, the system made has higher accuracy than DNN. It can give orders to turn on and off the several actuators simultaneously or gradually by the established rules.

Method
Advantage Disadvantage

k-NN
With optimal k, the accuracy is high.
Need to experiment with some k-value. This system can turn on the actuator simultaneously. This system can turn off the actuator simultaneously or gradually.

DNN
The system can turn on the actuator simultaneously.
The accuracy is lower than the k-NN result. The system cannot turn off the actuator gradually.

Fuzzy Logic
High accuracy.
The system cannot turn on the actuator simultaneously.

IV. CONCLUSION
This research is conducted to test the system design using k-NN to classify nutrient conditions on a hydroponic system with IoT on a prototype scale. The evaluated system shows that k-NN successfully classifies the nutrient condition with several k-values. The classification result can be used in a real-time condition and used as a command to the actuator module. The actuator also can turn on or off the nutrition controller simultaneously at a time according to the label that is classified. This system can be further developed by making real planting to prove the success of the system and improving the accuracy value of the k-NN classification.