Raspberry Pi-based smart sensing platform for drinking-water quality monitoring system: a Python framework approach

. This paper proposes the development of a Raspberry Pi-based hardware platform for drinking-water quality monitoring. The selection of water quality parameters was made based on guidelines of the Central Pollution and Control Board (CPCB), New Delhi, India. A graphical user interface (GUI) was developed for providing an interactive human machine interface to the end user for ease of operation. The Python programming language was used for GUI development, data acquisition, and data analysis. Fuzzy computing techniques were employed for decision-making to categorize the water quality in different classes like “bad”, “poor”, “satisfactory”, “good”, and “excellent”. The system has been tested for various water samples from eight different locations, and the water quality was observed as being good, satisfactory, and poor for the measured water samples. Finally, the obtained results were compared with the benchmark for authentication.


Introduction
Drinking-water quality monitoring is essential before consumption in daily life, as it may affect human health directly or indirectly (Bhardwaj et al., 2018).As much as 80 % of illnesses are linked to poor quality water and sanitation conditions (Anan, 2003).The available water is severely polluted, and the situation may become worse in the future.Drinking water with pollutant concentrations exceeding BIS (Bureau of Indian Standards) limits is considered unsafe.The water quality is measured by different government agencies among 632 districts in India, which can be accessed by the IWT (India Water Tool) visualization tool (World Resources Institute, 2016).Among 632 districts, 59 are above BIS limits.The yellow and red areas in Fig. 1 indicate places where chloride, fluoride, iron, arsenic, nitrate and/or electrical conductivity exceed national standards.
Traditional water quality measurement techniques involve sample collection on site and subsequent laboratory-based chemical analysis, which is both labor-and cost-intensive (Korostynska et al., 2013).Also, the measurements are not in real time.Hence, to reduce the labor cost and time consumption, there is a need for real-time monitoring of water quality for drinking applications (Bhardwaj et al., 2015).The work presented in this paper aims to provide efficient realtime monitoring of water quality in drinking applications that can address the issues related to drinking-water quality for various natural resources, e.g., lakes, rivers, wells, etc.
The proposed work consists of a multi-sensor array (MSA) hardware platform along with a software platform (i.e., Python framework) and follows a three-stage approach.In the first stage, MSA was designed that consists of an array of commercially available individual sensors for water quality parameters.The selection of the parameters is based on the guidelines of the Central Pollution and Control Board (CPCB), New Delhi, India (Central Polution Control Board, 2007).In the second stage, the hardware platform was designed based on the Raspberry Pi board.An additional serial port expander was used, since Raspberry has only one I 2 2C channel and communicating with all the sensors simul- taneously was required.In the third stage, a graphical user interface (GUI) was designed for the human machine interface (HMI) and fuzzy modeling in Python.The water standard was defined based on calculated water quality parameters using the fuzzy inference system (FIS), since FIS has the capability to absorb vagueness related to observed parameters.The fuzzy approach reported in this paper has been used and discussed widely in many environmental applications; this helps in decision-making in many real-life complex problems (Lermontov et al., 2009).
Many researchers, such as Ponsadailakshmi et al. ( 2018), Tiri et al. (2018), Raman et al. (2009), Jinturkar et al. (2010), andIcaga (2007), have implemented the fuzzy modeling in MATLAB for water quality index calculation.However, the process of modeling was offline, whereas in this paper we implemented the fuzzy approach in real-time calculation, after the data collection, with the help of libraries in the Python framework.

Water quality parameter selection criteria
The Central Pollution and Control Board (CPCB) suggested criteria of water quality parameters for different usage of the water.CPCB has decided on five different categories for the use of water in different applications such as irrigation, drinking, bathing, etc.In this work, category "C" parameters are considered, since we are targeting the drinking-water source after conventional treatment and disinfection.

Defining water quality
The fuzzy inference system (FIS) can include vagueness in decision-making and reasoning.Hence, techniques based on fuzzy logic have proved very useful, since they are less mathematically intensive than neural networks, genetic algorithms, etc., and they support approximate reasoning as well.In FIS, knowledge is presented as linguistic rules.The inputs are converted from a crisp value to linguistic variable by the process of fuzzification, and these variables are fed to the inference system.This interference system gives a new set of a linguistic variable which is then converted to a crisp value with the help of defuzzification (MathWorks, 2018).The process to design fuzzy thus involves three necessary steps: (1) define the membership function for each variable, (2) perform fuzzy inference based on the inference method, and (3) select the defuzzification method to determine water quality.
The proposed fuzzy logic was implemented in Python with the help of a library developed by the SciKit-Fuzzy development team (Anon, 2018) to define the water quality from groups of five linguistic variables defined as bad, poor, satisfactory, good, and excellent.The fuzzy system uses the Mamdani implication model, which takes five inputs: pH, electrical conductivity (EC), oxidation reduction potential (ORP), dissolved oxygen (DO), and temperature.The Mamdani FIS produces a more accurate response than the Takagi-Sugeno type model, since it uses the centroid method of defuzzification.The defuzzified output of the model is water quality, which corresponds to five inputs of the model.In this paper, the Mamdani-type FIS model was implemented for the decision support system, since it has a spontaneous and rule-based capability of decision-making.The modeling was performed based on five input parameters and one output parameter to determine the water quality.The selection of the membership function was done based on the complexity of the system considered for decision-making.Triangular membership functions (MFs) are most commonly used membership functions because of their linear nature and ease of implementation (Zhao and Bose, 2002;Kosko, 1993).Hence we have selected a triangular MF to fuzzify the crisp variable into a linguistic one.The triangular membership function depends on three parameters, l, m, and n, and are given by Eq. (1): (1) The logic operations used in the fuzzy logic are min, max, and complement, and these are defined by the Eqs.( 2), (3), and (4) respectively.A and B are two subsets: (3) (4) After the logic operations, the "if-then" rule was applied.All the rules were applied in parallel, and the rule which did not affect the output was ignored.The outputs of all rules were then aggregated, and all fuzzy sets that affect the output were combined into a single fuzzy set.Finally, the fuzzy set was converted into a crisp set through defuzzification, in which a single number was generated.There are several methods for defuzzification, such as the centroid, maximum, mean of maxima, height, and modified height method.In this work, the centroid defuzzification method was used, which is the most popular method.The output was calculated by averaging individual centroids, weighted by their heights as given by Eq. ( 5) (Zadeh, 1988): where µ(u i ) is the min and max value of the membership degree of the input values (depends on min and max operator).
In this paper, we have assigned two groups to each water quality parameter, which are desirable (DES) and undesirable (UNDES), as described in Table 1.If the parameters are in the desirable range, then only fuzzy has been applied; otherwise it is not applied.For example, if the pH is in the range of 6.5 and 8.5, the assigned group is DES; similarly if pH < 6.5 or pH > 8.5, the assigned group is UNDES.In the same way, the group is checked for all five water quality parameters.After checking the desirable group, the individual membership function is assigned to each parameter.Also, we have defined the membership function for water quality on the scale of 0 to 100.After assigning the membership functions, the if-then rule was applied and overall quality was defined based on adopted rule-based formulation.

Hardware platform design
The hardware platform plays a vital role in any system development since data acquisition, and data processing is done with the help of the hardware platform itself.The main task of the hardware platform design is MSA design and its interfacing with the Raspberry Pi board followed by the Python framework.The details of the design are given below.

Multi-sensor array (MSA) design
For the proposed work, an MSA is designed using the industrially manufactured sensors from Atlas Scientific, USA.The individual sensors are arranged in an array form to make the MSA.The sensors used are a pH sensor, electrical conductivity (EC) sensor, dissolved oxygen (DO) sensor, oxidation reduction potential (ORP) sensor, and a temperature sensor.The total dissolved solid (TDS) parameter was derived from EC.

Integration of MSA with Raspberry Pi board and interfacing with Python
Once the MSA is designed, it must be coupled with the Raspberry Pi for data acquisition and further data processing.Bhardwaj implemented water quality monitoring based on the cyber-physical system (CPS) using an Arduino Uno board (Bhardwaj et al., 2018).Although Arduino is userfriendly, the reason for selecting the Raspberry Pi for this work is its computational capabilities, which cannot be reached in the Arduino platform.Apart from its computa- tional capabilities, the Raspberry Pi is bundled with an inbuilt Bluetooth and Wi-Fi module, an HDMI interface, a camera interface, a display slot, an SD card slot, a USB slot, etc.; all of these must be interfaced externally when using the Arduino platform, depending on the application.
For stand-alone applications, a display panel can be interfaced it with the Python framework.We have used a 7 in.touchscreen and interfaced it with Python programming.
Python is an open-source programming platform that supports data processing and computing.The only drawback that we are facing with the Raspberry Pi board is a limited number of I 2 C channels, so we have interfaced an external serial port expander with the board to enhance the number of I 2 C channels.The experimental setup of the MSA integrated with the Raspberry Pi board is shown in Fig. 2. It includes the MSA connected to a serial port expander and a Raspberry board followed by Python programming.

Experimental procedure
The proposed system has been tested for water samples from five different locations.To get accurate readings, each sensor node was calibrated before the measurement.The calibration was performed with the reference solution given for each sensor.Initially, the measurement iteration was carried out for at least 5 min so that sensor reading became stabilized because the original readings must be recorded only after the sensor attains stability in order to make any conclusive decision out of data.The system was tested for a total duration of 21 h over 7 d.The average values of the experiment for all locations are shown in Table 2. Locations 1 to 5 are the drinking-water samples from the distribution networks, and the samples from the locations 6 to 8 are the simulated sensor readings.This was done to validate the sensor readings, as the acquired results from the distribution networks are in real time, and hence sensor readings have not much variation within the desirable range.All the targeted parameters were measured through the developed setup as well as from the commercial water quality monitoring system.The results obtained from MSA were accumulated through the fuzzy inference system implemented in Python framework.The water quality defined by the fuzzy model is shown in Table 3.The water quality is good for locations 1, 2, 4, and 5 in the distribution network and satisfactory for location 3.For locations 6 to 8, the water quality is poor.

Interactive user interface
The graphical representation was provided for real-time data obtained from various sensors with the help of the GUI platform for the interactive HMI.An interactive GUI has been designed in the Python framework with a touch interface, as shown in Fig. 3.The touch interface is provided for the ease of operation for the operator.In the GUI, the operator can select the measurement from the menu, whether it is an individual parameter or the overall water quality, with a single touch.The acquired data were kept for future use by saving them in a memory drive provided with Raspberry board.The live plotting of data is shown in Fig. 4. The x axis represents time, and the y axis represents the sensor node reading.

Validation of sensor readings
To measure the accuracy of the developed system and for the authenticity of the results acquired, the proposed system was compared with the available benchmark equipment, the YSI EXO-1 sonde monitoring system, and the percentage relative error (PRE) was calculated (Lee, 2016).PRE expresses the error in percentage to determine the accuracy given by the following formula: The calculated PRE is presented in Table 2 for all the samples, and the graphical representation is shown in Fig. 5.The x axis shows the different locations, and the y axis displays the corresponding calculated PRE.For all the acquired water quality parameters, the PRE lies in between 0 % and 2 %,  except EC, which is in the range of 0 % to 3 %, thus showing the good accuracy of the sensors used.Based on the results of the parameters obtained from MSA, water quality has been defined for all the locations using fuzzy libraries as shown in Table 3.The input and output membership functions were

Performance comparison with existing work
Many authors have also designed a water quality monitoring system.Taru developed the system for water quality monitoring using an Arduino Uno board and LabVIEW (Taru and Karwankar, 2018), in which three water quality parameters (temperature, turbidity, and pH) were measured, and the GUI was developed in LabVIEW, which requires a PC.Salunke developed a smart sensor interface for water quality monitoring in the IoT environment, in which only two water quality parameters (pH and turbidity) can be measured (Salunke and Kate, 2017).Bhardwaj has developed the water quality monitoring system in which there was no GUI (Bhardwaj et al., 2018).Rahmat designed the real-time monitoring system for water pollution (Rahmat et al., 2017).However, in this paper, the focus is on the drinking-water quality monitoring system.Also, we have developed the GUI in the Raspberry Pi board as an independent system which does not require any PC, and more than three water quality parameters can be observed from the developed system.The added value of the developed system in relation to standard monitoring is its development cost.The developed system costs us less than USD 1000 as compared to the benchmark, which costs approximately USD 11 000 .

Conclusions
Water quality monitoring is essential before consumption, and real-time monitoring will reduce the risk of illness in human beings.Traditional methods for water quality monitoring are being replaced by online water quality monitoring.In this paper, the design and development of a smart sensing platform for drinking-water quality measurement is presented.The proposed system consists of a Raspberry Pi board integrated with a multi-sensor array, a 7 in.touchscreen, a keyboard, and a mouse.Unlike the used benchmark, the proposed system is low-cost, as discussed in the earlier section.A software panel is also developed for the interactive user interface.The developed user interface can help the end user to operate the system efficiently and make decisions based on the result displayed on the screen.The fuzzy de-cision employed in this paper is an efficient way to detect drinking-water quality in real time, as compared to manual approaches.
In the future we plan to implement the system enabled with the internet of things (IoT) for online drinking-water quality monitoring in the distribution networks.At present, the calibration of the sensors is time-consuming and requires a specific amount of time to be stabilized.Hence in the future, the focus will be on the auto-calibration of the sensors and the drift analysis and compensation of the sensors using different regression algorithms.

Figure 5 .
Figure 5. Percentage relative error (PRE) plot for different water quality parameters.

Table 1 .
Groups defined for water quality parameters.

Table 2 .
(a) Average values of samples for pH, DO, and EC and their calculated PRE.(b) Average values of samples for ORP and temperature and their calculated PRE.

Table 3 .
Fuzzy water quality for all locations.
implemented in MATLAB.The same has been used for the validation of the fuzzy model implemented in Python.