Microgrids are localised power system that use local power generation to supply electricity to nearby loads. This idea has gained popularity with the development of battery energy storage system (BESS) and the emergence of renewable energy sources (RES). The integration of electric vehicles (EVs) into the grid has made it possible to integrate batteries and RES without significantly altering the system. The operation of microgrids is has discussed in this study with a special emphasis on power flow control during system disturbances and transitions. This article describes an algorithm designed to optimise the regulation of power, voltage, and frequency in a microgrid that includes EVs. The results of this study show that load control and energy distribution using simulation studies may be done effectively. This study used suggested algorithm to show stable frequency and controllable voltage dips. Additionally, this study contributes to a better knowledge of microgrid control.