The main problem in the operation of micro-grids is controlling the voltage and frequency. The inertia of the whole grid is low, so the operation of the system is interrupted by sudden changes in load or incidence in the absence of a proper control system. In order to solve this issue, various control structures have been proposed. In this paper, an optimal distributed control strategy for coordinating multiple distributed generation instances is presented in an islanded microgrid. A secondary frequency control method is implemented in order to eliminate voltage deviation and reduce the small signal error. In this layer, an optimized PID controller is used. PID controller optimization is carried out via the Honey Badger Algorithm, and results are obtained using the MATLAB software. According to the results, inadequate adjustment of a secondary loop leads to poor and unacceptable outcomes, and the necessary power quality is not achieved. However, by using the proposed method, a proper performance of the microgrid in the face of disturbances is achieved.