## 3 Energy Management System  
The EMS for hydrogen-based microgrids comprises three main components: the power system, the hydrogen storage system, and the control system. The power system includes an energy source, such as a solar panel or wind generator, while the hydrogen storage system includes hydrogen production, storage, and utilization components. The control system coordinates these components to ensure a constant supply of renewable energy to the microgrid [5]. One of the challenges of hydrogen technologies-based microgrids is the low energy density of hydrogen. It requires a large volume of hydrogen to store the same amount of energy compared to other conventional energy sources. Therefore, hydrogen storage systems need to be optimized to reduce the space requirement. Meanwhile, centralized EMS may be used for island microgrids [42]. The challenge could be overcome with a fuzzy control system to control the battery, super-capacitor, and hydrogen storage. It will increase the complexity of this study, but with the optimization technique, it will be less costly [43]. However, in this study the PSO technique is used. To calculate all the values of the system, all costs sum up in a PSO [12]. Moreover, complexity of this system could be vanished simply by offline energy supervision methods for different combinations of energy storage systems according to different kinds of applications like MGs and EVs. Optimization techniques enable microgrid EMS to make informed decisions regarding resource allocation, demand response, energy trading, grid stability, and cost minimization. By leveraging these techniques, microgrids can improve their operational efficacy, reduce costs, integrate renewable energy resources effectively, and enhance the overall system reliability and resilience [44]. So, in this research the lack of standardization of hydrogen storage, distribution, and consumption technologies is addressed with an optimization technique. This lack of standardization makes it difficult for hydrogen-based microgrids to become a mainstream energy source. The MG system includes a hydrogen storage reservoir to store the produced hydrogen. The amount of stored hydrogen can be calculated at any time using the mathematical equations outlined in Section 2. It depends on the variables of the electrolyzer and fuel cell flow rates. Meanwhile, the efficiency of the fuel cell could be estimated per the requirements of the system [15]. The EMS can manage one variable at each time. In modern MG systems, it's becoming more common to employ two energy management techniques simultaneously to enhance system efficiency and reduce operational costs but to sacrifice on the one-time cost. After the system cost has been determined using optimization techniques, the next milestone to address is improving the power quality. The improvement in power quality can be demonstrated by the voltage convergence across the entire system achieved through PSO. The constraints of the optimization problem include factors such as the output power generated by each type of DER, maintaining power balance within the MG system, and managing the energy exchange between its components. The power generation constraints for each type of DER include both the minimum and maximum limits of power output at given time t, and it can be calculated in (17):  
\[P_{minimum}\leq P_{output}\leq P_{maximum} \tag{17}\]  
where \(P_{minimum}\) and \(P_{maximum}\) are the limits of output power measured in watts, and \(P_{output}\) is the acceptable output power. At each time t, the total electrical load within the hybrid microgrid system must be equal to the power generated by all DERs and the total amount of energy exchanged with the grid, and it can be measured by using (18):  
\[ \begin{split} P_{solar}(t)\times\eta_{DC/DC}+& P_{wind}(t)\times\eta_{AC/DC}+& P_{fuel\ cell}(t)\times\eta_{DC/AC}=P_{selt\_grid}(t)\times E_{selt}(t)-P_{ buy\_grid}(t)\\ &\times E_{buy}(t)+& P_{Load}(t)\end{split}