Microgrid properties including bidirectional power flow in feeders, fault level decrease in the islanded mode, and intermittent nature of distributed generators (DGs) result in the malfunctioning of microgrid conventional protection schemes. In the present article, a protection scheme based on impedance is suggested for fault detection in LV and MV overhead and cable distribution lines in both grid-connected and islanded modes. To determine a fault detection index, new suggested equivalent circuits for doubly fed lines are applied. Relay location data and magnitude of positive sequence voltage of the other end of the line are used. It is simulated by PSCAD and MATLAB software in order to evaluate its performance and approve its validity. This scheme can detect even high-impedance faults in both grid connected and islanded modes in LV and MV overhead and cable distribution lines. In addition, it is robust against load and generation uncertainty and network reconfigurations. Low sampling rate and minimum data exchange are among the advantages of the proposed scheme.