Energy Management in Hybrid Microgrid using Artificial Neural Network, PID, and Fuzzy Logic Controllers

— Microgrids are described as linking many power sources (renewable energy and traditional sources) to meet the load consumption in real-time. Because renewable energy sources are intermittent, battery storage systems are required, typically used as a backup system. Indeed, an energy management strategy (EMS) is required to govern power flows across the entire Microgrid. In recent research, various methods have been proposed for controlling the micro-grids, especially voltage and frequency control. This study introduces a microgrid system, an overview of local control in Microgrid, and an efficient EMS for effective microgrid operations using three smart controllers for optimal microgrid stability. We design the Microgrid, which is made up of renewable solar generators and wind sources, Li-ion battery storage system, backup electrical grids, and AC/DC loads, taking into account all of the functional needs of a microgrid EMS and microgrid stability. In addition, the battery energy storage is managed through the performance control of battery charging and discharging using an efficiency controller. The proposed system control is based on the optimum supply of loads through the available renewable sources and the battery State of Charge (SOC). The simulation results using Matlab Simulink show the performance of the three techniques (PID, ANN, and FL) proposed for microgrid stability.


I. INTRODUCTION
New smart grid concepts will be required for future power systems. Flexible microgrids (MGs) are necessary in this regard, since they must be able to operate in both gridconnected and island modes. A microgrid system's principal goal is to fulfill load demand by prioritizing renewable energy over auxiliary sources like diesel [1]. Such systems must save enough money to offset the cost of renewable generators and other system components. Because of the utilization of renewable energy resources (RESs), the Microgrid (MG) is not only cost-effective, adaptable, and steady, but it also has environmental advantages over traditional utility networks [2].
Microgrids also promote the involvement of small power sources in the market, which may be aggregated to provide the power needed to achieve the Distributed Generators' target goals (DG). Because of the various power sources that might be mixed, studying microgrid safety and stability is difficult [3]. In most cases, the load demand, which has an influence on the microgrid structure during the design stage, must be included in the microgrid stability and control evaluation [4]. High perception of distributed generation (DG) into power grids challenges the process and stability of power systems. Therefore, just microgrid (MG) structure and control techniques for DG are necessary to ensure microgrid and power systems' resilience, safety, and efficiency [5].
Much study has been conducted on MGs' sizing, control, energy management, and operation in recent years. In a microgrid system, an energy management system is necessary to control the flow of power and energy between sources and loads and to provide high quality, safe, sustainable, and environment-friendly energy to consumers [6]. This chapter will overview the Microgrids concept, microgrid control architecture, and an Overview of local control in Microgrids.
A microgrid (MG) is a hybrid electrical system, low or medium-voltage, that includes small energy sources based on renewable resources as primary resources to provide highquality electricity for small consumers, mostly operated in rural areas that are separated or isolated. Finally, microgrids have been used recently to address the grid blockage difficulties as far as the high integration of distributed renewable sources is concerned [7]. MGs can operate in one of two operating modes, depending on technical and economic conditions: connected to the main grid through a Common Coupling Point (CCP) or islanded [8].
Microgrids are currently changing in terms of idea and definition in order to give consumers with sustainable energy options in terms of renewable energy integration, grid stability, flexibility, and cost.
MG has the potential to maximize the overall efficiency of the system, the quality of the power supply and allow customers to control their electricity supply [9]. A microgrid is defined as an energy system incorporating management intelligence and consists of a variety of components. A typical microgrid control hierarchy is depicted in Figure 1. In general, a smart microgrid EMS must manage and coordinate a mix of DGs, Electricity Storage Systems (ESS), and loads to supply high-quality, dependable, sustainable, and environmentally friendly energy at a reasonable cost. The MG control practical requirements for efficient and stable working can be formulated as [10]: • Control of voltage and frequency; • Active and reactive power (P-Q) balance and proper communication among DG; • Microgrid resynchronization with the main grid; • Optimizing the Microgrid serving cost; • Power flow control between MG and power grid network. PI/PID linear control, sliding mode, and artificialintelligence-based control have all been utilized in the past to control Microgrids. This section covers the energy management control strategies utilized in the Microgrid. PID control is a comprehensive feedback control approach that is extensively employed in industrial control systems' automated controllers. PID controllers are the most extensively used systems for engineering application control, and they employ a proportional factor (P), integrative action (I), and differential action (D) to transform the error signal into an input signal [11].
In a hybrid car, a PI controller might be used to collect regenerative braking energy and keep the electric vehicle's voltage bus constant while charging the battery, according to reference [12]. A comparison of the responses of PI and PIDcontrolled bidirectional DC-DC converter systems is also included in [13]. The PID controller must automatically regulate power interruption or load fluctuation effects, as demonstrated in the example in [14]. The settings of this controller are determined by trial and error, or other ways provided by Ziegler and Nicholas [12]. With the correct gain setting, PID/PI is strong, safe, and gives near-optimal control system performance. The PI/PID tuning procedures have limited capacity to adjust the PID additions adequately for nonlinear and sophisticated systems. The PID performance in this framework is strongly based on the right settings of the PID parameters [15].
To sustain power output and loads, MGs, particularly in islanded MG, are exposed to a range of issue controls. When the Microgrid gets islanded due to a power outage, maintaining the uncertainty parameters and limits of the DG units and loads becomes a serious difficulty. The sliding mode controller (SMC) [16] has become a helpful device for MG systems because to its safety and usefulness in tackling such difficulties. On grid-connected mode, the SMC is used as a power quality control in the main bus to modify voltage and frequency. When parameter limitations exist, sliding mode control has been researched for robust nonlinear control to ensure stability [17].
An artificial neural network (ANN) control approach has recently been employed for microgrid control, notably voltage and frequency regulation, in a variety of applications [18], including the management of electrical equipment such as inverters and bi-direction inverters in AC microgrids. The ANN controller has demonstrated a fast reaction time as well as great stability and dependability. It has the potential to increase an AC microgrid's frequency and voltage stability, as well as power quality, and to ensure quick transitions between modes [19]. However, no study has been done on using ANNs to control DC/DC converters or to use ANNs to govern DC microgrids. In ref [20], a preliminary inquiry into developing an ANN-based DC/DC converter control system and combining it with a droop mechanism to regulate a freestanding DC microgrid is reported.
To estimate real-time wind speed, a back-propagation ANN is used [21]. A discrete-time NN controller for DC distribution system control is presented in reference [22]. [23] provides MPPT controllers for several types of RES using a Radial Basis Function Network and an upgraded Elman Neural Network (ANN). In the field of MG control, one of the essential properties of NNs is their ability to estimate the parameters of a given model structure, which is often all that is available when working with a complex system model. The authors in [24] developed a three-phase AC-DC balanced, and unbalanced power flow calculation approach based on an RBFN to determine and control the reactive power of a hybrid AC-DC MG. When the operating conditions of the MG change, the RBFN is used to solve a set of power flow nonlinear equations. The setpoint of the local controllers is updated using power flow analysis.
To address the uncertainties of DC-DC converters (DDCs), Kazemlou and Mehraeen [25] propose a decentralized NN controller, which integrates the distributed sources of a DC grid and stabilizes the output voltage in the event of a disturbance. Low-inertia distribution systems, such as solar panels linked to the DC bus through a buck converter, are given special attention. The suggested controller changes the duty cycle adaptively to ensure stability; input and output voltages and currents must be quantifiable, but communication between the converters is not necessary. The DC-bus voltage and active and reactive power flows are managed by two NNs at the front-end converter in [26].
The rules of a nonlinear mapping are created using fuzzy set theory and fuzzy logic [27]. The use of fuzzy sets lays the groundwork for applying indefinite and uncertain models in a systematic manner. Fuzzy control is based on fuzzy logic, which is similar to human reasoning and natural language to traditional analytical systems [28].
Fuzzy logic is currently employed in almost every business science and electrical system. One of them is frequency control in the Microgrid. The primary purpose of frequency control in microgrid systems is to maintain the output-toconsumption balance. Fuzzy controllers successfully solve a wide range of control difficulties due to their resilience and dependability. PID controllers are outperformed by fuzzy logic, akin to human reasoning. Fuzzy control is more adaptable than traditional PID controllers in nonlinear systems and faster settling time [29].
In addition, an energy management system was built using Fuzzy Logic Control (FLC) (EMS). EMS for a DC microgrid based on the fuzzy logic controller [30] is proposed in addition to EMS for stand-alone microgrids. The proposed FLC prioritizes selling additional power supplied by Renewable Energy Sources (RES) while maintaining a battery State of Charge (SOC) over 50% to improve battery life. This heuristic knowledge suggests that the EMS for the situation under investigation be created utilizing Fuzzy Logic Control. Rather than using a mathematical system model, this method seamlessly blends the user's experience. A better EMS architecture based on FLC was also shown [31]. This study presents a Microgrid Platform and an enhanced EMS for efficient microgrid operations and a data analysis monitoring interface. The main contents and Innovation of this paper are: • This paper proposes an advanced energy management strategy (EMS) for the hybrid microgrid encompassing renewable sources, storage systems, and DC/AC loads. • Comparison of the efficiency of three controllers (PID, ANN, FL) used for the advanced EMS model • A real-time monitoring interface in the Python platform has been implemented for hybrid microgrid energy management and data analysis. The reminder of this paper is organized as follow: section II presents the details of each control's strategies (PID, ANN, FL) used for energy management. EMS management strategy and the monitoring interface are described in section III. Section IV presents simulation and discussion of results. This paper is ended with a conclusion.

II. MICROGRID CONTROL STRATEGIES
The battery storage system is the main element for the balancing of microgrid, because the battery charge to store the energy surplus, and discharge to provide the energy needs. For this reason, the battery is connected to the microgrid bus using a DC/DC bidirectional converter as shown in Fig. 2. The Bidirectional DC/DC converter used in this work, is a half-bridge IGBT topology that operates in continuous conduction mode (CCM). The converter operates in boost mode; it operates in buck mode when storing excess energy at the DC bus. In boost mode, S2 and D1 are active and current flows to the DC Bus. In buck mode, S1 and D2 are active, and power flows to the battery. As we mentioned in the previous section the control of this converter, represent the main challenge for the energy management in microgrid.
In the next, we will present the details of the three best controllers, in order to compare the results of them in the stability and energy management of microgrid.

A. PID controller
The bidirectional DC-DC converter is the essential component for energy management. The bidirectional converter maintains a constant voltage of 300 V while balancing load output and consumption. The DC BUS voltage was measured and compared to the reference value since the bidirectional converter is voltage-controlled. The duty cycle of each direction is calculated using the difference between these voltage levels, which is handled in PID blocks as shown in Fig. 3. The bidirectional converter's control is a critical component of the energy management system to manage energy between the DC Bus, renewable energy sources, and storage devices. Charging, discharging, and stop mode are the three operational modes used. Based on voltage and battery state of charge sensed at the DC Bus, the recommended battery charger algorithm creates the duty cycle value for regulating the system converter using a PWM signal. The parameters of the controller are modified to allow the ideal plant to follow the reference model. A reference model, a controller, and an adaptive mechanism are the three essential components of the proposed controller. As illustrated in Fig.  4, the reference (300 V) is chosen to generate an ideal response similar to the reference input.

B. ANNC controller
The Artificial Neural Network Controller (ANNC) has been used in engineering applications. It has worked very well. The main goal of this kind of control is to make nonlinear dynamics more predictable. They are made up of two neural networks: The first neural network is used to figure out the system. The second is for the design of the controls, as shown in the figure above.
In this paper, the ANNC was used to manage the bidirectional DC-DC converter by generating the duty cycle for the PWM to keep the DC Bus voltage steady at the value of the reference voltage. As a result, the ANNC inputs are the reference voltage, the DC Bus voltage, and the duty cycle value is the output. Many tests were carried out to develop a database to develop the ANNC as shown in Fig. 6. The approach entails running the simulation for various irradiation and load power values and then measuring the DC Bus and duty cycle voltage.

C. Fuzzy Logic
Fuzzy logic control is mostly based on the rules made by the Linguistic variables. Unlike other methods, fuzzy logic control does not need to do complicated math. It only needs to do simple math to control the model. Even though it is based on basic math, it works well in a control system. Thus, this method is one of the best ways to control a plant and is more accessible than other ways. Controlled by Fuzzy logic is based on the idea of Fuzzy sets. In fuzzy set theory, each element has a level of membership with which it is part of any given set. A fuzzy set is a type of set with a lot less clear boundary. The Fuzzy Logic Controller (FLC) is more commonly used when the precision required is low, and the plant does not need a lot of complex math. Even though it is based on basic math, it is still fascinating. it performs well in a control system. As a result, this strategy is one of the most influential and simple ways to regulate a plant. The fuzzy set theory underpins fuzzy logic control. Each element in fuzzy set theory has a degree of membership with which it belongs to any given set. Fuzzy sets are similar to classical sets but with significantly softer bounds. The Fuzzy Logic Controller (FLC) is more commonly employed when intermediate precision is required, and the plant does not require significant mathematical analysis. Other benefits include [33]: ➢ It does not necessitate extremely accurate inputs. ➢ An efficient reaction does not necessitate the use of fast microprocessors. ➢ It only requires a small amount of data, namely rules and membership functions. ➢ It's more efficient and can handle nonlinear models better. Fig. 7 show the internal block diagram of the FLC: The fuzzy controller generated a suitable switching pattern for the switching of batterie for charging and discharging operation. The fuzzy logic controller receives four inputs from the comparison between DC_Bus voltage and the reference voltage. It provides the duty cycle for the PWM block to send a signal for buck/boost converter, as shown in Fig. 8.

A. Energy Management System (EMS)
The power system that this work proposes is made up of many different power sources, like the one shown in Fig. 9: With an MPPT block, the solar system is connected to the DC Bus through a DC/DC converter that is controlled by the MPPT block to get the most power out of it.
• Wind turbine system is connected to the DC Bus through multiples converter and an MPPT block to get the most power from the wind turbine possible.
• BDC is used to connect the Battery System to the Microgrid and controlled using (PID, ANNC, and FL) in this work.
• The electrical grid connected to the DC Bus through the AC/DC converter will only be used when the renewable power is not enough, and the battery state of charge is less than 20%.
The main objects of the Energy management system are: • To provide a power source for all system loads • To maximize the power production of renewable sources • To keep the balance of the microgrid Bus, keep the voltage in DC constant in 300 V, and frequency in AC bus constant in 50 Hz. • To protect the battery against overcharging and over-discharging. The EMS strategy gives each part of the Microgrid its control signal so that each component can be controlled by itself, even if it comes from a different source (decentralized controller). A flowchart in Fig. 10 shows the Energy Management strategy that was used in this study.    The main object of EMS is to supply the loads demand during all meteorological conditions (Solar irradiation). In addition, maintain the DC_BUS voltage around the reference voltage 300 V value by calculating the difference between them, as Fig. 10 shows. The battery system is then responsible for maintaining the voltage value around the required one by charging and discharging throughout the bidirectional DC-DC converter.

B. Interface for Monitoring of Microgrid Energy Management System
The energy management system uses advanced intelligent technology based on an artificial intelligence system. The platform collects power consumption for AC and DC loads and power production for solar, wind, and battery storage systems. The energy-monitoring interface allows you to access and monitor your home energy consumption anytime from anywhere, making energy-saving easier. The interface has been developed based on Python software, a server created on python to provide access using an IP address in all world areas. The Microgrid was implemented in Matlab /Simulink. The power production and consumption are measured and saved on an excel file. The python interface uploads those data directly from files using the directory and show them in the platform as shown in Fig. 11.

IV. SIMULATION RESULTS
The hybrid microgrid system is composed of hybrid DC and AC sources. Each power source is connected to the DC bus of Microgrid using a boost converter to extract the maximum power of each renewable source. The solar cell type is Sunpower SPR 250 NX-BLK with 27 panels in series and 10 in parallel to provide a maximum power of 68 KW. The wind turbine type is PMSG and offers a total power of 10KW. The battery type is Li-ion, capacity = 250 Ah, and Voltage V=200 V. The loads demand in DC Bus is P=10 KW and V=300 V. The loads required in AC Bus are between zero and 0.3 s P=20 KW, between 0.3 s and 0.5 s P=50 KW, and between 0.5s to 1s P=60 KW.
The simulation runs for one second with 1e-5 sampling time to present the comparison between the response of three controllers (PID, ANN, and FL) in the balance of Microgrid during the change of meteorological condition and max loads demand. The reaction of each element to the various variations is presented in the following section. Fig. 12 and Fig. 13 show the solar radiation variation and wind speed, respectively, used in this simulation.  According to Fig. 14 and 15, DC and AC loads are needed for both DC and AC loads. PV power was about 0 kW. The wind power was about 2 KW. The battery will run out of energy to keep the power balance because its SOC value in the limited range is 20%<SOC<80%.  At 0.3 s the solar power increased until arriving its maximum value P=45 KW, and the wind turbine increase to 18KW, and the power demanded increase to 60KW. This means, a surplus of power at the microgrid, which is traduced by an increase of state of charge curve, negative values of the power provided by the battery, as shown in Fig. 14 and 15.
At t=0.75, the irradiation value goes down again, making the main source less important (solar system). This means that the battery will be used again to give the microgrid Bus a lot of power. Notably, the difference between the amount of power produced and the amount requested grows. This means that the amount of power the battery can provide grows linearly with this difference. Fig. 16 and Fig. 17 show the comparison of SOC and battery power during the application of PID, ANN, and FL controllers. As stated at the outset, this research aims to cover the load power by balancing the amount of energy in microgrid systems while also stabilizing the voltage at the DC Bus and frequency at the AC Bus. The comparison of the state of charge and the battery power shows that the response corresponds to the ANN controller presents a high value for the state of charge, which means the high saved power during the proposed scenario. Fig. 18, Fig. 19, show the measured value of power and voltage in DC Bus.  From Fig. 18 and Fig. 19, we can see the efficiency of the three controllers in the stabilization of DC Bus, with more efficiency for the response of the FL, and ANN controllers. As we described before in this report, the battery is the main element for the balance of the microgrid Bus. Fig. 20 and Fig. 21 show a comparison of the measured power and frequency at the AC Bus.  shows that the frequency of the three controllers in the limit's marge, with more accuracy for the FL, and ANN controllers. Only at the start of the simulation, called the "transitory regime," is there a difference in frequency between the merge limits. This is not taken into account. So, we can say that FL and ANN controllers are good at keeping the microgrid's voltage, power, and frequency stable, but the FL has a small advantage in keeping the frequency stable. The simulation results show that the proposed EMS works well and is very stable even when there are significant changes in the weather and the amount of work that needs to be done.

V. CONCLUSION
A microgrid is defined as a low-medium voltage power distribution that integrates renewable energy resources and controllable loads. Microgrid management faces new and unique challenges that have never been encountered in traditional power systems. To meet these challenges, a traditional Energy Management System (EMS) must be redesigned to accommodate the inherent characteristics of microgrids. While many projects have produced excellent research results, they have only addressed portions of the characteristics or have only used simulations to validate their EMSs. This work proposes a Microgrid modeling, an EMS for voltage control, by taking into account both the functional requirements and the engineering challenges and a monitoring interface for data analysis. We develop three techniques for energy management, voltage, and frequency control in AC micro-grid. The first technique is based on PID controller. The controller provides a very good stabilization of the DC voltage, AC bus frequency, optimal energy management, and optimization of energy using the battery. The second technique is based on an artificial neural controller to regulate a bidirectional DC/DC converter, which connects between the battery and DC_Bus. The second controller shows a very good stabilization of the microgrid and high performance of the energy management. In the third approach, we propose a smart technique based on fuzzy logic for smart energy management in the same microgrid with different meteorology conditions. The proposed technique shows high performance for microgrid control and energy management compared to other techniques. Of course, various improved multi-objective evolutionary algorithms and advanced control structures, such as robust loop shape controllers and model predictive controllers, can increase the frequency control performance of an islanded microgrid even further. The results of this thesis can be better if you think about the following: • Hardware implementation of the three methods (PID, ANN, and FL) to show how well they work in the lab. • The integration of energy optimization into the energy management system. This includes things like the price of electricity and the amount of CO2 that is released into the air.