Smart Systems for Monitoring Buildings - An IoT Application

. Life in society has initiated a search for comfort and security in social centers. This search generated revolutions within the knowledge about the technologies involved, making the environments automated and integrated. Along with this increase, ecological concerns have also arisen, which have been involved since the design of intelligent buildings, remaining through the years of their use. Based on these two pillars, the present study aims to monitor three central systems inside the apart-ments of the Apolo Building (Bragan¸ca city, Portugal). The electrical energy consumption, water flow, and waste disposal systems are integrated through a single database. The data is sent remotely via WiFi through the microcontroller. For better visualization and analytics of the data, a web application is also developed, which allows for real-time monitoring. The obtained results demonstrate to the consumer his behavior regarding household expenses. The idea of showing the consumer their expenditure is to create an ecological awareness. Through the data collected and the environmental alternatives found, it is possible to observe whether there was a behavior change when receiving this data, either in the short or long term.


Introduction
As life in society advanced, the need to create spaces that brought more comfort and safety became a priority [1]. To centralize social spaces, of either economic activities or residences, buildings were created to become the center of activities.
The first centralized control equipment appeared primarily in-room acclimatization equipment. With the greater dissemination of microcontroller processes, there was a high expansion in the control processes, which allowed the supervision and control of more developed equipment in larger quantities. But it was in the 80s, with the increase of the necessities to improve workplaces, bringing more comfort and safety to the environment, telecommunications services, and flexibility of workplaces that contributed to the emergence of the three pillars for the intelligent building system, these being: automation, telecommunications, and computing systems [1].
The term "smart" generated confusion in the designation of intelligent buildings because it induced people to have unreasonable expectations for these constructions. Due to the economic reality and the unfamiliarity of the users with new technologies, these expectations were frustrated, reducing the number of specialists, proliferation of brands and equipment, and appearing, in a way, a negative association to the term [1].
Although the presented work does not intend to classify or determine terms related to the field of intelligent buildings, a brief history related to the theme will be discussed in Section 2. The work focuses on collecting data regarding the systems of electric energy consumption, waste disposal, and water flow per apartment to create a database for developing future consumer awareness applications.
The remainder of the paper is organized as follows: following the introduction are the works related to the present development in Section 2. Next, Section 3 presents the description of the systems involved and the communication and data storage. Section 4 demonstrates the prototypes' developments and results. And finally, Section 5 concludes the results and points to possible future work.

Related Work
This section is dedicated to making a brief summary of the main works related to the systems that will be used in this project. Initially, in order to contextualize it, studies about the definition of smart buildings were also discussed.

Definition of Smart Building
The search for a definition of the smart building has always been accompanied by polemic. According to research conducted by Wigginton and Harris [2], there are more than 30 definitions of intelligent when related to buildings. In order to centralize, support, and promote issues related to intelligent buildings, the Intelligent Building Institute (IBI) organization was created in 1986 in the United States of America. This institution defined a concept restricted to the branch of the enterprise, being an intelligent building defined by [2]: A building that provides a productive and cost-effective environment through optimization of its four basic elements -structure, systems, services, and management -and the interrelationship between them. Intelligent buildings help business owners, property managers and occupants to realize their goals in the areas of cost, comfort, convenience, safety, long-term flexibility and marketability.
In contrast to this definition, the UK-based European Intelligent Building Group defines it as [2]: One that creates an environment which maximizes the effectiveness of the building's occupants, while at the same time enabling efficient management of resources with minimum life-time costs of hardware and facilities.
According to [3], the need to search for an exact definition for intelligent building s critical when "new building will not be optimally designed to meet the next century". Some more recent publications, such as by Yang and Peng [4], have added to the concept of intelligent building the "learning ability" and "performance adjustment from its occupancy and the environment".
The research developed by Wong et al. [5] sought to conduct a comprehensive review of the concepts and definitions of intelligent building, taking on some important directions for research related to intelligent building investment.
It is worth mentioning that it is explicit that an intelligent building will be the one with more integration between systems and not necessarily the one that is more automated. The integrated systems may be related to building infrastructure, automation of systems and integrated control, and management and maintenance of the whole system. In [6], it is pointed out that since there is no correct definition for intelligent building, the most sense, in her view, would be to classify buildings gradually according to "degrees" of intelligence, where: A determined building as having basic intelligence (25% automation of the systems), moderate intelligence (50% automation of the systems), or sophisticated intelligence (over 80% automation of the systems).

Monitoring Systems
In [7], the main systems to be monitored for the human comfort standard are listed. They are generally classified within temperature, luminosity, and hearing to air quality (i.e., CO 2 level). Based on this, in [8], a system for monitoring the parameters of luminosity, temperature, relative humidity, and air quality was developed to ensure a service, according to them "intelligent, safe, and comfortable to live".
Thus, to obtain increasingly efficient buildings, the principal goal of automation was to make the processes involved efficient [9]. Specifically, energy efficiency is a concern when associated with smart buildings due to the costs and ecological care [10]. According to the Journal of the European Union [11], buildings account for 40% of total electricity consumption. This worry runs through all stages, from the building's design, construction, and usage. The optimization of electricity use must be monitored and goes through process control, applying improvements continuously at the points that lag behind.
The monitoring of energy consumption can be done through Hall Effect type sensors. These sensors can measure both DC and AC without the need for intervention between the monitoring circuit and the power circuit to be monitored. Hall Effect is the principle whereby a magnetic field passes perpendicularly through a rectangular conductor with current flow. As a result, electrons are deflected towards the ends of the conductor, generating a voltage known as Hall Voltage, the output voltage of which is proportional to the magnetic field in which the sensor is exposed [12].
Water efficiency has also become important as part of the ecological process surrounding intelligent buildings. According to World Water Development Report (WWRD), the immediate concern is its availability and management of it [13].
The work developed by Teixeira [14] aimed to develop a system that allows the certification and labeling of water efficiency, providing the consumer with knowledge about it. With the application of water efficiency measures to his case study, there was a 63.9% reduction in water consumption.
With the Internet of Things (IoT) technology, the waste management system has evolved in developing smart cities with Smart Waste Management (SWM), covering everything from monitoring the containers to planning the route taken to collect them. The work developed by Cerchecci et al. [15] proposes optimizing waste management by monitoring the capacity of dumpsters. The system uses LoRaWAN [16], and the measurement is made by an ultrasonic sensor, which is coupled to a Raspberry Pi board that sends the data to a central analysis. In real-time, the waste collection route is planned according to the quantities of waste garbage cans. It was observed that with these techniques applied, there was a reduction of 18% in the collection time, and the waste policies were optimized in the long term.
In [17], a temperature and humidity monitoring system was developed using low-cost sensors and ZigBee communication. The system can communicate with the smartphone by an Android application through a Raspberry Pi-based host and the STM32L100RCT7 microcontroller, with a power consumption of only 0.5W.

Internet Of Things
The implementations of the monitoring systems were based on IoT technology. The term, which appeared in 1999 disseminated by researcher Kevin Ashton, with which the technology of integration between inanimate objects became known, allowing communication, transmission, and execution of various functions [18]. The root of this term is directly linked to the developed study of RFID (Radio Frequency Identification) technology. In [19], we see that IoT is not derived from technologies but uses them to fulfill functionality.
According to Debasis and Jaydip [20], the IoT system is a network of physical objects and virtual devices that can communicate with each other. Thus, it is possible to highlight that the IoT is responsible for generating multidisciplinary connectivity between professionals working on the system project, whether in hardware or software, allowing the construction of a quality and safety system [21]. For Ma [22], the increasing evolution and growing complexity involved in IoT technology bring challenges such as heterogeneity, device availability, exorbitant amounts of data, and security and privacy.

Wireless Sensors Network
In [23] Wireless Sensors Network (WSN) is defined as a self-configured network capable of monitoring physical or environmental conditions through sensors that have a centralized database where data can be observed and analyzed. The system can consist of thousands of sensors, where sensor nodes can communicate via radio signal [24,25]. According to [26], the WSN is divided into a hardware part, composed of a low-power embedded processor, memory, sensor with ADC units, radio transceiver, location finding system, and power supply, and another part for software, composed of operation system microcode, sensor drivers, communication processors, communication drivers, and data-processing mini-applications. Thus, one can characterize the WSN as a system consisting of sensing, computing, and communication between devices at a single network node. This centralization allows the measurement, data storage, and control of the systems involved.
In [27], a software application capable of communicating with a raw hardware system consisting of Magnetic Target Switch (MTS) sensors plugged into Processor and Radio Modules (MPR) is proposed. The TinyOS application developed "to support the concurrency-intensive operations required by networked sensors with minimal hardware requirements". In [28], WSN was used as a solution for energy management, with the data being visualized through a web application, which also allowed control of the devices involved in the system.

System Description
The proposed system in this work integrates three main sensors that transmit data via WiFi through the ESP32 microcontroller to a database in InfluxDB. The sensors are used for monitoring water flow, and waste discard (YF-B2, and load cell, respectively). Additionally, an IoTaWatt is applied to monitor electric energy consumption. For better comparisons between the data collected in the mentioned systems above, sensors were also added to monitor the local temperature and humidity, DHT11. The system architecture can be simplified as shown in Fig. 1. Each sensor's choice focuses on monitoring the basic usage of a regular apartment. This way, it is expected to find a correlation between each parameter. The used sensors are described throughout this section.
Energy System Based on the operation of the Hall Effect, equipment from the company IoTaWatt [29] was installed in the system to be monitored. This equipment has a wall transformer that converts the local voltage to a standard reference voltage, allowing the line voltage and frequency to be determined. The transformer is capable of reading up to 14 different circuits with passive clamptype sensors, i.e., it is not necessary to interrupt the cables to insert the sensors. Data storage can be done locally or remotely. The device also has its web server, where it is possible to monitor the system in real-time and remotely. For the case study in question, the configuration performed in the equipment allowed data to be sent directly to the project's database. Fig. 2 shows the communication interface and the equipment already allocated for the testing phase.
The choice of measuring this parameter is to make hypotheses of energy consumption with external factors. For example, does temperature increase/decrease affect energy consumption? If yes, then by how much? And how can be this discerned if it was caused by an increase of people or temperature in the apartment?
Water System The flow rate monitoring system will consist of a YF-B2 sensor [30]. This sensor is composed of a copper metal body, water rotor, and Hall effect sensor. As the speed at which the water passes through the rotor varies, the Hall sensor sends out pulse signals corresponding to the flow. To convert these signals, These signals are read by the ESP32 microcontroller and converted to the flow rate in liters per minute.
The YF-B2's small size makes it easy to install, making it possible to install it in 1 2 " pipes. Its operating voltage ranges from 5-15V, and the maximum operating current is 15 mA. The flow rate reading is 1-25 L/min, with a liquid temperature capability up to 120 • C. It is worth noting that the external operating temperature of the sensor is limited to 0-80 • C. As the building where the system is being developed already has the hydraulic part finished, it is necessary to have the sensor installed by a professional. At the time of this publication, this installation was not possible, and for this technical reason, the approach to this sensor will not be the focus of the work presented here. The electronic connection between the sensor and the microcontroller is shown in Fig. 3  As with the other systems, the purpose of measuring the flow rate is to create relationships between environmental data and consumption, such as the difference in water consumption in different seasons, hence different temperatures of the year, and show how these variables are related.
Waste System To analyze the quantities of garbage discarded in the residence, a system to measure the weight of the garbage drums was implemented. This measurement is made through a load cell attached to a generic base, where any waste basket can be placed on it.
The types of load cells can be characterized by their output signal (pneumatic, electrical or hydraulic) or by the principle of weight detection (bending, tension, etc.). Its operation consists of a resistors bridge that was developed in 1833 by Samuel Hunter Christie, but was named the Wheatstone Bridge after its diffuser Charles Wheatstone.
The load cell used in this work acts by changing the electrical resistance of the signal as the applied weight generates physical deformation on the plate, with a maximum supported weight of 5 kg. The signal is read via the HX711 load cell amplifier and acquisition module, which sends the data to the ESP32 microcontroller.
For this system, the purpose of measuring waste disposal goes beyond having weight data. It is necessary to evaluate the relationship between the waste disposed and, for example, the increase in temperature or energy consumption. The goal of this study is to create these relationships between the monitored consumption and to analyze the behavior patterns with the changes associated with temperature, humidity, season, visits to the apartment, and other changes.
Temperature and Humidity Monitoring The DHT11 sensor was also added to the system, which allows the monitoring of local humidity and temperature, allowing a more comparative analysis between the state of the environment and the expenses generated. As mentioned in the previous topics, the purpose of monitoring these systems is to create relationships between the data. The choice to measure the local temperature and humidity becomes of crucial importance since it is one of the factors that can cause the most changes in the consumption generated. This sensor has a low cost and it is easy to install, with an operating voltage of 3 -5.5V, which allows it to be used directly in the ESP32. This type of sensor is already factory calibrated and is capable of having readings of 20-80% humidity and temperatures between 0-50 • C, with an error of 5% and ±2 • C, respectively.
Communication and Database description The ESP32 [31] is an embedded system board, produced by Espressiff System. By having a low cost, integrating WiFi and Bluetooth systems on the same embedded board, the ESP32 is commonly used in IoT projects. The microcontroller's operating range is 2.2V to 3.6V, and power consumption is around 0.3W. The source code was integrated into the ESP32 board, which is a bridge between acquiring the data from the sensors and sending it via iFi to the database.
For a better analysis and comparison of the obtained data, an important feature in data collection is the date and time tag. Thus, the Time Series Database (TSDB), offers an optimization when used in time series, as the present case. This type of database was created so that the user could have the freedom to create, update, manipulate and organize time series more efficiently, allowing the visualization of long-term changes [32].
InfluxDB [33] is a database developed by InfluxData, which allows to create a TSDB database. According to DB-Engines Ranking [14] [34], InfluxDB ranks first among Time Series models. The [34] is an independent site that ranks databases according to search engine popularity and frequency of technical discussions.
For the project, the web application Grafana [35] was also used, which allows better visualization of the data with the creation of several interactive dashboards. This application also allows updates of the visualized data automatically and even in real-time. Fig. 4 allows the visualization of one of the charts generated to monitor the data obtained from the test apartment. It is possible to see that the graph for the water flow is null, because, as mentioned in Section 3, this sensor could not be installed at the time of this publication and will be discussed as future work. However, the database and the Grafana are already configured to receive the data.

Development and Results
The study developed was installed in the Apolo Building, in Bragança, Portugal. Although the building was under construction, most of the structure was already finished, so it was necessary to find a solution that had minimal intervention in the construction. A pilot apartment was chosen to serve as a test since the building cannot be inhabited yet. The implementation done in this project pursued low-cost solutions, as can be seen in Table 1. The values were based on Portuguese stores of electronic components for the sensors and microcontroller and the IoTaWatt site for its equipment. First of all, IoTaWatt is already installed initially with two sensors, one to capture the overall consumption of the apartment and the other specifically for air conditioning consumption. In the future, it will be used to monitor more specifically the apartment's consumption, such as consumption from the power supply of the induction stove, or consumption only with the lights. This specification of consumption can be done through the electric panel. Initially, was installed the Shelly EM equipment, from the company Shelly. This meter, despite working very similarly to the IoTaWatt, has the disadvantage of having modules with a maximum capacity of two monitoring circuits. In other words, for measurements in larger quantities, which was planned, more equipment from Shelly would be needed. The idea was then replaced by the IoTaWatt equipment, which as mentioned earlier, allows the reading of up to 14 different circuits.
From Fig. 4, the data obtained through IoTaWatt allows us to observe some peaks in overall electricity consumption. As mentioned earlier, this test apartment has no residents yet, which allows us to conclude that these peaks are from the refrigerator, the only equipment turned on uninterruptedly. Also, by observing the graph, it is possible to validate the functioning of the garbage system. A 3D prototype was developed for this system, which can be visualized in Fig. 5. A button was also attached to the system that allows the tare of the scale to be reset when the garbage can changes. It is important to mention that the systems that are integrated inside the apartment, namely the DHT11 and load cell sensors, are connected to the same ESP32, which is located inside the apartment. The water flow sensor, on the other hand, which is located at the entrance to the building, is connected to another ESP32, where in the future all flow sensors of all the apartments will be connected. And as mentioned earlier, the IoTaWatt has an integrated microcontroller, so its communication is direct via WiFi, without the need for a connection to the apartment's ESP32. Fig. 6 shows the connection between the sensors and the ESP32. The database was divided between floor and apartment tags, with the floor being "bucket" and apartments, "measurements", in order to optimize for a future machine learning implementation. The simplified system architecture is shown in Fig. 7. In summary, the database was divided between floors and apartments, to allow better machine learning applications in the future through these filters.

Conclusion and Future Work
The integration of systems via IoT allows centralizing all the information obtained in the building. As mentioned earlier, the idea of making the building intelligent aims to promote not only the automation of it, such as doors with electronic locks, remote on/off function for lights, but to integrate all the systems involved.
This paper presented a low-cost solution using open-source tools to integrate metering systems in buildings. The data obtained allow performing a diagnostic analysis of the consumption. Although the data collected is not real, since the building is not inhabited yet, it allowed the prototype development and its validation. As some of the hardware is still under development, it has not been shown completely. After the complete data acquisition prototype has been installed and developed, better data analysis will be possible. We presented the current results only to demonstrate the operation of the designed system and list the intended next steps for this project. Among them is the application of machine learning, in order to create relationships between the consumption and the resident's behavior. In the future, a printed circuit board is being developed that will allow the addition of various sensors that may be desirable to monitor other parameters of the apartment, for example, light intensity, air quality or sound noise.
As future work, is worth mentioning create an specific application to make the data collected and processed available to the resident. The main objective of the project is not to control the behavior of the resident, but to monitor the data collected, with the consent of the same and show viable alternatives that bring ecological solutions to the expenses generated. The application can be either via smartphone or tablet, or even displayed on the interactive screen inside the apartment. Through data analytics it will be possible to observe whether there will be short-and long-term changes through the information presented to the resident. There can also be integration of the other systems already present in the building, such as monitoring the air conditioning operation cycle, opening the entrance door, among other systems.