Increasing electrical energy demand, as well as fossil fuel shortages and environmental concerns have caused to use uncommon sources such as distributed generations (DGs) and renewable energy sources (RESs) into modern power systems. A Microgrid (MG) system consists of several DGs and RESs which is responsible to provide both electrical and heat powers for local loads. Due to the MGs nonlinearity/complexity which is imposed to the conventional power systems, classical and nonflexible control structures may not represent desirable performance over a wide range of operating conditions. Therefore, more flexible/intelligent control methods are needed most of the past. Hence, in this paper addresses to design an online/self-tuning PIcontroller based on artificial neural networks (ANNs) for optimal regulating the MG systems frequency.