Wireless sensor networks contain of many sensors that can serve as powerful tools for data collection in environments. A key challenge in these networks is the limited lifetime of sensor batteries. Ideally, all nodes would exhaust their energy simultaneously or through regular scheduling, maximizing the lifetime. Consequently, the primary concern is achieving optimal energy utilization to extend the network's lifetime over a logical duration. Depleting the batteries of the sensors means stopping the operation of the network, because it is practically impossible to replace the batteries of thousands of nodes. To address this issue, the low energy adaptive clustering hierarchical (LEACH) protocol has been widely recognized as one of the prominent solutions for clustering WSNs. However, the random selection of cluster heads in each round under the LEACH protocol fails to guarantee proper convergence. To overcome this limitation, this paper proposes a refined approach by utilizing a genetic algorithm and a novel objective function that incorporates various factors, including energy level and distance. The algorithm employs chromosomes to represent CHs and facilitates the selection of cluster nodes. Notably, the proposed algorithm dynamically performs clustering, meaning that clustering is conducted iteratively, considering identifying dead nodes. By leveraging this approach, the algorithm significantly enhances the clustering quality, ultimately leading to an increased network lifetime. To validate its effectiveness, it is compared with LEACH, LEACH_E and LEACH_EX algorithms, demonstrating its superior capabilities. On average, the proposed algorithm has more alive nodes in the network, and the remaining energy is at least 11% higher than the best other algorithms. [ABSTRACT FROM AUTHOR]