Enhancing the Lifetime of Wireless Sensor Networks Using Fuzzy Logic LEACH Technique-Based Particle Swarm Optimization

Wireless sensor networks (WSNs) have attracted significant attention because of their widespread use in health care, habitat tracking, disaster prevention, agriculture, monitoring areas, fire tracking, and other real-life applications. The lifetime of WSNs must be prolonged to increase their use for various applications. One of the most effective methods for improving the network’s lifetime is clustering with the optimal cluster head (CH). This study proposes a fuzzy Logic (FL) low-energy adaptive clustering hierarchy (LEACH) technique-based particle swarm optimization (PSO). It employs hybrid PSO and a K-means clustering algorithm for cluster formation. It selects the primary CH (PCH) and secondary CH (SCH) using FL. Extensive simulations were conducted using a simulation program to validate the proposed protocol’s performance. Furthermore, the proposed protocol was compared with traditional algorithms, such as fuzzy c-means (FCM) clustering and FLS-based CH selection to enhance the sustainability of WSNs for environmental monitoring applications, LEACH-Fuzzy clustering protocol, and LEACH based on energy consumption equilibrium. The results confirmed that the proposed protocol efficiently balances energy consumption to improve wireless sensor network performance and to maximize throughput. The simulated results indicated that network lifetime was improved by more than 46% and packet transmission by 17.6%.


I. INTRODUCTION
Wireless sensor networks (WSNs) consist of several sensors (a few tens to thousands), with characteristics such as self-organizing, low cost, and random deployment [1]- [3]. Sensors are tiny nodes randomly distributed throughout the network area. They detect environmental signals and then transfer sensed data to the base station (BS). They have mostly been used for habitat monitoring, disaster prevention, health care, agriculture, monitoring regions, and fire tracking [4]. Sensor nodes have tiny batteries that are costly to recharge or replace through complex environments. In real-world applications, each node in WSN must consume minimal energy as possible for data gathering and transmission to extend the WSN's lifespan.
Researchers have studied numerous energy-efficient WSN operation strategies using clustering. Clustering has been an effective approach for reducing energy utilization, increasing the stabilization of the network topology and the lifetime of the network. The lifetime can be specified as the round when the first node dies (FND), half of the nodes die (HND), or last node dies (LND) [5]- [7].
In WSNs, the routing protocol determines the path for sending data to the sink using the least amount of energy [8]- [10].
In clustering routing, WSNs are split into various clusters. The main processes are cluster formation, cluster head (CH) selection, and routing between nodes and BS [11]- [16]. Every cluster includes CH and cluster members (CMs). The clustering-routing protocol consumes less energy than the other routing protocols.
Low-energy adaptive clustering hierarchy (LEACH) [17], [18] is a popular clustering-routing protocol. It employs a distributed approach for the formation of clusters and CH selection. Although it is a simple algorithm, a random selection of CHs results in increasing energy usage and earlier death.
This study proposes a fuzzy Logic (FL) low energy adaptive hierarchy (LEACH) technique-based particle swarm optimization (PSO) that applies hybrid PSO and a K-means clustering algorithm to centralized approaches in cluster creation and FL for selecting CHs, namely, primary CH (PCH) and secondary CH (SCH). FL is used to transform an input space into an output space [2]. Communications among CMs, CHs, and BS follow the standard rules for the number of hops.
The contributions of this work using the proposed technique are summarized as follows: • Cluster construction is performed using a hybrid particle swarm optimization (PSO) and K-means clustering algorithm as a centralized strategy.
• The WSN's lifespan and throughput are enhanced by employing three parameters to perform PCH selectionusing FL, including energy level, distance to cluster's center, and distance to BS.
• To improve network stability, FL is used to select the SCH by employing two parameters: energy level and distance to PCH.
• Using simulation software, the proposed protocol is compared with conventional algorithms, such as FCM clustering and FLS-based CH selection, to enhance the sustainability of WSNs for environmental monitoring applications (Rajput and Kum) [19], LEACH-fuzzy clustering (LEACH-FC) protocol [2], and LEACH based on energy consumption equilibrium (Chen et al.) [20]. The reminder of the paper is organized as follows: Section 2 discusses related works and current problems. Section 3 presents the network system model. Section 4 presents our proposed technique, including the hybrid PSO and a K-means clustering algorithm and the CHs selection algorithms. Section 5 presents simulation experiments for the proposed technique and compares it with stateof-the-art methods. Finally, section 6 presents the conclusion.

II. RELATED WORK
The technology for wireless sensor systems is growing quickly. Many protocols for the effective routing of WSNs have been developed. These protocols rely on energy conservation and network lifespan extension.
Heinzelmen et al. [17], [18] proposed the low-energy adaptive hierarchical clustering protocol (LEACH). It is among the most well-known hierarchical protocols. LEACH's primary functions are to randomly establish clusters and to transfer data between CMs and CHs, as well as between CHs and BS. It is a simple algorithm. However a random selection of CHs results in increased energy consumption and an earlier death.
Heinzelmen et al. [21] introduced a centered clustering protocol LEACH-centralized (LEACH-C). It calculates the average energy level of CMs at BS. It does not choose as CHs those that have an energy level below average. Centralized clusters are better than LEACH clusters, but this protocol does not offer larger networks scalability and robustness.
Mumtaz et al. [22] proposed the energy aware routing using improved LEACH protocol (E-LEACH). The number of CHs is estimated with a parameter equal to the square root of the total number of sensors by application of a minimum spanning mechanism. The lifespan of the protocol network is increased by maximising energy during the initialization stage, but still random selection of the specific number of CHs leads to more energy consumption and earlier death of these nodes.
Sharma et al. [23] presented a method for the determination of cluster heads, Distance-based Cluster Head (DBCH). Both energy level and distance from nodes to BS were used. Despite this, CH still had many tasks to be performed according to its energy level. It needed to use a vice cluster head (VCH) or a SCH to minimize its energy consumption by performing some tasks.
Loscrì et al. [24] introduced a two-levels hierarchy for lowenergy adaptive clustering hierarchy protocol (TL-LEACH). It performed a two-tier transmission operation. Data were transferred to the SCH from CMs and then to PCH directly connected to BS. The selection of PCH and SCH is not dependent both on energy level and distance measures. This results in greater energy efficiency.
Chen et al. [20] developed the LEACH algorithm based on the energy consumption equilibrium protocol. PCH selection is performed in such as a LEACH protocol. Two levels of the transmitting mechanism involve transforming data between the simple nodes and SCH. Then, transforming between the SCH and PCH. PCH communicates directly with BS. This protocol extends the network's life by optimizing energy during the setup stage. However, it may increase energy consumption and the earlier death of such nodes if the clusters are randomly created and the PCHs are selected randomly.
Abdulsalam and Kamel [25] proposed a centralized clustering protocol, the weighted low energy adaptive clustering hierarchy aggregation algorithm for data streams in WSNs (W-LEACH). This protocol was created with non-uniform WSNs in mind. Initially, all nodes were assumed to have the same energy. CH is chosen based on the weight value given to each sensor. Regardless of whether or not that node has previously been elected as CH. Despite this, CH still had many tasks to be performed according to its energy level and needed to use a VCH or a SCH to minimize its energy consumption by performing some tasks.
Kim et al. [26] introduced a CH election mechanism using FL in WSN (CHEF) protocol. Each sensor produces a random number among zero and one. If that number falls below a threshold, the sensor uses FL to determine the probability. CH is chosen as a node having higher chance. Two inputs are used by the fuzzy inference system (FIS): residual energy and the distance between nodes. This protocol improves energy use, but still presents the possibility that the random number of nodes chosen for CHs is a problem that leads to a number of suitable nodes not allowed in the selection phase.
Bagci and Yazici [27] introduced an energy-aware fuzzy approach to unequal clustering in WSNs (EAUCF) protocol. The network region is broken up into unequal clusters. Clusters are smaller than those nearer to BS. CHs are elected based on FL. The FIS takes two inputs: the remaining energy level and distance from the sensor to BS. All sensors can use the fuzzy inference method to measure the chance of winning in each round. It compares the output to a random number between 0 and 1. The Sensor is chosen as CH if the output is large. Repeating the entire process of selecting CH in each round leads to energy conservation. The CHEF method prevents a suitable node from being selected because of the comparison between the fuzzy output and the random number.
Baranidharan and Santhi [28] developed a distributed load balancing unequal clustering in WSNs using the FL approach (DUCF) protocol. They used three inputs in FIS: energy level, node temperature and distance from the node to the BS. All sensors can use FIS to measure the chance of winning in each round. Although this approach has taken the best cluster node into account, the selection of CHs increases energy consumption as it is performed in each round.
Zhang et al. [29] proposed the energy-efficient distributed clustering algorithm for WSNs with nonuniform distribution (EEDCF) using FL. It is a completely distributed clustering technique. It analyzes whether each node fits into the CH compared to its neighbors using a TSK FIS. The input parameters were energy level, node degree, and neighboring node energies. Despite this, CH had many tasks to be performed based on its energy level. It must use a VCH or a SCH to minimize its energy consumption by performing some tasks.
Moh'd Alia [30] proposed the decentralized fuzzy c-means-based energy-efficient routing protocol for WSNs (DCFP). It is a fuzzy c-mean algorithm energy-efficient WSN routing protocol. The clusters are created using the fuzzy c-mean technique. The node closest to its cluster center is then picked as CH. The average energy level for all CMs per cluster is calculated using CH from the previous round. Then,the target function is executed to choose CH for the following round. The proposed protocol constructs clusters with less intracluster communication. However, it overloads the present CHs for all CMs to elect CHs for the following round with iterative computations. For the proposed protocol, CH works only in the present round.
Lata et al. [2] proposed a fuzzy clustering protocol (LEACH-FC) by selecting the optimal PCH is based on FL. The node with lower centrality than others and consuming less energy for transferring data is elected as CH. The results confirmed that the LEACH-FC algorithm performed better than the LEACH protocol. However, CH selection is not the best in several scenarios and must use a VCH or a SCH to minimize its energy consumption by performing some tasks.
Dohare and Singh [31] introduced the PSO-based deterministic energy-efficient clustering (PSODEC) in IoT. Based on the largest remaining energy, this method chooses the CH node among the CMs. The nodes are distributed at random throughout the network. The cluster is constructed using the K-means algorithm. After that,the PSODEC method is utilized for choosing PCH node in every cluster. Simulation is run, as well as the findings show that the PSODEC performed better than LEACH and DEC. But even so, because the CH's remote location from the BS, communication can be problematic in some scenarios.
Sert et al. [32] proposed a two-tier distributed fuzzy protocol (TTDFP). It is an energy-efficient protocol for data aggregation in multihop WSNs. In CH selection, it examines proportional node connectivity, node's remaining energy, and distance to BS. In selecting a route, it examines the average link remaining energy and proportional distance. It uses FL to handle the uncertainties that arise in these phases.
Sert et al. [33] introduced a multi-objective fuzzy clustering algorithm (MOFCA) for WSNs that is not only energyefficient and distribution-independent. In calculating the CH competition radius,the suggested MOFCA algorithm evaluates the remaining energy levels, distance to BS, and density. it uses FL to handle the uncertainties that arise in these phases.
Sert and Adnan [34] proposed a modified energy-efficient clonal selection algorithm (CLONALG-M) for rule-based Wang et al. [35] developed a compressive sensing-based (CS-based) and clustering technique to handle load balancing in WSNs.
Lin et al. [36], introduced the game theory-based energyefficient clustering-routing protocol (GEEC) to solve the load-balancing problem in WSNs using CHs. Table 1 shows the comparison of several LEACH protocols in terms of CH selection criteria, number of clusters, clustering level, medium access, hop count, and time complexity.

III. SYSTEM MODEL
Sensor nodes have been assumed in this section based on the network model. The energy consumption of the sensor nodes has been discussed based on a radio model (energy model).

A. NETWORK MODEL
Suppose that N sensors are randomly dispersed within a twodimensional square area, and that sensors within that area collect information regularly. The sensed information must received, aggregated, and transmitted to BS. PCH still has many tasks to be performed based on its energy level. It must use a SCH to minimize its energy consumption by performing some tasks, as shown in Fig.1. The SCH collects sensed data from all CMs through clusters and aggregates them. After aggregation, SCH transmits aggregated data to PCH through its cluster. The PCH receives and transmits the data to BS. Communications among CMs, CHs, and BS follow the standard rules for the number of hops.
The network model has the following characteristics: 1) The sensor network is in a fixed state. If the nodes have been deployed, they cannot be relocated. 2) After deployment, the BS's position is fixed and known to all CMs.
3) The BS's energy is unlimited. 4) Each CM has a GPS device that can save its location.

5) Data aggregation is performed by all SCHs, and infor-
mation is sent to the BS by all PCHs. 6) Communications among CMs, CHs, and BS follow the standard rules for the number of hops [2], [18], [22].

B. RADIO MODEL (ENERGY MODEL)
The recommended technique is implemented on the radio model employed by the LEACH protocol [17], [18]. Each sensor node in WSN requires energy to perform clustering and transmission of data from other sensor nodes. Two distinct energy models are presented: free-space model and multipath fading channel models [21]. Power attenuation is caused by the distance d between the transmitter and the receiver. When this distance is less than the threshold value (d 0 ), the algorithm uses the free-space model (d 2 power loss). Otherwise, it uses the multipath fading channel model (d 4 power loss), and the threshold d 0 is given in (1) [37], [38]: where, E fs is the free-space parameter, and E amp is the multipath parameter.
If the transmitter transmits B-bit data to the receiver across a d distance, the transmitter's energy consumption (E TX ) can be computed as given in (2) [37], [38]: where, E elec is the electronics energy dissipation for B-bit transmission or reception, and d is the distance between the transmitter and receiver. To receive B-bit data, sufficient energy (E RX ) is obtained from (3) [37], [38]:

IV. PROPOSED FUZZY LOGIC LEACH TECHNIQUE-BASED PSO
In this study, a FL LEACH Technique-based PSO is proposed for energy efficiency and for maximizing the number of bits transferred to BS. As Shown in Fig.(2), the proposed protocol is divided into setup and steady phases (three main steps). The setup phase consists of cluster formation using a hybrid PSO and K-means clustering algorithm. The sensor network is in a fixed state. If the nodes have been deployed, they cannot be relocated. Because we are testing fixed nodes, there is no need to repeat cluster formation per round, as shown in Fig.(2).
The steady phase includes three main steps: PCH selection, SCH selection, and intracluster data communication. This phase is repeated in each round, as shown in Fig.(2), because the energy of CMs, PCHs, and SCHs changes during the rounds; thus, there is a need to repeat it.
First, cluster formation is performed depending on the hybrid PSO and K-means clustering algorithm. Input data, which are the locations of the (N) sensors, are clustered into a specified number of clusters (N c ).  N c should be obtained using Gap statistic clustering evaluation. The gap statistic compares the total within intracluster variation for various values of N c to their predicted values under the data's null reference distribution. The value that maximizes the gap static will be used to determine the best clusters [39]. Distance metric (Euclidean distance) is used for to compute the criterion values. This indicates that the clustering structure differs significantly from a random uniform distribution of points.
Second, PCH is selected based on the node's residual energy, distance from the node to the cluster's center, and distance from the node to BS. Third, SCH is selected based on the node's energy level and distance from the node to PCH within its cluster. Furthermore, the BS runs the FL to select the entire PCH and SCH nodes in the network.
Finally, intracluster data communications, all CMs sense data and transfer them to SCH within the cluster. Each SCH acquires and aggregates the data from all CMs for transmission to PCH. Each PCH receives data from all SCHs and forwards them to the BS.

A. CLUSTER FORMATION
In the context of data clustering, the input data are divided into a given number of clusters depending on the similarity between data vectors. The output is the clusters with the associated data over each cluster, thus determining the cluster center [40]. The network clustering in our proposed technique is based on the hybrid PSO and K-means clustering algorithm.

1) K-MEANS CLUSTERING ALGORITHM
K-means clustering divides data vectors into a preset number of clusters using Euclidean distance as a similarity metric. VOLUME 10, 2022 Data vectors inside a cluster have minimal Euclidean distances between them and are linked to a single centroid vector, representing the cluster's ''midpoint''. The centroid vector is calculated by taking the mean of the data vectors in the relevant cluster.
The number of cluster centers in K-means is obtained by applying Gap static clustering evaluation on input data (sensor nodes) to obtain the exact number of clusters. Then, define the outcome of the K-means clustering algorithm as one of the particles for the PSO algorithm to be used in the clustering process.
In this paper, the data vectors are the sensor nodes. The K-means algorithm will be described as follows: 1) Calculate the distance from each sensor node to each cluster center using the Euclidean distance [23], [41] from (4): where, points s = (s 1 , s 2 ) and c = (c 1 , c 2 ) are the sensor node and cluster center coordinates, respectively. 2) Assign the sensor node to the cluster with the closest center. 3) After assignment for all sensors, recalculate the new cluster center (c) using the mean [40] as given in (5): where, n j denotes the number of sensor nodes in the cluster j, and S p denotes the subset of sensors that forms the cluster C j , until a stopping criterion is achieved. In this paper, the stopping criterion is satisfied when a specified number of iterations have been exceeded [40].

2) PARTICLE SWARM OPTIMIZATION
PSO is a population-based stochastic search algorithm inspired by the social behaviour of flocks of birds' [42], [43]. A swarm in the context of PSO, refers to a collection of possible solutions to the optimization problem, with each possible solution denoted by a particle. The PSO aims to discover the particle position that best assesses a given fitness (objective) function. Every particle provides a position in search space and is flown across it, updating its position toward the personal best position of the particle. During the flow, a particle position is updated using (6) and (7) [40]: where, w is the inertia weight, c 1 and c 2 are the acceleration coefficients, r 1 and r 2 are random numbers between 0 and 1, and D is the input dimension. The cognitive component is a function of the particle's distance from its best personal position. The social component is a function of the particle's distance from the global best position. The global position is the best particle in the neighborhood of the particle. In this paper, the PSO was stopped after a certain number of iterations were reached.

3) HYBRID PSO AND K-MEANS CLUSTERING ALGORITHM
In the proposed algorithm, a single particle denotes the N c cluster center vectors structured as follows: A swarm represents a possible clustering for the sensor nodes. Using the hybrid PSO and K-means clustering algorithm, data vectors (sensor nodes) can be clustered as follows: 1) Defines the outcome of the K-means clustering algorithm as one of the particles. 2) Initializes the remaining swarm's particles (cluster centers) randomly. 3) For t=1 to t max do: a) For each particle i do b) For each sensor node i) Computes the Euclidean distance d(s,c) using (4). ii) Assigns node to cluster c with closest cluster's center. iii) Calculates the fitness of particles as the quantization error J as given in (10): c) Updates personal and global best positions. d) Updates the cluster centers using (6,7). Where, t max denotes the max number of iterations [40].

B. PCH SELECTION USING FL
FL is used for decision-making, where the input conditions are considered to obtain the desired result as obtained from the ''if-then'' statement. Two fuzzy models are used: Mamdani [44] and Sugeno [45]. The Mamdani fuzzy model is widely used in various applications [19]. Thus, for our proposed protocol, the Mamdani method (one of the most widely used methods) is used as a fuzzy inference methodology. In our proposed protocol, each sensor runs a FL every round to calculate its chance of becoming PCH. That PCH selection is based on three node parameters. Crisp input parameters for the FL were examined using three input variables, given as follows: Residual-energy: available energy level in each node. Distance-to-cluster's center: distance between CM and its cluster's center.
Distance-to-BS: distance between CM and BS.
To determine distance-to-cluster's center and distance-to-BS, we used the Euclidean distance given in (4). Consequently, CMs have easier access to the node, which is nearest to the cluster center point. It indicates that other nodes can spend less energy on data transmission through the node as PCH.
Each input function (fuzzy variable) contains three membership functions M f with varying degrees of function. Three levels were used for the lingual representation of node energy, as shown in Fig.3: low, medium, and high. Here, M f ranges from 0 to 0.5, as calculated form (11) [2]. Fig.4 shows that the node's distance-to-cluster's center has three levels for the lingual representation: near, adequate, and distant. Here, M f ranges from 0 to 140, as calculated form (13) [2].
The node's distance-to-BS, as shown in Fig.5, has three levels for the lingual representation: near, adequate, and distant. Here, M f ranges from 0 to 70, as calculated form (12) [2].
Nine membership functions have been established to indicate the decision of a node as a PCH selection chance: very weak, weak, little weak, little medium, medium, high medium, little strong, strong, and very strong as illustrated in Fig.6 an expert-defined fuzzy output function (Chance) [46], [47].
Nine membership functions were used instead of seven membership functions of previously proposed systems, because the differences in the relevance of the inputs might be represented more clearly in the experiments, yielding better outcomes [46], [47].
Triangular M f was used to represent low, medium, high, and adequate fuzzy sets. Meanwhile, trapezoid M f was used to represent near and distant fuzzy sets.Trapezoidal and triangular membership functions are suitable for real-time operations and their computations are not complex [48].
Equations (11), (12), and (13) are used to obtain the optimal values for our parameters: Max_distance_to_cluster s_center Figs. 3, 4, and 5 show the graphical representation and associated linguistic states for the input established M f : energy level, distance to cluster center, and distance to BS. Expert-defined (3 3 = 27) fuzzy rules are used to describe the interaction between variables in the fuzzy rule base [19], [49] for PCH selection based on the output chance value, as presented in Table 2 and are then examined using the Mamdani model. These rules are true for high-energy nodes, close distance-to-cluster's center, and close distance-to-BS. Fig.6 shows the graphical representation and associated linguistic state for an expert-defined fuzzy output function M f (chance value) for PCH selection.
Furthermore, the final crisp number, which is a chance value, was obtained using the centroid defuzzication      [19], [49]. each cluster were compared, and PCH is chosen based on the node with the greatest chance value. PCH is chosen from the higher-energy node when two or more nodes have the same maximum chance value. It receives data from SCH and sends it to BS. The processes required for PCH selection are described in Algorithm 1.

Input: N nodes information and BS coordinates.
Output: PCH nodes in the network. Node-Information: • Node.type = ''N'' (Cluster Member) • Node.energy = current energy (All nodes start with initial energy) • Node.location = current node's coordinates 1) For each node in the same cluster a) Sends node's information to BS b) Calculates the chance value using FL 2) Chooses PCH with the highest chance value 3) Receives data from SCH 4) Transmits data to BS 5) End

C. SCH SELECTION USING FL
After creating N c clusters and selecting PCH, SCH will be chosen. It contributes to lower energy usage by gathering sensed data from CMs, aggregating it, and delivering the aggregated data to PCH. The election of SCH is decided using FL. In every round, each CM in our proposed technique runs FL to measure its probability of being SCH. Consider that selecting SCH necessitates the consideration of two-node attributes. As a result, two input variables were used for crisp input parameters evaluated for FL: Residual-energy: available energy level in each node. Distance-to-PCH: distance between CM and its PCH. The Euclidean distance is used to estimate the distance between CM and its major PCH, as shown in (4). As a SCH, if a node is close to PCH, it might use less energy for data transmission. Each input function (fuzzy variable) has three M f that show a different degree of function. Three levels were used for the lingual representation of the node's energy, as shown in Fig.7: low, medium, and high. Here, M f ranges from 0 to 0.5, as calculated form (11) [2].
The node's distance-to-PCH as shown in (Fig.8) has three levels for the lingual representation: near, adequate, and distant. Here, M f ranges from 0 to 140, as calculated form (14) [2].  Five membership functions were used because the difference in the relevance of the inputs might be represented more clearly in the experiments, yielding better outcomes [46], [47].
Triangular M f was used to represent low, medium, high, and adequate fuzzy sets. Meanwhile, trapezoid M f was used to represent near and distant fuzzy sets.
Equation (14) was used to determine the maximum values of our parameter distance to PCH.
Figs. 7 and 8 show the graphical representation and associated linguistic states of the established M f : energy level and distance to PCH. Fig.9 shows the graphical representation and associated linguistic state for an expert-defined fuzzy output function M f (chance value) for SCH selection.
Expert-defined (2 3 = 8) fuzzy rules are used to describe the interaction between variables in the fuzzy rule base [50] for SCH selection based on the output chance value, as presented in Table 3 and are then examined using the Mamdani model. These rules are true for high energy nodes located near PCH.
Furthermore, the final crisp number (a chance value) was obtained using the CoA defuzzication procedure. In every cluster, the chance values from all nodes were compared, and SCH was chosen with the most chance for the node. If two or more nodes are equal to the maximal chance value, SCH is the node with the highest energy. It gathers, combines, and  [17], [18] using the defined aggregation ratio E DA prior to relaying toward the PCH. The corresponding value of E DA is 5 nj/bit/ m 4 as used in [2], [41].

D. INTRACLUSTER DATA COMMUNICATION
After cluster formation with selecting PCH and SCH nodes, BS sends the message information. It comprises PCH's id, SCH's id, and the CM corresponds to a cluster. The CM selects a time-division multiple access (TDMA) slot to transmit data, and then goes to sleep. When SCH receives data, it aggregates the sensed data and forwards it to PCH. After that, PCH sends the data to the BS. Fig.10 illustrates the overall workflow of the proposed protocol.

E. TIME COMPLEXITY ANALYSIS
The iterative algorithms of hybrid PSO and K-means clustering algorithm, and FLS require time to provide the final output. Thus, an analysis of time complexity is performed. It represents the function O(). It is determined by system inputs, outputs, and the time-dependent processing variables used to perform the proposed protocol. Clusters are constructed at the start of the protocol using the hybrid PSO and K-means clustering algorithm. The time complexity of  this cluster formation process is estimated as O(n 2 ) as the pairwise distances between sensor nodes must be determined. Here, N is the total number of sensor nodes in the network. All nodes execute FLS to estimate a PCH chance as PCH selection criteria. The FLS has three inputs, each defined by three membership functions. Thus, 27 rules are derived to estimate a PCH chance. All nodes run FLS to estimate a SCH chance as SCH selection criteria. The FLS has two inputs, each defined by two membership functions. Thus, eight rules   [2], [20], [40]. are derived to estimate a SCH chance. The time complexity of this process is computed using the formula O(n × FL rules ). Table 4 summarizes the time complexity analysis.

V. SIMULATION RESULTS
The proposed protocol is based on an optimization technique and FL, both of which are easily implemented using MATLAB. The proposed technique's results are compared with conventional algorithms, such as FCM clustering and FLS-based CH selection to enhance the sustainability of WSNs for environmental monitoring applications (Rajput and Kum) [19], LEACH-Fuzzy Clustering (LEACH-FC) protocol [2], and LEACH based on the energy consumption equilibrium (Chen et al.) [20].
Our comparisons are split into three groups: alive nodes related to rounds, bits transmitted to BS related to rounds, and the remaining network energy related to rounds. Table 5 presents the simulation parameters used. In scenario 1, a total of 100 sensor nodes and BS are distributed in a monitoring area of 100 m ×100 m. In scenario 2, a total     Table 6 and Fig.11 compare the proposed protocol with Rajput and Kum, LEACH-FC, and Chen et al. The results proved that the proposed protocol outperforms others for the network lifetime. Fig.12 shows that the last node died in the proposed protocol at more than 10,000 rounds (92 dead nodes), in Rajput and Kum at 6851 rounds, in LEACH-FC at 2481 rounds,  and in Chen at al. at 1764 rounds. The results confirmed that the proposed protocol outperforms others by 46% and more. Fig.13 shows the stability of the network by comparing the average remaining energy in the network related to each round. Therefore, the proposed protocol consume less energy than other protocols, such as Rajput and Kum, LEACH-FC, and Chen et al. Fig.14 and Fig.15 show that 196 × 10 6 bits were transferred in the proposed protocol at 92% of the network lifespan. Meanwhile, 124 × 10 6 , 94 × 10 6 , and 71 × 10 6 bits were transferred to the BS in Rajput and Kum, LEACH-FC, and Chen et al.,respectively.
Note that the proposed protocol technique transmits more bits to BS than Rajput and kum, LEACH-FC, and Chen et al. VOLUME 10, 2022

B. SIMULATION RESULTS FOR SCENARIO 2
As Shown in Table 7 and Fig.16, the proposed protocol is compared with Rajput and Kum, LEACH-FC, and Chen et al. The results proved that the proposed protocol outperforms others for the network lifetime. Fig.17 shows that last node died in the proposed protocol at more than 10,000 rounds (970 dead nodes), in Rajput and Kum at more than 10,000 rounds (929 dead nodes), in LEACH-FC at 6766 rounds,and in Chen at al. at  2725 rounds. The results confirmed that the proposed protocol still outperforms other protocols. Fig.18 shows the stability of the network by comparing the average remaining energy in the network related to each round. Therefore, the proposed protocol consumes less energy than Rajput and Kum, LEACH-FC, and Chen et al.
Figs.19 and 20 show that 1 × 10 9 bits were transferred in the proposed protocol at 97% of the network lifespan. Meanwhile, in Rajput and Kum, 882 × 10 6 bits were transferred at 92% of the network lifespan to the BS. In LEACH-FC, 604 × 10 6 bits were transferred to the BS,and 294 × 10 6 bits were transferred in Chen et al.
Note that the proposed protocol technique transmits more bits to BS than Rajput and kum, LEACH-FC, and Chen et al.

VI. CONCLUSION
This paper proposes a fuzzy Logic (FL) low energy adaptive hierarchy (LEACH) technique-based particle swarm optimization (PSO). Clusters were generated using a probabilistic algorithm in LEACH, but they were made using the hybrid PSO and K-means clustering algorithm in our proposed technique. We used three parameters, namely, energy level, distance to cluster center, and distance to BS, to select a PCH using FL. Two parameters were used to select a SCH using FL: energy level and distance to PCH.
Both improvements were made to extend the network's existence and boost its throughput. The simulated results showed that the network lifetime was improved by more than 46% and packet transmission by 17.6%. Thus, there is an improvement for the proposed protocol technique compared to other protocols, such as Rajput and Kum, LEACH-FC, and Chen et al.
In future studies, real-time implementation could be conducted as a follow-up to this paper. Delay may be used as a performance metric, and the approach must be modified to work with delay-sensitive applications.