# Novel Internet of Things Platform for In-Building Power Quality Submetering
## 2 IoT Power Quality Sensor  
### System Architecture  
To contextualize the integration of the IoT PQ smart sensor in a grid, the system is described first from the hardware point of view and, subsequently, from the ICT viewpoint. Figure 1 shows the general system architecture. It shows the complete procedure followed with the IoT PQ sensor implemented: since the PQ event is detected by the sensor until it is stored in the cloud database where it will be available for the customer. Through a cloud system, users can access data from their installations with their mobile devices such as tablets or mobile phones. The proposed smart sensor can be installed in a non-intrusive way inside a building. It allows on-time access to data collected through the IoT cloud platform. This smart sensor is based on ATMega technology, as it is used to acquire data and send it to the cloud system. It integrates the ADE/758 IC to measure power quality parameters according to the standard IEC 61000-4-30, a Real-Time Counter (RTC) peripheral precise information about timestamp, as well as an ESP8266 Wi-Fi module to send data to the cloud. To visualize the recorded data, the IoT PQ sensor utilizes a mobile device such a smartphone or tablet. ThingSpeak offers a flexible and easy way of storing the information collected by sensors in the Cloud, so ThingSpeak platform has been chosen not simply to monitor data recorded by the designed IoT PQ sensor, but also for its ability to operate with data that supports MATLAB(r) code integration. Therefore, voltage sags are on-time monitored as well as categorized according to the SEMI F-47 curve. Focusing on the IoT PQ sensor device itself, it measures voltage and current RMS, active and apparent energy, as well as detecting voltage sags in a three-phase distribution system. The hardware description from the IoT PQ sensor is now considered. Figure 2 shows the block diagram of the components of the PQ monitoring prototype. This system, based on an IoT paradigm, incorporates in its construction the following components: ATMega328P-PU MCU, ADE/758 IC, and the ESP8266 Wi-Fi module. To power the system, a dual power source--5 V & 9 V (one for each chip)--is needed. An RTC peripheral is added to the ATMega328P to do timestamp. Finally, a signal conditioning circuit is needed at the ADC ADE/758 voltage input. Figure 1: System architecture. The ATMega328P-PU is a low-power single-chip 8-bit enhanced RISC-based microcontroller that combines 32 kB ISP Flash memory with read-while-write capabilities, 1 kB EEPROM, 2 kB SRAM, 23 I/O lines, 32 working registers and serial programmable Universal Synchronous and Asynchronous Receiver-Transmitter (USART). More features can be found in [40]. This microcontroller, specifically designed for in-home and building automation, manages this cost-effective and flexible PQ Meter, allowing the communication between multifunction energy metering ADE7758 IC [41] and the Wi-Fi chip ESP8266 [42]. The timestamp, a critical part in a measuring device, has been addressed with the use of an RTC peripheral (DS1307 ZN) [43] communicated with the ATMega328P through I2C bus. Finally, the enhanced prototype includes the ESP8266 Wi-Fi System on Chip (SoC) module, which is a low-cost Wi-Fi chip with full TCP/IP stack and MCU capability, based on serial interfacing requirements [42]. The ESP8266 module was selected due to recent popularity in IoT prototype research and its affordable cost. The most interesting part of the prototype is ADE7758 IC [41] representing the heart of the design. This multifunction energy metering has a voltage channel with single-ended voltage inputs and a differential current channel. The voltage value is driven to the voltage channel ADC, and with the appropriated configuration, the chip detects zero-crossing, giving several PQ parameters through different internal registers. On the other hand, the current differential channel adapts its phase current levels to a proportional differential voltage measured by the ADC for this purpose.