Low-cost wireless sensor network applied to real-time monitoring and control of water consumption in residences

The objective of this work is to explore the implementation of a low-cost real-time monitoring and control of water consumption together with a user feedback interface. Water usage information will be available in a cloud storage and can be accessed through a mobile application. The collected data allows access and supervision of both clientand water concessionaire. Project feasibility is analyzed in terms of hardware and software, as well as each element required for the design. The simulations were carried out with the purpose of verifying system operation, considering the following metrics: transmission rate, signal strength and transmission quality. After the simulations, the hardware and software were integrated, and the final result was presented through a mobile application. This work presents and applies a design and development methodology of Wireless Sensor Network (WSN) using Internet of Things (IoT) technologies and Smart City in water-distribution systems.


INTRODUCTION
The water supply in Brazil is a recurring and worrying theme not only in the dry season but also during the whole year in certain regions. Due to the deficiency of the last years and to the decrease of the water level in the dams, the water supply has become a serious problem. To make matters worse, water loss is very high. According to the SNIS (2019), in 2016 the state of Minas Gerais lost 34.47% of revenue due to water loss, leaks, robberies, clandestine connections and measurement errors. In Brazil, this average total value was 36.24%, which represents a loss of over R$ 8 billion. For instance, the northern area of Minas Gerais, in the city of Montes Claros, Brazil, was forced to endure several periods of shortage, some of them interrupting water distribution for two days (COPASA, 2019), causing several hardships to city residents. According to a United Nations report (UNESCO, 2015) and Christofidis (2003), if current water supply and distribution conditions are maintained, 70% of the planet's inhabitants will face deficiencies in water supply, and a quarter of the population suffer chronic shortages of drinking water.
The shortage of natural resources is a constant concern of environmentalists, government, institutions and companies who also wish to reduce expenses, in addition to the environmental factor. For this reason, programs to reduce losses and raise awareness about the use of natural resources are a constant theme in the country's affairs. Silva et al. (2016) presented a study to describe the technologies developed by Embrapa, a public agricultural research institution, for the rational use of water in irrigation systems of Brazil. The majority of them are related to knowledge and techniques, such as personal training, construction of small dams, collecting rainwater, etc. Some technologies featured in the work of Silva et al. (2016) use software to check the crops and farms, but the use of new IoT and Smart City concepts are not largely applied yet.
The use of IoT technologies brings new possibilities to measure and predict water consumption and to store data about how water is being used. These data can help water concessionaires foresee problems such as leakages or robberies faster, and thereby avoid losses. This large amount of information will be stored in the cloud, so it can be used as input for statistical studies or in machine-learning applications. Further, online feedback information would help to establish better practices. The work of Tom et al. (2011) illustrates how important it is to have real-time consumption information with easy access for residents. This research reports that households that received data loggers feedback from daily consumption had a significant improvement in reducing consumption compared with those who received weekly advice from a professional at home. Based on these findings, this work proposes the use of the Wireless Sensor Networks (WSN), Smart City and IoT concepts to perform individual monitoring with online feedback and control of water consumption in residences through an Android mobile application, with excessive-expense or leak-warning tools.
A recent report in Saravanan et al. (2018) has illustrated a SCADA system to measure water flow, temperature and turbidity. The data is sent to a web server that performs analytics to show water conditions to the user but, in this case, using GSM technology may not be the best choice due to the high operational cost and power consumption. Riis (2016) also proposed the installation of the SCADA software with PLC and Fieldbus/Ethernet communication in control points of the water company supply; but despite being a robust option, it is expensive and the solution does not include domestic water monitoring. Gupta et al. (2018) proposed a water-quality monitoring system using Raspberry Pi module with integrated WiFi network, which depends on WiFi signal to send information to the cloud. Other similar researches in several applications are proposed by Kim et al. (2008) Zin et al. (2019). This paper proposes the new IoT solution for domestic water-consumption monitoring with the use of the Zigbee technology. This system was developed to operate in low-cost and low-power conditions to build large WSNs, through mesh network, capable of sending data to the cloud and providing the user the possibility of having online information through a mobile app. Water consumption will be on display, and the user can take action when necessary. Although the only parameter measured is the water flow, for power consumption optimization, the system can easily be modified to accept many others; when the microcontroller can handle it, the software need only be updated to receive the new parameters.
The "Materials and Methods" section of the paper shows the hardware and software design. The "Results and Discussion" section presents prototype testing. Finally, the "Conclusion" section concludes the study. Figure 1 shows the schematic of the water consumption monitoring system with the IoT technology and Smart City concept. The system includes Sensor Nodes, responsible for measuring domestic water consumption through a flow sensor and transmitting the collected data through a Radio Frequency (RF) module to the Base Station, which will collect this data and send it to the cloud through the gateway. The system will also be able to detect leakage by setting volume limits configured in the app. The user will be able to close the valve water remotely. Rev. Ambient. Água vol. 14 n. 6, e2407 -Taubaté 2019

MATERIALS AND METHODS
The Coordinator Node will be responsible for receiving the data from the Sensor Nodes and transmitting them via serial communication to an application or program that will be running on a mobile device or computer. This application will be responsible for processing the data and sending it to the network gateway. Once this data arrives at the gateway, it is transmitted to the Internet via Ethernet and stored in the cloud, so it can be accessed from anywhere and at any time through mobile applications or web pages. This data may also be sent to the water concessionaire server, so they would have access to it and could manage the entire water distribution system. The water valve closing procedure can be carried out remotely only by the concessionaire if wanted, e.g., in case of non-payment. This criterion is a strategicpossibility feature since it is technologically available.
The set established by the Node Coordinator, Application and Gateway is called the "Base Station", because all the data will arrive there and be transmitted to the cloud. The Base Station can be placed in a street-light pole, where the device can be powered. Furthermore, it will preferably be located in a central network region so that the sum of the distances between the Sensor Nodes and the Base Station is as small as possible.
The use of ZigBee protocol in the communication between the sensing points and the Base Station was chosen because the technology is developed for low-power applications, and it is able to implement a network of more than 10,000 nodes with topology mesh. For instance, if a communication point is lost, the network will immediately reroute this data to reach the Coordinator Node.

Hardware
The Base Station consists of an RF-communication module, which is the Coordinator Node, connected to a computer or device with Internet-access capability and a gateway. The data will arrive via RF to the Coordinator Node and will be transmitted to the computer USB port using serial communication. Once this data arrives at the computer, it is sent to the cloud through the application developed using Javascript language and the Firebase platform, a Google-owned company that offers cloud service for mobile-and web developers (FIREBASE, 2019). The Sensor Node, which is responsible for sending the data flow to the Coordinator Node, is formed by the following: a processor unit,that processes data information from sensors and commands from user; a sensor unit that transforms water-flow data into some signal that can be read by the microcontroller; a transmitter module that transmits information via RF; and a power source, the energy supply. An enclosure with dimensions of (6x8.5x4) cm is used to pack those devices. Below, we show the sensor node configuration: The Xbee module hardware was chosen due to the Wireless Sensor Network applications, small size, low cost and the fact that it operates with the ZigBee protocol. It has an average communication-distance range large enough to communicate between neighboring houses in an urban environment.
Regarding the Sensor Unit, there are two approaches for water-flow measurement: the inline-direct flow, which is intrusive, and the non-intrusive flow estimation. The first approach needs direct contact with the water while the second does not, which is better with respect to Rev. Ambient. Água vol. 14 n. 6, e2407 -Taubaté 2019 installation but not as good with respect to price and calibration. Table 1 shows these characteristics for the main water-flow sensors used in the literature review. Based on cost, installing and calibration complexity, the flow sensor with hall effect was chosen. The sensor has a propeller that rotates as water passes through it. This propeller has a magnet on one of the blades, responsible for generating the magnetic field that passes through a semiconductor inside the sensor. Consequently, it generates a square wave voltage signal the frequency of which is proportional to the propeller´s rotational speed, i.e., the higher the waterflow rate the higher the pulse frequency. The Pulse Rate versus Flow Rate is provided by the YF-S201 sensor Datasheet. The linear relation flow (y) and frequency (x) is represented by Equation 1.
= 0.121 + 0.025 (1) Tests for obtaining data throughput, signal quality and signal strength were performed with the Sensor Node near the hydrometer box, located outside the residence, and the Base Station, located inside, in the residence room. Results are shown in the next chapter. Figure 2 shows the software overview operation with the respective routines of each program. The first part, (1), depicts the Sensor Nodes capable of communicating with each other, so that the information reaches (2), the Coordinating Node, which will receive the data and address from (3), the computer, through serial communication. Parts (2) and (3) pertain to the Base Station of the system; in part (3), the computer will process the information through an application, which will send the received data to the cloud (Internet).

Software
After that, an application was created using the Android Studio® development platform, so that any user, from anywhere, with a cell phone and internet, could have access to the information (5). It should also be noted that the information could be sent in the opposite way, when the user or concessionaire sends commands to the Sensor Node to close or open valve. In this case, the command information starts from the mobile, (5), to go to the cloud database (4); the application in (3) identifies the receiving information in the cloud; it retrieves this information that will be sent to the respective Node Sensor (1) destination. Each network device has its own and unique MAC address that is sent within the transmitted data and used for identifying the source and destination device packet.  Figure 3 shows the Sensor Node installed for system transmission and accuracy testing. In the figure we can identify the processor unit, sensor unit, the transmitter and power supply. The testing was performed by placing one Sensor Node near the hydrometer, outside of the house. The Base Station with the Coordinator Node was located inside the house, in which the estimated distance between the Coordinating Node and the Sensor Node is 8.5 m, in a straight line, with three physical barriers. First, to verify RF transmissions, a test was done by Rev. Ambient. Água vol. 14 n. 6, e2407 -Taubaté 2019 sending and receiving 100 packets of 255 bits (maximum packet size). The result was zero packet loss; the signal strength was -27 dBm, which corresponds to approximately 2 μW, knowing that the receiver sensitivity is up to -96 dBm (0.25 pW) (DIGI, 2019), the minimum value for transmission to occur.

Hardware
After this first step, the second was measuring water-flow transmission data. Information was sent with 1-second intervals. Each packet sent from the Sensor Node to the Base Station had the maximum size of 232 bits. Thus, the maximum transmission rate was 0.232 kbps, much lower than defined by the maximum limit of the RF transmission module, 250kbps, and 100% of the data was transmitted without presenting problems related to packet loss and transmission distance.
The third and final step consisted of doing a comparative between the water flow manually measured and water flow automatically measured by the Sensor Node. For manual measurement, a container with a fixed volume of 2L and a stopwatch was used. First, the Sensor Node was installed in the hose that would also fill the container. The valve was opened and it was timed for three different flows (the flow was controlled by the opening of the water valve). The flow value is obtained by dividing the volume (L) by the time (s) and converting that unit of measurement to L.min-1. At the same time, the data was also sent by the Sensor Node to the application that calculated the flow and saved it in the data cloud. The results showed errors less than 5% after the sensor calibration.

Application
The left side of Figure 4 illustrates the screen of an Android mobile emulator running the developed application; the right side displays the application already installed on the phone and running. This form will inform the user of the current water consumption, the accumulated consumption of the day and of the month. In addition, the user will be provided with the value of his water bill, in which this data can be monitored and compared with that of the Water Supply Company. The water rate is defined by the Water Utilities and it is public-domain information.
In order to decrease water consumption, the application can be configured so that the user chooses the maximum consumption value per day or per month. When this value is reached, a message is generated to alert that the value has been exceeded.

CONCLUSIONS
This work proposes a low-cost real-time monitoring and control of water consumption together with a user feedback interface. A methodology was developed and implemented based on WSN and IoT technologies. Tests and analyses were executed to prove the system's functionality. RF transmissions presented good performance with a maximum data rate of 250kbps, much greater than the need for water-flow data, which is 0.232 kbps. There was no package loss during tests and a signal strength of -27 dBm was reached. After some corrections on the linear relation between water-flow sensor pulses and the expected water flow, the consumption water volume reached errors less than 5%.
Among the advantages of this system are the low operational-and implementation costs, modularity, the mobile app and the use of cloud data, allowing real-time access to the readings and throughput values that can be used in the future as statistical data. Besides that, by using a standardized communication protocol, such as Zigbee, the Firebase and the Android Studio platforms, allows greater interoperability and system robustness.
As future works, we suggest the implementation of a network in a neighborhood or urban area, with the use of as many Node Sensors as possible to check its performance on a larger scale. The suggested solution can also be used with other sensors to measure different parameters, such as water quality and temperature, in order to obtain more information about its use. Energy harvesting is another direction that may be explored to make these IoT devices autonomous in terms of energy supply.