Water Discharge and River Depth Measurement Using Fuzzy Logic Based on Internet of Things

Based on statistics from Indonesian National Board for Disaster Management (BNPB) there are still many casualties caused by drifting or drowning in rivers every year. This is because most victims do not have sufficient information related to water discharge and river depth. In an effort to reduce the potential victims of these problems, a prototype was designed to provide a warning regarding river status as a display in the detail condition of the river in real-time. In this research, a prototype measuring instrument was produced that could provide information on water discharge and river depth in a sustainable and real-time manner. The prototype device consists of two main sensors as an implementation of internet of things, a water flow sensor and an ultrasonic sensor. Water flow sensor used to calculate the water discharge, and ultrasonic sensor used to measure depth of the river. The measurement results of the two sensors then become input parameters which are further processed using the fuzzy logic method, to be able to produce output in the form of river status. Fuzzy logic has been used because it can work well for simple classification and work similarly like human reasoning. This information can be monitored through the website and LCD attached on the device. The results of the study with the help of the Linear Congruential Generator (LCG) method indicated that greater input value of the water discharge and the river depth caused more dangerous of the river status. Whereas the prototype produced has an error range of 5-6 cm for depth information generated by the ultrasonic sensor while the accuracy of the water flow sensor on the master device is 79.75% and the slave device is 84%.


Introduction
River plays an important role in human life. In Indonesia, rivers can be used for many things, such as irrigation facilities, hydropower (PLTA), livelihoods, and so on. Unfortunately, we often heard news of people being washed away or drowning, especially in rivers. Based on BNPB data, it shows that there are still many victims drifting or drowning every year in various regions in Indonesia, especially communities around rivers. According to the National Disaster Management Agency at 2008, one of the factors that can cause disasters, namely the lack of information or warnings about a hazard. The large number of victims washed away or drowned due to the lack of information from the community, about the water discharge and the depth of the river itself. Based on the statement from the Hydrology Division of Balai Besar Wilayah Sungai (BBWS) Citarum, that each river has a different flowrate and can change at any time.
Drifting is a condition where the object is carried by the stream. According to Dr. Boedi Swidarmoko, Sp.P., drowning is death due to asphyxia in sufferers [1]. There are still many victims drifting or drowning in the river which makes this problem needs to be done or needs to be more effective. With the advancement of technology today, technology is needed to provide sufficient information for the public about the needs of the surrounding river. Therefore, departing from the above problem, this research builds a device that can categorize or classify the status of the river using the water discharge and cross river input.
Various attempts have been made to minimize the number of victims, such as installing warning boards or guardrails. The warning board that was installed had not been renewed for a long time and caused the surrounding community to often underestimate it because it was considered obsolete. This makes the efforts that have been made by related parties (Department of Water Resources, BBWS) not yet effective. Therefore, a technology that capable to provide detailed information about river conditions is still needed, especially regarding water discharge and river depth accurately, so as to minimize victims of drifting or drowning.
Research on the measurement of height and depth of water has previously been carried out, as conducted by Rausan Fikri et al. from the Tanjungpura University Physics Study Program. They conducted a research on web-based water level monitoring design, which in this research examined the measurement of water level using the HC-SR04 ultrasonic sensor and the measurement results can be accessed online on the website. The accuracy obtained in the measurement of water level is 96.48% [2].
In 2015, Vidia Susilo conducted a study on river depth measurement. The ultrasonic sensor used is the MB7060 sensor. Tests carried out in several places such as, in the pool with the results of an average error of 25.9% with the smallest error obtained around 5.03% and testing from the boat obtained the smallest error results around 14.75% and the biggest error around 74, 58% [3].

Research conducted by Sumardi Sadi and Ilham Syah
Putra in 2018 about the design of water level monitoring based on short message service (SMS) gateway. They conducted research on water level monitoring and alerts through text messages and give orders to close or open flood gate. The water level is divided into four and each height will display standby status. If the water level reaches standby level two, the operator will manually move the motor through the relay via short message. Likewise with the height of the water if it reaches standby level one, then the operator manually moves the motor two through the relay by ordering via text message [4].
Several studies on the calculation of water discharge have also been carried out, as was done by Aidi Finawan and Arief Mardiyanto, they examined the design of measuring devices for water discharge in a watershed. The measurement accuracy obtained for the smallest error is around 19% and the biggest error is around 28.2% [5].
The research was conducted by Wang YiHong with the title Development of Multi-path Ultrasonic Flow Meters Based on Embedded Systems examining the measurement of water flow through pipes using ultrasonic flowmeter sensors. The measurement accuracy results obtained are very good where the error occurs is less than 0.4% [6].
In a study conducted by Fathor Rohman regarding the manufacture of prototype flow meters to measure water discharge. He used an optocoupler sensor where there is an infra-red and a photo detector. Between the infra-red and the photo detector, a dish from the flowmeter is installed, which later the dish will rotate. Testing is done by flowing water into the flow meter and the results are displayed via LCD. The accuracy obtained in this study is very good with an error of less than 2% [7]. This prototype used fuzzy logic method with input parameters of water discharge and river depth to produced river status information. The fuzzy logic method is also considered easier to implement because it works like human reasoning. This is also supported by Jarkko Miittymaki and Matti Pursula in the journal article "Signal Control Using Fuzzy Logic" and Angga Juliat Saputra et al. in their journal article concluding that fuzzy methods can work well for simple classification and work similarly like human reasoning [8] [9].

Research Method
In this section will be explained about the devices used, methods, design and flowchart for this research. In Figure 1, Arduino Mega 2560 is a microcontroller board based on ATmega2560 (datasheet). It has 54 digital input / output pins (where 14 can be used as PWM output), 16 analog inputs, 4 UART (hardware serial ports), 16 MHz crystal oscillator, USB connection, power jack, ICSP header and reset button. To use simply connect it to a computer with a USB cable or turn it on with an AC-to-DC adapter or battery [10]. Arduino Nano is made on the basis of the ATmega328 microcontroller (for version 3.x) or ATmega168 (for version 2.x). Has the same function as Arduino Duemilanove, but in different package. Arduino Nano does not include a Barrel Jack type DC plug and is connected to a computer using a Mini-B USB port. It has 14 input / output pins (where 6 pins are used as PWM output), 8 analog input pins, a 16 MHz crystal oscillator and a reset button [11].

Microcontrollers, Sensors, Modules
Waterflow sensor component as seen in Figure 2 is the Light Dependent Resistor (LDR) sensor which is highlighted using a laser module to detect the rotation of the propeller [12]. To facilitate checking of the propeller spinning or not, a buzzer or alarm is added which will sound when the propeller passes the LDR sensor.  Figure 3 shows HC-SR04 sensor which is an ultrasonic wave-based distance measuring sensor. The principle works similar to ultrasonic radar, where the waves are emitted and then received back by the receiver on the sensor. The range of the sensor range is about 2 cm to 400 cm (datasheet) [13]. In this prototype the HC-SR04 ultrasonic sensor is used to measure depth. Basically, the depth measurement is almost the same as the water level measurement or TMA, where the formula used is (the distance of the sensor to the water surface + the distance of the water surface to the river) -(the distance of the sensor measurement).  Figure 4 has a GPS receiver (Global Positioning System Receiver) that can detect locations by capturing and processing signals from navigation satellites. This GPS processor module uses ublox NEO-6 GPS Module [14]. GPS module functions to receive the coordinates or longitude and latitude where the measurement device is installed.  Figure 5 shows Wemos D1 module and NodeMCU. Wemos D1 module based on ESP-8266EX microcontroller. ESP8266 is a chip that has a Wifi feature that allows connecting to a Wifi network. It has 11 input / output pins. Wemos D1 is already equipped with a USB IC to the CHG340 serial, so there is no need to buy a serial USB module separately [15]. Wemos D1 module is used for communication between master device and slave device in this study.
NodeMCU ESP8266 module is equipped with a micro USB port that functions for programming and power supply connectors. In this study, NodeMCU module is used to send or upload sensor measurement data that has been processed on the master device to the web which has been provided [16]. In Figure 6, LCD and LED are components that are used to display the measurement results and river status in this research.

Buoy Method
The Buoy method is one way to calculate the water discharge [17]. The results of the Buoy method experiments will be used to check the accuracy of the measurement of the waterflow sensor. In conducting the testing using the Buoy method there are several preparations, such as data retrieval which will later be included in the formula of the Buoy method to get river water discharge. First, calculate the flow velocity by drifting an object that can float (table tennis ball, cork, or wood) from cross-section 1 to cross-section 2. Distance of travel time is calculated using a stopwatch as shown in Figure 7 on the left. After that, then calculate the area of the two river crossings by measuring the width of the river and then multiply the results by measuring the average depth by dividing the width into five parts (d1 to d5) then the results are averaged as illustrated in Figure 7 on the right. Do the same thing on the cross section 2 then average the results with the results of cross section 1. The formula used to calculate debit using the Buoy method, as below [18]: Calculate water speed: Which "V" is river flow velocity (m/s), "D" is distance between cross-sectional areas 1 to 2 (m), and "t" is time required for the float to cover the distance from crosssection 1 to cross-section 2 (s).
Calculate the average cross-sectional area: which "A" is Wet cross-sectional area (m 2 ), "I" is River width (m), "d" is average river depth (m).
Water discharge calculation: which Q is water discharge (m 3 /s). In the master device as shown in Figure 8 using Arduino Mega 2560 (label 1) as a microcontroller which served as the control center. The battery / battery (label 2) functions as a resource. Because the components in the device operate at 5V, a step down (label 7) is needed to reduce the voltage from the power source so as not to damage the component. GPS modules (label 3) are used to capture and process signals from navigation satellites to get the coordinates of the device installed. Wemos D1 module (label 4) as communication between master and slave devices. The ultrasonic sensor (label 5) used is HC-SR04 to measure river depth. Waterflow sensor (label 6) is used to measure water discharge. The results of the measurement of the two sensors into the microcontroller input, then processed using the fuzzy logic method so as to produce the river status output. The measurement results are displayed via LCD (label 8) and LED (label 9) to make it easier to distinguish the output status of the river. In addition, the calculation data is also uploaded to the web through the NodeMCU ESP8266 module (label 10).

Measurement Device Design
Components on the slave device as seen in Figure 9 are almost the same as the master device except there is no NodeMCU ESP8266 module, LCD and LED lights.
Arduino Nano (label 1) uses as Microcontroller which works as the main control on slave devices. The working scenario of the tool, the ultrasonic sensor (label 2) measures the depth of the river and the waterflow sensor (label 3) measures the water discharge. The distance of the master and slave devices in this research is about five meters. The measurement results on slave and master devices are processed using a microcontroller. Water discharge and river depth are input to the microcontroller and then processed using the fuzzy logic method to get the output status of the river. The measurement results on the slave sensor are sent to the master device via the Wemos D1 module. Furthermore, the results of the temporary stream status on the master and slave devices are included in the fuzzy rules to get the final status results displayed through the master device LCD. To make it easier to know the final status of the river, the master device is also equipped with LED lights that will light up according to the river status category, namely: Green for STANDBY 4, White for STANDBY 3, Blue for STANDBY 2 and Red for STANDBY 1. Measurement results are uploaded to the web via NodeMCU ESP8266 module.

System Flowchart
As explained in Figure 10 below, there are three parts, namely the master, slave, and web that are connected using the internet. The system flow of the master and slave devices is almost the same, the GPS module will collect and process signals from satellites to get the coordinate data of the device that is placed. Water and ultrasonic sensors work in accordance with their respective duties, the water sensor measures air flow and the ultrasonic sensor will measure the depth of the river. The measurement results of the two sensors will be processed by a microcontroller on each device uses fuzzy logic so as to get a temporary stream status. Measurement results and temporary stream status results on slave devices are sent to the master device via the Wemos D1 module. Then after receiving data from the slave device, then the results of the status of the stream while the master and slave are re-entered in the fuzzy rules to get the final river status results. The final status results will be processed via LCD and LED on the master device. In addition to receiving via LCD and LED, the measurement results of the master and slave devices as well as the final river status output will be uploaded to the web via the NodeMCU ESP8266 module. After the measurement data on the device is received on the web, the data will be stored in the river information database. Measurement data for each device and final status results will be sent via a monitor with access to the web address provided. Then the sequence of numbers is recursively defined as follows: LCG like this is called a multiplicative generator (MG) [19].
a. Fuzzification, at this stage the membership function of each fuzzy variable is constructed, namely the depth and discharge of water.  Figure 11 shows the membership function of the fuzzy depth variable. In the depth variable is divided into four fuzzy sets: shallow, medium, deep, and very deep. Figure 12 shows the membership function of the fuzzy water discharge variable. In the variable water discharge is also divided into four fuzzy sets: slow, medium, fast, and very fast.
b. Inference, at this stage, fuzzy rules are developed as shown in Table 1. c. Defuzzification, this stage determines the value of a constant to represent each linguistic output. The method used is Sugeno and the constants set as shown in Figure 13.

Result and Discussion
Tests carried out in the Cigede River located at 6°58'23.3"S 107°37'30.5"E longitude and carried out in two different spots.    Table 3 show the results of testing the tools in second spot. The second spot is the part of the river that has a water discharge and river depth lower than the first place. The test is carried out for about 40 minutes. In the  The outputs in both experiments show the status in Standby 4 and in accordance with the rules set with 100% accuracy. This is also caused by tests conducted in the dry season so that river conditions do not allow it to rise to the next status.
To determine the water flow constant a number of experiments are performed by comparing with the results of the buoy method testing. The formula used is [21]: which "k" is constant, and "rps" is rotation per second.  Table 4 shows that there are five attempts to determine the most optimal waterflow constant. From the above experiments, it can be concluded that 3.6 is the most optimal constant value with an error range of 0.01 when compared to the results of water discharge using the Buoy method.  Figure 14 shows the measurement data of the device uploaded to the web. Data of each device is displayed making it easier for the community or related offices to monitor the condition of the river around the location of the device. In this research, testing the accuracy of fuzzy designs that are built using the Linear Congruential Generator (LCG) method. The LCG formula is in equation (5). By entering the depth and discharge data, with the rules set in the use of the LCG formulation, the values of m = 20, a = 11, and c = 7 are determined, so that the formula +1 = (11 + 7) mod 20. The result of testing 21 data parameters for input depth and water discharge using the LCG method dan be seen in Figure  15.
Testing the accuracy of the fuzzy system that was built with the LCG method of a total of 21 data -each data was carried out five times, the results obtained for each input value is greater, the status of the river that comes out is also more dangerous. And all results obtained are in accordance with established fuzzy rules.

Conclusion
After carrying out the implementation and conducting several experiments to ensure the tool runs well and in accordance with expectations, there are some conclusions in this research. Accuracy results obtained from the two experiments show different results, this is due to several factors, such as: the amount of garbage in the Cigede River causing the sensor waterflow to clog, the wind that occurs at any time so that it can change the speed of river water flow and other technical factors. Waterflow sensor accuracy testing was carried out as many as 2 experiments in different places. In the first experiment the accuracy of the waterflow master sensor is 79.5% and the slave is 80%. In the second experiment, the accuracy of the waterflow sensor on the master device was 80% and 88%. Ultrasonic sensors have an error range of 5 -6 cm. Fuzzy system test results using the LCG method with a total of 21 data input fuzzy variables, the results obtained are in accordance with the developed fuzzy rules. Greater input value caused more dangerous of the river status.
In further research, it is better to make a fence or barrier to hold the trash. This is intended so as not to obstruct the waterflow sensor during measurement. Distance fence or barrier should not be too close to the sensor because it can make the river flow slower. Supporting ultrasonic sensors is better to use materials from iron or wood to make it more robust. Testing needs to be done on more than one river so that the data obtained is more complete so as to obtain optimal results.