In terms of enhancing overall energy usage, wireless sensor networks (WSNs) can run with minimal energy to extend their lifespan. Due to limited power resources, the optimal base station (BS) location could prolong the overall sensor network's lifetime. In this paper, an algorithm to find the optimal location of BS is proposed. The concept of BS virtual locations grid is used, where BS virtual locations grid within the network's area is created. To find an optimal BS location, the distances between all sensor nodes from virtual locations in the grid are considered, where one of these virtual locations will be chosen as the optimal location. Consequently, BS changes its location to another optimal location each specific number of iteration according to the number of alive sensor nodes within the network (BS mobility). The proposed algorithm is applied to the Stable Election Protocol (SEP) with two and three energy levels. Using the original SEP with two and three energy levels protocols in terms of the network's lifetime and energy consumption, the performance of the algorithm is compared. It is observed that, decreased energy consumption has been achieved, as well as the lifetime of the network has been significantly improved.