Design of a real–time water quality monitoring and control system using Internet of Things (IoT)

Abstract United Nations (UN) sustainable development goal 6 focuses on clean water and sanitation for all. To date, one-third of the world’s population lack access to clean, safe water. The traditional water purification methods cannot monitor and control water quality parameters from the early stages. In this paper, Internet of Things (IoT) is used to develop a real-time water quality monitoring and control system for a water treatment plant. A microcontroller is developed and interfaced with sensors to detect any deviations in the water quality parameters from the World Health Organization (WHO) standards. Every stage of the water treatment process is tested for quality, and deviations from the WHO standard triggers an autonomous control measure. A simulation model and a working prototype are developed. The research produces the expected results: accurate monitoring and control of water parameters.


Introduction
United Nations (UN) sustainable development goal 6 focuses on clean water and sanitation for all (United Nations, 2015). Freshwater on the earth's surface constitutes 2.5%, and only 1% is accessible for use (Vasistha & Ganguly, 2020). Water security risks are increasing day by day. Water security is the reliable access to water of sufficient quantity and quality for basic human needs, small-scale livelihoods, and local ecosystem services, coupled with a well-managed risk of water-related disasters (WaterAid, 2012). Two keywords are quantity and quality. Water scarcity (quantity) and freshwater decline (quality) have been exacerbated by climate change (Whitehead et al., 2009). Water availability is becoming increasingly unpredictable as a result of disrupted weather patterns. The shortage of water currently affects more than 40% of the world's population (UNDP, 2020). This alarming figure is projected to continue rising (Boretti & Rosa, 2019). Water quality is also severely affected. Changes in rainfall and increased water temperatures affect chemical reaction kinetics. This reduces freshwater ecological quality. Water pollution has also increased due to industrial activities (Mutubuki & Chirinda, 2020). Although 2.1 billion people have improved water sanitation since 1990, the provision of safe drinking water in adequate quantity remains a major challenge (UNDP, 2020). The 2018 projections by the United Nations World Water Development indicate that 6 billion people will experience a lack of access to safe drinking water by 2050 (United Nations, 2018). The supply of unsafe drinking water is responsible for 3.575 million fatalities annually (Dubey et al., 2020), and it also hinders socio-economic growth (Odhiambo, 2017).
The aforementioned negative effects are largely felt in developing countries, where water quality monitoring is done manually. One such method is the multiple barrier concept. This is a quality assurance technique that encourages water quality standards to be met at each stage of the water treatment process (LeChevallier & Au, 2004). This method achieves total water quality at the end of the entire process. The method enhances operational efficiency; however, it is difficult to monitor and control parameters from the early stages when using these traditional methods.
A deviation in quality can pass the early stages, only to be detected at later stages, which not only is costly but time consuming as well. In some instances, the deviation goes completely undetected. A case study conducted at a water treatment plant showed that each successive run for a manually operated water treatment plant takes an average of 35 minutes. The process involves taking water samples to the laboratory for analytical testing. Productive time is lost through unnecessary delays such as walking to the plant for sample collection, walking back to the laboratory for analytical testing, sample analysis, and recording as well as opening and closing manually operated valves. The result is an overall inefficiency of approximately 36.5%. The process is also costly requiring skilled technicians and advanced equipment. The manual testing processes are error prone and pose health risks such as the spread of waterborne diseases like cholera, typhoid, and diarrhoea.
To overcome such drawbacks, research has been done on developing systems for water monitoring and control. Cloete et al. (2016) designed and developed a real-time water quality monitoring system for measuring flow, temperature, pH, conductivity, and oxidation reduction potential. Rao et al. (2013) focused on measuring water quality for aquatic ecosystems. Wang et al. (2009) built a system that enables users to use the current and historic water quality data to make decisions. Other research focuses on bringing solutions to the challenge of freshwater scarcity. Júnior et al. (2021) conducted research that focused on monitoring and managing water resources. Other systems were developed to use optical sensors to monitor water quality. Højris et al. (2016) used an image analysis system to identify and classify individual bacteria and abiotic particles present in water. Vang et al., 2014) focused on the use of biosensors to develop a microfluidic-based system for the detection and monitoring of water contamination using a bacterial indicator such as microbial adenosine-triphosphate (ATP).
Literature has few studies that propose a combination of water quality monitoring and control. This paper is based on the design of a real-time water quality monitoring and control system for a conventional water treatment plant using Internet of Things (IoT). The use of IoT allows for the integration of different sensors for data acquisition. The obtained data are verified with the threshold values in the control section. The decision-making process is based on fuzzy logic reasoning. The values are generated on the web page and the user receives a detailed description of the values through a short message service (SMS). If parameter levels or any other parameters are off spec, an autonomous control measure is carried out by use of multi-media filters and automated chemical dosing units.
The objectives of the study are • To develop an Arduino-based microcontroller system for water quality monitoring and control.
• To develop a fuzzy logic algorithm to decide on the water quality conditions using MATLAB and SIMULINK.
• To develop a short message service (SMS) notification system based on Global System for Mobile (GSM) technology for alerting the user of any deviation in the water quality condition.
• To develop a web-based application for real-time monitoring of water quality parameters.
• To develop a prototype of the water quality monitoring and control system.
The rest of the paper is organized as follows. The next section focuses on the system design and overview, where the system architecture is laid out. The monitoring and control action of the different components of the system is also presented. This is followed by the fuzzy logic controller which is implemented in the processing of different water quality variables. The design algorithms of the proposed system are also shown. The next section demonstrates how the system monitors and controls water quality parameters. Results are shown to validate the system design. The last section concludes the paper.

Work study
The work study techniques of method study and work measurement are conducted at a manually operated water purification plant. The purpose of the work study is to determine the efficiency of the existing system and to ascertain the causes of delays in the purification process. The process flow chart for manual plant operation is shown in Table 1.
The reason behind the low efficiency can be attributed to process delays due to the time that is taken walking to and from the plant during sample collection, as well as closing and opening manually operated valves.

System architecture
The developed system consists of a microcontroller and multiple sensors for the measurement of temperature, pH, turbidity, dissolved oxygen, hardness, and dissolved solids for the detection of any deviations of the water quality parameters from the standard. Figure 1 shows the system architecture.
The Arduino microcontroller is responsible for storing and retrieving numerical data gathered from the different sensors and control valves as described below.
• Optical dissolved oxygen sensors work by measuring the interaction between oxygen and luminescent dyes after exposure to blue light (Sun et al., 2018). The sensor measures the altered wavelengths that indicate the presence of oxygen concentration.
• The pH sensor has a logarithmic scale whose range is from 0 to 14, with the neutral point being 7. A pH value above 7 indicates alkalinity, whereas a value below indicates acidity (Daigavane & Gaikwad, 2017).
• The temperature sensor monitors the coldness or hotness of the water measured in degree Celsius (Daigavane & Gaikwad, 2017). The operating temperature range varies between −55°C and 150°C.
• Turbidity sensor uses light to detect suspended particles in water by calibrating the light transmittance and scattering rate and it changes with the water quality of total suspended solids (Villa et al., 2019).
• Oxidation reduction potential (ORP) sensor gives a relative number of oxidizers and reducers in an aqueous solution. Oxidation reduction potential is measured as a voltage in millivolts (mV). The value of ORP is essential in monitoring the hardness levels in water (Ashraf et al., 2019).
• The total dissolved solids TDS sensor indicates the number of soluble solids (milligrams) dissolved in 1 L of water. The higher the value, the more soluble solids are dissolved in water, and the less clean the water is (Kitchener et al., 2017).
• The solenoid water valve is used to control the water flow direction according to the command registered by the controller.
The parameters that the system focuses on are dissolved oxygen, pH, temperature, turbidity, hardness, and total dissolved solids. The system collects real-time data and sends it via an internet controller (ESP8266 Wi-Fi module) to a web-based application (ThingSpeak). The host computer analyses, processes and presents the data, which is then sent to the user's mobile through a Global System for Mobile (GSM) SIM900 communication module by means of a short message service (SMS). Quality is tested at each stage of the water treatment process and any deviation from the World Health Organization (WHO) standard triggers an autonomous control measure according to a set of established rules. The decision-making process of the system is achieved through fuzzy logic control developed using MATLAB/SIMULINK. The system provides correction by incorporating automated chemical dosing units and multimedia filters.

System control logic
The system control logic monitors and controls any deviation of the water parameters from the stipulated World Health Organization (WHO) standards. The system flow diagram is shown in Figure 2.
The system consists of a microcontroller and multiple sensors for the measurement of water quality parameters. Data are analysed by the microcontroller, and the result is displayed on the LCD screen of the device. At the same time, another copy of the sensor readings is sent remotely to the user's mobile phone in the form of a short message service (SMS). A web-based platform is available for remote monitoring. A Global System for Mobile (GSM) module is used to provide a direct connection between system results and the user. If the water condition is out of specification, then an autonomous control measure is then carried out by using automated chemical dosing units and automatically controlled multimedia filters. If the specifications conform to the World Health Organization (WHO) standard, then water is allowed to flow to the next process stage.

Results and discussion
The monitoring and control action of the different components of the system is based on fuzzy logic reasoning. Fuzzy logic is a technique that characterizes and manipulates uncertain or ambiguous information, and allows a wide range of possible truth values to be processed through the same variable (Ross, 2005). The fuzzy logic controller is implemented to provide correction by incorporating automated chemical dosing units and multimedia filters. The technique is an innovative technology for designing solutions for multi-parameter and non-linear control models for the definition of a control strategy. It delivers solutions faster than conventional control design techniques.

Parameters monitored and controlled
Based on the WHO standards it was determined that the parameters to be monitored and controlled are temperature, pH, turbidity, dissolved oxygen, hardness, and dissolved solids. Interface modules Figure 1. System architecture. Chafa et al., Cogent Engineering (2022) Temperature, pH, and turbidity are the most critical parameters in water quality testing and relate to other water quality parameters. A change in one of the parameters will influence the outcome which is the water condition. It is important to note that of the three critical parameters, temperature is the least critical. For example, if the pH is good, then the temperature is not a factor that will influence the water quality. This is because temperature variations may be changing quickly due to fluid dynamics and ambient temperature conditions. Factors such as pH and turbidity are not affected by ambient conditions but define the exact conditions of water and the presence of any contaminants.

Fuzzy logic implementation
The set of input variables under test is dissolved oxygen, pH, temperature, turbidity, hardness, and total dissolved solids. They are fed into the control system. A comparison is carried out based on a set of fuzzy rules. The output is a linguistic variable that indicates the condition of the water. Figure 3 shows the fuzzy logic designer interface.

Fuzzification
Fuzzification is a mathematical procedure for converting an element in the universe of discourse into the membership value of a fuzzy set (Bisht et al., 2018). It divides the input and output variables into fuzzy region sets. The membership functions used for both the inputs and outputs are the triangular membership functions (trimf). Their membership parameters (a b c) represent their respective linguistic variables. This is highlighted by the parameter membership functions. If  Chafa et al., Cogent Engineering (2022) the measured parameter is out of limits, then the fuzzy logic controllers decide on the course of action depending on the set rules. The same applies to scenarios where the exact quantities of the parameters are established.

Fuzzy Rules
Fuzzy rules represent modelling knowledge or experience. The rules employed in the system are all given a weight of 1 and the connection employed is the "and" connector. Other variations are possible, the fundamental rule is that any combination is either of the parameters in this range: (1) (Temperature is Hot) or (2) (pH is Acidic/Alkaline) and or (3) (Turbidity is Bad) Any fuzzy rule set having any of the above conditions will generate a Recirculate command implying that the water condition is bad, every other condition implies a Pass condition. Table 2 shows possible variations in fuzzy rule sets or combinations and how they will be implemented.

Fuzzy inference
It is used in a fuzzy rule to determine the rule outcome from the given rule input information. The inference system is defined as shown in Table 3.

Defuzzification of output values
Defuzzification is a mathematical process used to convert a fuzzy set to a real number (Chakraborty et al., 2021). In the developed system, the centroid of area (COA) defuzzification method is used due to its wide acceptance and capability in giving more accurate results compared to other methods. Defuzzification, therefore, allows an output based on the measured input variables of the water parameters to be established.

Communication technology
The system provides instantaneous results and allows real-time monitoring and control through a wireless sensor network. A different technology is used in each of the communication scenarios,  that is, communication between sensors and controller, and communication with the user. These are explained in the following sections.

Communication between sensors and controller
The acquired data are verified and compared with the standard values of dissolved oxygen, pH, temperature, turbidity, hardness, and total dissolved solids as in the control code. The system collects real-time data and sends it via an internet controller (ESP8266 Wi-Fi module) to a webbased application (ThingSpeak). The host computer analyses, processes and presents the data, which is then sent to the user's mobile through a Global System for Mobile (GSM) SIM900 communication module by means of a short message service (SMS). The system results are displayed on the LCD as shown in Figure 4.

Communication with the user
A SIM900 Quad band GSM/GPRS module is used for data transfer. The notification system notifies the user of the water quality condition every time a measurement is carried out. The notification message sent to the subscribed user is shown in Figure 5.

Monitoring web application
The web server is observed on how it responds to changes in parameters in the field. Results under various conditions are shown on graphs and gauges on the application dashboard. Figures 6, 7 , and 8 show the monitoring dashboard. The system is being hosted at www.thingspeak.com.
In the field 1 chart, the pH remained constant for 5 minutes and then suddenly increased to a pH of 5. The increase is not gradual as shown by the rapid fluctuations from 14:40 to 14:45 hours. The pH dropped sharply to a pH of 1 and remained constant whilst fluctuating between 2 points of pH 1 and 2. The pH then increases sharply to a neutral value of pH 5. Field 2 chart represents temperature against time.
Field 2 chart shows the variation in temperature with time. The temperature remains constant for a short period at 22°C and dropped to 22°C in 2 minutes then remained constant over the testing period at 21°C. Field 3 chart represents turbidity against time.
Field 3 chart shows the variation of turbidity over time. Since major changes occur to the turbidity it remained low below 50 whilst recording fluctuating decreases over the time of testing. Figure 9 shows the gauge points.   The gauge points at the section indicating a Pass condition at the exact point in time. This means that the water quality parameters conform to the standard requirements and flow is allowed to the next process stage.

Development of the simulation model for water quality correction
The simulation model for the system is developed using Proteus 8 Version. The different components of the system are controlled by an Arduino-based microcontroller through interface modules. The recirculation valve opens to fill the main tank to a set point and closes once the tank is full. The pH meter then checks the level of pH to determine the corrective reagent required. In the case that the measured pH is acidic, the system will then check the level of the base reagent in the base tank using an ultrasonic-level sensor. When the base level is below the set point, an alarm system is triggered to allow the user to take action by filling the tank to the set point. At the set point, the base dosing pump switches ON allowing the base to neutralize the water in the main tank. This sequence also occurs for the cases where correction requires an acid reagent. When the standard level of pH is reached, the dosing pump switches off and the outlet valve opens to allow water into the process stage. The simulation runs according to the flow chart shown in Figure 10.

pH correction unit
The system consists of dosing pumps to allow the flow of correction reagents into the tank. A controller monitors the switching ON and OFF of the pumps according to the time specified and the pH level as measured by the pH sensor. An ultrasonic-level sensor also monitors the level of acid and base reagents in the tanks. If the level reaches a low level, the system alerts the user. An agitator allows the proper mixing of water and the applied reagent. The electronic circuit design is shown in Figure 11.

Multi-media water filtration system
The system consists of a multimedia filter arrangement and pipework design to purify water on one-way process flow. Filtered water from all filters flows through a common pipe. During the backwash process, the water level in the filter vessel falls such that the head in the filtered water stream is sufficient to provide the required backwash flow. Control valves open according to the process in action. Proper control of control valves provides the required flow direction as required by the process needs. The design consisting of pipe arrangement, control valves, and multimedia filters is shown in Figure 12.

Design of a prototype for water quality monitoring and control
Random test variables within the context of the study are used to check the system response to changes in field conditions. A working prototype is fabricated which is shown in Figure 13.

Conclusion
Internet of Things (IoT) is used to develop a real-time water quality monitoring and control system for a water treatment plant. The system provides instantaneous results and allows real-time monitoring and control through a wireless sensor network. A simulation model and a working prototype are also developed to demonstrate how the system works under different field characteristics. Every stage of the water treatment process is tested for quality, and deviations from the WHO standard triggers an   Chafa et al., Cogent Engineering (2022) autonomous control measure. Real-time monitoring and control of water quality improves water security. It eliminates the use of traditional water purification methods, which cannot monitor and control water quality parameters from the early stages. It also removes human interaction, eliminating time lost when water samples are sent to the laboratory for analytical testing, and the cost of offline testing. This solution contributes to the prevention of the spread of water-borne illnesses. The monitoring and control of water parameters produces the expected results of the study. The design principles used in this research can also be applied to other sectors such as water quality monitoring for the food and beverage, and aquaculture industries.