Hierarchical Control of Microgrid Using IoT and Machine Learning Based Islanding Detection

Due to the increase in penetration of renewable energy sources, the control technique plays a vital role to determine the performance of Microgrid (MG). Recently, the Internet of Things (IoT) and cloud computing has gained significance in solving various industrial problems. Robust and scalable Information Communication Technology (ICT) infrastructure is critical for efficient control of MG. IoT Devices with efficient measurement and control capability can play a key role in the MG environment. In this paper three layers hierarchical control of inverter based MG was developed using cloud-based IoT infrastructure and machine learning (ML) based islanding detection scheme. MG was operated in both island and grid connected mode. In the Primary layer, a voltage frequency (V-F) droop control with virtual impedance control was applied to avoid the disturbances in island mode. Moreover, Active Reactive (P-Q) power control was used for grid connected mode. In the secondary layer voltage and frequency deviations were removed by using the decentralized averaging based method. Voltage and frequency from each distributed generator (DG) were communicated by using a lightweight IoT-based protocol through an edge device (ED). Context-aware policy (CAP) was adopted in ED to optimize traffic flow over a communication network (CN) by comparing the difference in the present and previous data values. In the tertiary layer, a cloud-based ML model was developed using an artificial neural network (ANN) for islanding detection. ANN model was trained by data produced by simulating islanding scenarios in Matlab. Phasor measurement unit (PMU) data was communicated to the cloud for island prediction. The Proposed scheme was implemented on a modified IEEE-13 bus system with four inverter-based distributed generators (DGs) in Matlab, and Microsoft cloud services were used. The successful implementation of MG hierarchical control using an IoT feedback network with less data traffic along with cloud-based islanding detection using machine learning are the main contributions in this work. The whole system achieves stability within 2 seconds of islanding according to IEEE 1547 standards.

Due to advancements in technologies of IoT devices, artificial intelligence, data handling, and 5G communication, the concept of industry 4.0 has become a center of attention. Smart devices and ICT infrastructure capable of bidirectional data flow has a huge impact on the performance of smart grids [1]. Smart grid requires real-time communication between different nodes containing smart devices for stable operation. Artificial intelligence, cloud computing, and IoT devices can play a major role in the efficient performance of the ICT. In literature, various solutions have been presented for smart grid problems using the IoT concept. Self-healing, fault detection, load forecasting, and optimized performance of power systems can be significantly improved with the implementation of IoT and artificial intelligence technologies [2]. Using IoT devices smart grid was divided into three types of networks [3]: (i) Home Area Networks (HAN), (ii) Neighborhood Area Networks (NAN), and (iii) Wide Area networks (WAN). HAN connects residential electrical appliances with smart meters. NAN develops communication between the substation and smart meters from multiple HAN. WAN supports communication between network gateways, transmission lines, power plants, and control centers. An IoT-based model for a Smart grid using IPv6 protocol with scalability for a large number of devices was implemented in [4]. Power restoring time problem was addressed in the large distribution system by fault localization using centralized cloud base IoT structure [5]. The problem of high bandwidth and low latency in cloud computing for smart grid has been addressed by introducing edge computing in [5]. However, the use of IoT in power systems can add major threats like cybersecurity and privacy issues [6]. Due to the increase in load demand and stress in power transmission lines MGs are considered the future of smart grid [7]. The scalability of the smart grid evolves with the concept of interconnected MGs and CNs. A strong and reliable communication network is needed for MG irrespective of complexity in topology and undesired events [8]. Generally, a three-layer hierarchical control structure is used for the MG control layer i.e. primary, secondary, and tertiary layer. Communication takes place at each layer with different control objectives [9]. The stability and power quality of MG depends on the primary and secondary layer which require a fast time-critical communication system [10]. The primary layer has main objective to regulate the local voltage and frequency of DG with respect to active and reactive power. V-F Droop control is widely used for the primary layer. Matching control, virtual synchronous machine control, virtual oscillator control and droop control were discussed in [11] which can fulfill primary layer fast control objectives. A dual control scheme i.e. current regulated P-Q power control for grid connected mode and (V-F) droop control for island mode was adopted in [12]. To mitigate the effect of disturbances due to the inductive nature of the power network and to match the impedance of the inverter an additional virtual impedance control loop along with droop control was introduced in [13]. The concept of droop control on the virtual power source (VPS) was introduced in [14] for impedance matching, VPS voltage was found by adding voltage drop due to line and virtual impedance to actual DG voltage which has better stability performance in low voltage MGs as compared to high voltage MGs. The secondary layer objective is to reduce the deviation of voltage and frequency produced locally at the DGs by adjusting the reference value of primary controllers. In centralized secondary control, all errors are computed at a central point and then communicated to DGs for correction [14]. A single communication failure from the center can lead to whole system failure. In comparison, all deviation errors are computed and controlled locally at DGs in distributed secondary control but require high communication bandwidth as compared to centralized secondary control [15]. An averaging based decentralized control was proposed in [16], the error was computed locally by comparing the required value with the average of each DG. A consensus based distributive control technique to limit data exchange was proposed in [17].
Islanding detection plays a vital role in the efficient utilization of MG during undesired events. Islanding could be intentional or unintentional. Intentional islanding is mostly for repairing or economic purposes while unintentional islanding is due to faulty events. According to IEEE 1547 standards, unintentional islanding should be detected within 2 seconds [18]. Wrong and untimely island detection could lead to power disasters and equipment loss [19]. Islanding detection techniques are classified into three types (i) passive islanding detection (ii) active islanding detection and (iii) remote islanding detection. In the passive islanding technique, deviation of MG parameters like voltage, frequency, and phase angle are used to detect islanding [20]. The performance of passive islanding detection techniques depends on threshold selection. A small threshold leads to false detection of islanding as nonfaulty conditions may reach threshold while large threshold settings create a nondetection zone (NDZ) for islanding scenarios [21]. In active islanding, a small disturbance signal is introduced between the inverter and grid which becomes noticeable when MG is operating in islanding mode [22]. Active islanding techniques have a comparatively small NDZ but are suitable for single DG based MG. In the case of multiple DGs, too much insertion of external signals may lead to a drop in power quality at PCC and may cause synchronization problems with the main utility [23]. In [24], different active islanding techniques were studied for multiple inverter based DGs. Remote based islanding detection schemes are more efficient in time and islanding detection without any power quality issues but add an additional cost of proper Supervisory Control and Data Acquisition (SCADA) system [25]. PMU provides accurate and reliable measurement of voltage, frequency, and phase with time-stamping at the rate of 64 samples per second [26] and could be used to detect islanding remotely [27]. With the advent of artificial intelligence, many techniques were applied to detect islanding by utilizing previously recorded data. ML methods have better performance as compared to passive and active techniques, the efficiency of this method mainly depends on data used to train the model but it requires high physical computational power. In [28] decision tree classifier ML approach was applied to detect islanding but it has low accuracy. The Bayesian classifier was used in [29] which provides good accuracy but requires more computational power. An adaptive neuro-fuzzy interference system (ANFIS) was introduced to detect islanding cases by defining different stability margins [30] that require a complex method for obtaining input parameters. A support vector ML classifier was developed based on PMU measurements to detect islanding in MG [31]. CN inherent the time delay problem and affect the overall performance of the system. Too much communication delay in the secondary layer can affect the overall performance of the system by adding oscillations, degrading the power quality, and may lead to system instability [32]. In literature, many studies were conducted for communication delays in various techniques. In [33], a consensus based technique was modified by considering the effect of time delay. In [34], communication delay was studied in centralized secondary control and it was suggested that with the increase in communication delay, the gain of the controller can be adjusted to damp the oscillations and transient effects. By considering the effect of time delay control, stability was studied by developing a root locus [35]. To mitigate the effect of oscillations due to delay, [36] suggests the addition of a high capacitance filter which resulted in extra cost. In [37], a study was conducted to minimize the effect of communication delay by predicting the value using double ANN and previous data during delay, the k-means algorithm was used for clustering the input data of similar value to train the model and output control signal was predicted by the weighted sum of historical power and control signal data. In [38] effect of delay on DC MG was studied, it was suggested that communication delay up to 300ms leads to system instability and inaccurate current sharing. MG requires time-sensitive technologies to perform efficiently in real-time. MG is a complex system with many subsystems highly dependent on bidirectional CN [8]. A scaleable CN infrastructure is needed for the future connectivity of new MGs and smart devices. A high bandwidth CN capable of real-time feedback is critical for proper control and timely action in MG [39]. CN could be wired or wireless. Wired technology includes optical fibers, copper twisted pairs, power line communication (PLC). Wired CNs have compatibility and economical issues because of extra implementation and maintenance costs [40]. Wireless CNs are more advanced and more feasible in terms of reliability and scalability. Wi-Fi, Zig-Bee, Cellular networks (3G, 4G) are some of the robust wireless technologies [41]. Low power wide area network (LPWAN) such as IoT provides more coverage as compared to cellular networks with more economical benefits [42].
This paper proposes IoT based real-time CN for feedback control applications in MG and utilizes a fast cloud based structure for the centralized subsystem of MG. IoT based control provides scalability to the MG power network by allowing the addition of new DGs without interrupting the functionality of the existing system. Mostly power system contains a network of neighboring MGs connected in different distribution networks. For mutual optimal operation and cost effectiveness, information needs to be exchanged between MGs. Therefore, IoT based control infrastructure is required to provide a suitable platform for exchanging critical information in minimal real time. Cloud based computing allows to store and monitor data centrally which optimize power systems globally and can be useful to predict future trends. In the proposed system, (V-F) droop control and P-Q control have been implemented in the island and grid connected mode of MG, respectively. Averaging based decentralized control has been implemented in the secondary layer. Cloud based Machine learning technique was used to detect islanding, which provides fast response without any use of a physical processing device at the site. Following are the main contributions of the paper in this regard.
• A distributed Hierarchical controlled layer structure was implemented for smart MGs.
• IoT-based real-time CN for feedback control was implemented for distant placed DGs in large bus system MG.
• Role of Edge device was introduced by applying CAP policy to send only effective data over IoT network, which reduces the overall traffic of the network.
• A Centralized cloud based real-time islanding detection scheme was applied using ANN by sending PMU data through an IoT network.
In the rest of the paper, hierarchical control of MG is discussed in section II, IoT framework for CN is discussed in section III, while results and conclusions are discussed in sections IV and V respectively.

II. MG HIERARCHICAL CONTROL STRUCTURE
In the hierarchical control structure of MG, each layer has its objectives and response rate. These layers can be implemented using different techniques and technologies. This control scheme is scalable and allows the integration of more MGs. Fig. 1 illustrates the hierarchical control structure of MG. Four inverter based renewable DGs were connected at different busses of the IEEE 13 bus feeder system. The power Circuit breaker has been used to isolate MG from a utility. In the primary layer, droop control and P-Q control have been implemented locally at each DG. The cloud-based IoT network was developed for communication between DGs. The local measurements from each DGs were communicated using CAP policy to optimize traffic flow through the network in the secondary layer. In the tertiary layer, a cloud based machine learning model was developed for islanding detection to switch the power circuit breaker between MG and utility. Each layer has been discussed below as implemented for this work.

A. PRIMARY CONTROL
In the primary layer, control was applied locally in DG units to regulate the output. The stability of MG mainly depends on the performance of the primary layer due to which time-sensitive and communication less control techniques are used. Different control strategies are used for grid connected and island mode. For grid connected mode, P-Q current regulated control was applied. The control was applied on the inverter to deliver output power according to the reference set point. Output parameters like voltage, frequency, and phase were imposed by the main grid. The control was applied in d-q frame of reference. All alternating signals are converted in the d-q frame of reference using (1) and (2).
A d axis current is responsible for active power (P) control and q axis current is responsible for reactive power (Q) control. Based on reference P and Q, reference current was derived to compare with the grid current in d-q frame, and fed into PI control loop. P and Q in d-q frame are given by (3) and (4) respectively.
where V d , V q , I d and I q are dq components of grid side voltage and current. In steady state, V d is zero so reference current is derived as (5) and (6).
In Island mode, (V-F) droop control technique was applied. The main key objectives of droop control are to share the load between DGs and to regulate system frequency and voltage. Droop control loop, virtual impedance control loop, current Proportional Integral (PI) control loop, and voltage PI control loop were applied in sequence as shown in Fig. 2. The response time of the current and voltage control loop is very fast as compared to the outer droop control loop. The controller was provided with voltage and frequency references. Active power has a direct relation with frequency while reactive power of DG is controlled by voltage magnitude. Droop equations for active and reactive power are shown in (7) and (8).
where f * , P * , V * and Q * are reference values of frequency, active power, voltage and reactive power respectively. k p and k Q are droop coefficients. In decentralized mechanism, where more than one DGs are connected, k p and k Q of each DG should be selected in such a way that it should satisfy (9) and (10) respectively [43].
k p and k Q can be found using equations (11) and (12).
where δf and δV are deviations in frequency and voltage respectively, whereas, P max and Q max are maximum active and reactive power for a particular DG. Due to the complex physical power network and non-uniform inductive balance, droop reactive power-sharing is less effective. To match the output impedance of each DG, the virtual impedance loop was used after the droop control. The output voltage of DG is controlled due to which it remains relatively unaffected by disturbances, however the current increases to an unacceptable limit because of impedance mismatch seen by each inverter. A virtual impedance loop was added to limit the output current. The output voltage of the DG can be written as (13).
where V INV is the inverter output voltage, Z LINE is line impedance and I is an output current. If V ref is droop generated reference voltage and Z V virtual impedance then V INV will become as (14).
Putting value of V INV in above Equation (14). V DG will become (15).
From (15) it can be seen that output impedance seen by DG is equal to Z V +Z LINE . Virtual resistance provides a damping effect during transients and virtual inductance allows the accurate sharing of reactive power. However, a large value of virtual resistance causes too much voltage drop and a large value of inductance causes oscillations in the system. So the value of resistance and inductance must be chosen in such a way that system remains stable. In [44], an unstable margin of virtual impedance for the system was derived using eigenvalues. In [45], the values of resistance and inductance were selected arbitrarily depending on the best performance of the system.

B. SECONDARY CONTROL
The main objective of secondary layer control is to remove steady-state errors in voltage and frequency caused by the primary layer. Errors are removed after the sharing of power between the DGs by the primary layer. Without the implementation of the secondary layer, voltage and frequency will become load dependent and load deviation will cause stability issues. In this paper, averaging based decentralized secondary control technique was applied where each DG sends its local value of frequency and voltage to all other DGs in the system without central coordination. Each DG locally calculates the average value of voltage V avg and frequency f avg by using the received values as (16) and (17).
These average values are compared with the reference value and fed into the local PI controller for error generation, as shown in Fig. 2. This error is further added to droop output values for further compensation. The secondary layer requires a CN between all interconnected DGs. The performance of secondary control greatly depends on the speed of CN.

C. ISLANDING DETECTION WITH MACHINE LEARNING
Islanding can occur due to many reasons like system, faults, environmental conditions, equipment malfunctioning, under loading, overloading, etc., and affects system voltage, frequency, and phase, In this work ANN was used to train a model for islanding detection based on PMU data. Three different islanding scenarios were taken into account for the training of the model. 1) When short circuit fault occurs. The fault could be a single phase, two phase or three phase. 2) When the connected load is greater than the capacity of DGs. 3) When the connected load is less than the capacity of DGs. These scenarios were simulated in Matlab/Simulink to get data. Two PMUs were used one on the utility side and the other on the MG side of PCC. Islanding scenarios were intentionally introduced and data of both PMUs i.e. voltage, frequency, phase was collected before and after the event.
To reduce the processing complexities instead of using data from PMUs directly, the difference of both PMUs parameters was used to train ANN. Training data was labeled with three input parameters i.e. V voltage difference, θ phase difference, and f frequency difference and one binary output parameter i.e 1 for islanding scenarios and 0 for non-islanding conditions. ANN model was designed with three layers as shown in Fig. 3. The hidden layer contains three neurons with weights w 1 , w 2 and w 3 , the activation function was 'relu' while the output layer has one neuron and the activation function was 'sigmoid'. If the output of the model was less than or equal to 0.5 then it was considered as non-islanding and if the output is greater than 0.5 then it was considered as islanding.

III. IoT FRAME WORK
The IoT framework was made by interconnecting different sensing devices through the internet. For secondary control at each DG, the voltage and frequency were measured and transmitted to ED. The ED filters the data and provides a smooth connection to the cloud without any interference of the sensing device. CAP was used to filter the data in ED. CAP enables the ED to send only critical information which helps in reducing traffic over the network and cloud. Similarly in [30] vessel monitoring system (VSM) was used which reduces traffic up to 70%−90%. Data was only transmitted if the current value differs from the previous value by factor d which is 0.01% as given in (18).
where P 2 is the current data value and P 1 is the previous data value. The secondary control requires a communication system with fast transmissions rate and response time. According to IEC 61850 standard for communication between devices in power automation systems, the maximum latency for control is 16-100 ms [29]. Generally, the internet networking system is derived from the Open systems Interconnections (OSI) model which divides computing functions into 7 layers to support communication interoperability between different devices as shown in Fig. 4. In this work, IoT-based real-time Message Queuing Telemetry Transport (MQTT) protocol was used with reduced data packet size for fast and real-time communication. MQTT broker is a cloud entity and devices connected to it act as a client to the broker. Each client communicates with others through publish/subscribe method under a specific topic i.e. sending device will publish a message under the specific topic tag and receiving device must   be subscribed to that topic to receive the message. The ED of each DG act as a client to the MQTT broker. For islanding detection, a machine learning model was implemented in the cloud. Both PMU transmits their data using MQTT protocol under their respective topic to the cloud. The difference of values was calculated in the cloud and used as input to the ANN model for islanding detection. Along with two PMUs, cloud-based ANN model also act as a client to MQTT which reduces hardware computational cost.

IV. RESULTS AND DISCUSSION
The proposed idea was implemented on a modified IEEE 13-bus system with 4.16 KV L-L base voltage, 60Hz base frequency, and 0.89 power factor in Matlab. Bus 650 is considered as PCC. One PMU is connected on the main grid side of the circuit breaker and the other is connected on the MG side. Four DGs are connected on different buses and have made an IoT CN, as shown in Fig. 5. The IoT in Matlab was implemented by using the MQTT library package. Matlab engine was used to execute IoT tasks using the ''coder extrinsic'' property in Matlab, while the MG model was simulated in Simulink. Fig. 6 shows the working of the proposed scenario in Matlab/Simulink. DG capacities and other parameters are shown in Table 1. In Grid connected mode each DG follows the reference P and Q as shown  in Fig. 7, while voltage and frequency are imposed by the main grid. In Island mode, the system sets its voltage and frequency following the reference value. In practical scenarios, primary layer and secondary layer control start functioning at the same time but in this case, IoT network-based secondary layer was turned on at t = 1 sec to differentiate the results. The latency of the IoT channel VOLUME 9, 2021  was 42 ms. Fig. 8 shows the system frequency in island mode. Primary droop control stabilized the frequency at t = 0.5 sec with some deviation from 60 Hz. When secondary control was turned on at t = 1 sec, the frequency deviation was minimized. Similarly, the voltage at each DG was also stabilized by primary control with some deviations, when at t = 1 sec secondary control turned on voltage reaches to 1 p.u. as shown in Fig. 9. Fig. 10 illustrates that droop control also stabilizes the P and Q by satisfying the relation with voltage and frequency as given in the above equations. It can be seen that each DG has different peak behavior because the impedance seen by each DG connected in the network is different. This peak overshoot was stabilized by a virtual impedance loop by limiting the current. After the activation of the secondary control layer, P and Q reach the reference value because voltage and frequency deviation were minimized.  To analyze the effect of communication delay, frequency and voltage with IoT CN were compared without CN as shown in Fig. 11 and Fig. 12. It can be seen that comparatively transient stability with IoT is slower. The frequency becomes stable at a slightly higher value, while initially, voltage experiences some distortion at the start. Fig. 13 and Fig. 14 show harmonics response of voltage with IoT and without IoT at PCC respectively. It can be seen that due to IoT communication delay, a small percentage of higher order harmonics were added into the system. The total harmonics distortion (THD) without and with IoT were 1.21% and 2.36% respectively. Overall, the system remains in a stable condition according to the IEEE 1159 standards [46]. A large communication delay of 300ms was added manually to see the behavior of voltage and frequency as shown in Fig. 15 and Fig. 16. It can be seen that oscillations and voltage fluctuations were produced which jeopardized the power quality and stability of the system.
To get data for ANN training, the DGs have connected in grid connected mode with all three scenarios. The inductive load was used in all scenarios. At t = 1 sec, an islanding   scenario was introduced to record the data for both modes of operation. Fig. 17 and Fig. 18 show voltage and frequency data trends at PCC. When DG capacity is less than connected load, voltage decreases whereas frequency increases as shown in Fig. 17. In contrast, Fig. 18 shows that the voltage increases and frequency decrease when the DG capacity is greater than the connected load. To compile ANN model, loss function and optimizer were selected as 'binary cross entropy and 'adam' respectively. Fig. 19 shows the training accuracy and loss data of ANN trained model. Table 2 shows   the comparison of the ML model with other techniques in [19] in terms of NDZ, detection time, power quality, and effect in the case of multiple DGs.
For testing islanding detection, the circuit breaker was switched at t = 0.5 sec. PMUs edge device sends data to cloud through IoT, ANN model predicts the islanding and MQTT publishes the message 1 to each DG which means that islanding has occurred and each DG shifts from grid   operating mode to Island operating mode. Fig. 20 shows the frequency behavior at PCC. It can be seen that during islanding detection time frequency overshoots but then stabilized near to normal reference value with secondary layer   activation at t = 1.5 seconds. Fig. 21 shows the behavior of voltage magnitude before and after islanding detection, during islanding detection time voltage dips from its actual value and again achieves stable value in less than 2 seconds after the implication of hierarchical MG control.
For further validation simulation was performed using Simulink Desktop Real-time which executes models using real time kernel. Only two DGs were considered for simplification. NI PCIe 6351 DAQ card was used to collect data from IoT nodes. IoT nodes were implemented by using two esp8266 which subscribe data published from Matlab through IoT and give back to Simulink through NI DAQ card by using digital to analog converter as setup shown in Fig. 22. The focus of this setup is to showcase the effect of IoT communication channel on voltage signal from DG. For this purpose, commercially available Microsoft cloud services were used. MQTT broker was installed in the cloud. Fig. 23 shows the scale down (+5V to −5V) output voltage through NI DAQ card of phase A at PCC. The other two phases will have similar output but 120 degrees apart in phase. It can be seen that initially there is distortion in the wave then it gets stable.

V. CONCLUSION
The selection of proper communication technology is one of the main challenges in the design of smart MG. The real time IoT based CN with low latency can provide an efficient control system by keeping the MG in a stable range. In hierarchical control of MG, the primary layer requires a very fast response time so communication less control has been implemented in each DG locally. The secondary layer relies greatly on a communication network and requires real-time communication to function properly. Too much communication delay in the secondary layer can cause voltage rise and oscillation in the system which results in degradation of power quality. The IoT based secondary control with a time delay of less than 50ms improves the voltage and frequency by keeping the system in a stable range. The cloud based ML with the help of IoT provides an efficient method for islanding detection without any NDZ and power quality issues. The usage of cloud based computational resources decreases the cost of maintaining physical devices at the site and provides more reliability in terms of functioning. Due to cloud based IoT and artificial intelligence, the data can be stored and efficiently used for the overall optimization of the system in terms of cost, scalability, future prediction, and state estimation. Furthermore, applications like demand side management, market Participation, load forecasting can also be done effectively. His research interests include electric vehicles, converters, inverters, permanent magnet motors, magnetic bearings, bearing less motors, third generation left ventricular assist devices, magnetic circuit design, analysis of systems using numerical methods, finite element analysis methods, mathematical modeling, and control of linear and non-linear systems.
SHIBLI NISAR is currently an Assistant Professor with the Department of Electrical Engineering, National University of Sciences and Technology (NUST), Pakistan. He has attended and presented his research papers in various national and international conferences. He is the author/coauthor of 22 research papers, including impact factor journals and peer-reviewed international and local conferences. His research interests include signal processing, speech processing, mathematical modeling, designing, and analysis of wireless ad-hoc and sensor networks and machine learning. VOLUME 9, 2021