The clustering strategy is the most effective and efficient way to preserve energy in the Wireless Sensor Network (WSN). However, the cluster heads in the hierarchical clustering approach use the majority of the energy that is required to carry out the operations. These operations include receiving the data from the sensor nodes, aggregating it, and then eventually transmitting it to the base station. When choosing the appropriate cluster head, you can play a significant part in reducing the amount of energy that is consumed by the WSN and, as a result, extending its lifespan. A technique for the selection of energy-efficient cluster heads that is based on the particle swarm optimization method is proposed in this study (PSO-EECH). For the method that has been proposed to measure the amount of energy used, we need to take into account the cluster distance, the distance between each sensor node and the nodes that are nearby, and the amount of residual energy that is left in sensor nodes. The aforementioned structure is also capable of doing cluster building, in which the non-cluster head node can follow its CH based on the determined weight function. The proposed PSO-EECH approach has been put through extensive testing, and the results have shown that it possesses a high degree of accuracy in every scenario. The outputs of the proposed algorithm are compared with those of other clustering-based algorithms already in existence, and the conclusions of this comparison have reported that our method outperforms the other existing methods.