**6. Conclusions**

This paper proposed a new approach for energy management systems for microgrids with loads, PV units, and EV parking lots. The management system provided four charging modes that could be chosen by the users of the parking lot, and the EV factors that must be considered in charging modes were formulated.

The proposed EMS was evaluated using a 450 kW typical microgrid. As designed, the ULTRA mode charged the vehicles with nominal power within the expected time. In the FAST mode, the charging level and the priority level were achieved, since the EMS applied a charging limitation when demand exceeded the microgrid capacity. ECO mode was designed to provide the minimum charging cost to the user; thereby, over the analysis, it was verified that the vehicle charging occurred along the PV surplus, and no extra demand was requested from the microgrid in high demand periods. The V2G mode was developed to provide several benefits to the microgrid and also to attend to the user preferences. The V2G vehicles were discharged in high demand periods to support the microgrid loads and/or the other modes, and the same ones were charged in the PV surplus period. This performance occurred due to the relation between the price of V2G and the grid energy, taking the battery degradation into account to determine the charging power profile. The optimization algorithms were executed in convenient time in a Raspberry Pi 3 platform and were tested with an dSPACE emulation environment. All EV user preferences were met, as well as a relief in the valley of the microgrid demand, providing economic benefits to the microgrid agent.

**Author Contributions:** The authors contributed equally in the research: Conceptualization: E.G.C. and G.A.S.; Formal analysis: G.A.S., R.C. and C.M.d.O.S.; Investigation: E.G.C., G.A.S. and J.P.d.C.; Project administration: J.P.d.C.; Resources, C.M.d.O.S.; Supervision: J.P.d.C.; Validation: G.A.S.; Writing–original draft: E.G.C. and G.A.S.; Writing–review and editing: E.G.C., R.C. and C.M.d.O.S. All authors have read and agreed to the published version of the manuscript.

**Funding:** This work was supported by the Research and Development project PD 2866-0468/2017, granted by the Brazilian Electricity Regulatory Agency (ANEEL) and Companhia Paranaense de Energia (COPEL).

**Acknowledgments:** The authors thank the Funding Authority for Studies and Projects (FINEP), the Coordination for the Improvement of Higher Level-or Education-Personnel (CAPES), the Brazilian National Council for Scientific and Technological Development (CNPq), the Fundação Araucária, and the Universidade Tecnológica Federal do Paraná (UTFPR) for their complementary support to this work.

**Conflicts of Interest:** The authors declare no conflict of interest. The funders had no role in the design of the study; in the collection, analyses, or interpretation of data; in the writing of the manuscript; nor in the decision to publish the results.
