Given the negative impact of electricity production on the environment, the development of smart grids and microgrids using non-polluting renewable sources is recommended. However, these systems must operate properly to be deployed. In this paper, our purpose is to ensure control of a crucial problem in the development of microgrids, which is frequency deviation. To achieve this, linear matrix inequality (LMI) is applied to the sliding mode controller (SMC) added to an integral controller, providing robustness against disturbances and uncertainties. The combination of this is because SMC is a robust controller, the integral controller is fast response for steady state, and the LMI approach is good for controller design. The proposed microgrid consists of renewable sources as primary sources, such as wind generators, solar photovoltaic and solar thermal systems, fuel cells, and hybrid storage devices consisting of supercapacitors and batteries, and diesel generators. The system is influenced by load variations and intermittency of PV and WTG sources. To have an optimal controller, a particle swarm optimization algorithm (PSO) is used to fine-tune the controller's parameters, with ITAE as the objective function. Simulation results using MATLAB/Simulink software were presented with many scenarios, to demonstrate the performance in terms of overshoot, undershoot, and response time of the proposed controller compared to other conventional controllers.