This paper presents an energy management strategy using a Stateflow controller related to DC microgrids with the important penetration of renewable energy. The increase in world electricity demand is one of the principal drivers of the exhaustion of fossil fuels and increased greenhouse gas emissions. To solve these problems, several countries have adopted actions for widespread renewable energy deployment, which includes wind energy, solar power, biomass power, tidal, and hydropower. These sources are considered as significant in delivering clean energy and reducing greenhouse gas emissions for sustainable improvement. As these sources play an increasingly vital role in the global energy landscape, the efficient management of these intermittent sources is essential for grid stability and sustainability. This paper aimed to develop an energy management strategy for DC microgrids to supply power to a DC microgrid system. The main objective of this paper was to implement an energy management system to ensure the proper operation of DC microgrid systems utilizing Simulink blocks available in MATLAB/Simulink 2020b software. The simulation results demonstrated that the developed energy management algorithm was unconditionally reliable, ensuring the proper operation of the microgrid systems. Additionally, the results demonstrated that the energy management strategy exhibited robust performance across different scenarios, effectively balancing energy generation and consumption while ensuring the reliable operation of the microgrid system. Moreover, the developed algorithm model presents another advantage, as it enables users to access and to change any control parameters within the DC microgrid. By comparing these results with the literature, the developed energy management algorithm provides safety and the automatic control of the microgrid. [ABSTRACT FROM AUTHOR]