## 5 Proposed Approach  
Energy efficiency is a critical consideration in Wireless Sensor Networks, mainly when the nodes are battery-operated, which is typically the case. Each sensor node is equipped with a finite energy source, and in scenarios requiring smaller sensor nodes, the corresponding batteries must also be reduced in size. This limitation creates significant problems in managing the basic functions of the sensor, such as sensing, communication, and on-board data processing. The energy needed for the transmission of data packets increases with the transmission distance, which requires careful selection of an optimal transmission range to save energy and extend the operational lifetime of the network. In addition, energy consumption levels can increase due to high communication overhead, especially in networks with heavy data traffic. CHs are chosen randomly, and without mechanisms for effective load-balancing, energy depletion often happens unevenly, with particular nodes experiencing much higher energy exhaustion than others. KNN clustering is a type of supervised machine learning used to segment data into clusters, such that the data points within a single cluster are more similar compared to other clusters. That is particularly advantageous for analysing large and complex datasets, enabling the identification of patterns and trends that would otherwise remain undetected. Clustering also facilitates the prediction of unlabelled data. To enhance the clustering mechanism of WSN protocols, the proposed approach integrates the K-Nearest Neighbours algorithm into WSN protocols. It analyses training data and classifies new test data based on predefined distance metrics. The algorithm identifies the K-Nearest Neighbours of the test data, and the majority of class labels among these neighbours determine classification. The choice of K in the KNN algorithm is a critical factor influencing clustering efficiency and network performance. A small value of K (e.g., \(K=1\) or \(2\)) can make the algorithm overly sensitive to noise, leading to unstable cluster head selection and uneven energy distribution. Conversely, a large value of K (e.g., \(K>10\)) may result in overly generalised clustering, increasing communication distances and energy consumption. To determine the optimal value of K, we conducted simulations with different values of K (\(K=1,3,5,7,10\)) and evaluated their impact on clustering accuracy, energy consumption, and network lifetime. The results indicate that a value of K = 5 provides the best trade-off between clustering accuracy and energy efficiency for the given network parameters. Future work will explore adaptive methods for dynamically tuning K based on real-time network conditions; therefore, the choice of K (number of neighbours) is particularly important, as a small K can make the algorithm overly sensitive to noise, while a large K may reduce clustering accuracy. The following modification is proposed for the protocols: LEACH, SEP, TEEN, and DEC:  
**STAGE 1**: Initialisation  
* Network Setup: The network is initialised with n sensor nodes randomly distributed in a 2D field (100 m \(\times\) 100 m). Each node is assigned initial energy and coordinates (\(x,y\)). * Cluster Area and CH Initialisation: Initial CHs are selected using the original protocol's mechanism All nodes' coordinates, energy levels, and distances are stored in a database (\(DB\)). * Check and Remove Dead Nodes: Check and remove all dead cluster heads and nodes and modify (\(DB\)). **STAGE 2**: Distance and energy calculations  
* Check Distances:  
* Calculate the distance from each CH to the base station. * Calculate the _TOTAL_ distance (\(D_{total}\)) for every CH. * Calculate the _TOTAL_ energy (\(E_{total}\)) for every CH.