Nowadays, electricity consumption is increasing rapidly which leads to conventional power systems exhaustion. Therefore, micro-grids (MGs) implantation can enhance the resilience of power systems by implication of new resources, such as renewable energy sources (solar panel and wind power systems), electric vehicles (EV), and energy storage systems (ESS). This paper proposes a new strategy for optimal power consumption inside one microgrid; then, the approach will be extended to optimize the power consumption to enhance the resilience in the case of multi-MGs systems. The system controller of each microgrid has been implemented using ESP32 microcontroller and Raspberry IP4. The proposed approach intends to enhance the resilience of the system to react to any contingency in the system such as loss of power linkage between MG and the network in case of any natural disaster, especially in the rural area. Two controllers are implemented; the first one ensures MG autonomy by the efficient use of its own sources. The second one handles the system resilience cases by demanding/delivering power from/into neighbor microgrids. Hence, this work enhances the system resilience with an optimal cost. Thus, the MG can offer ancillary services for the neighboring MGs.