1 Introduction

Wireless sensor network (WSN) is considered as one of the most important technologies of twenty-first century [1]. The distinction between traditional wireless telecommunication networks such as cellular systems, mobile ad hoc networks (MANET), and WSNs is that WSNs have special characteristics such as node density, lack of reliability on sensor nodes; and severe restrictions on energy, computing, and memory resources [2]. These characteristics have attracted major attention within both academic literature and industrial institutions around the World. WSNs usually consist of a large number of low-cost and multi-purpose sensor nodes with low power that are deployed in a given network.

Although these sensor nodes are small, they are equipped with embedded microprocessors and radio transceivers. Therefore, they not only have sensing capability, but also can process data during communication. These sensor nodes communicate over short distances through a wireless media in order to perform common tasks such as environmental monitoring, war-zone monitoring, and industrial process controlling. Although sensor networks have different applications in different areas, their overall structures are the same and have some technical similarities. There are various topologies for transferring data form a node to base station (BS). They can be divided into two categories: cluster-based (CB) topologies and tree-based topologies [3].

WSNs are comprised of a large number of sensor nodes equipped with limited resources. Energy efficiency is one of the most important issues in this domain [4]. Therefore, forming efficient clusters is a key factor. Each working range in CB sensor network is called a round. In each round, cluster head (CH) selection, cluster formation, and data transmission are performed. Network lifetime is defined as the number of rounds in which all sensor nodes have energy [5].

In this paper, we focus on cluster formation using fuzzy logic by considering three parameters: the amount of energy in CH, the distance from CH to BS, and the number of connections in CH. In cluster formation process, each node is assigned to a CH having higher chance according to the three mentioned parameters and fuzzy inference system (FIS) [6].

The remaining of the paper is organized as follow: In Sect. 2, related works are reviewed. In Sect. 3, the proposed algorithm for creating optimal clusters of sensors for optimum energy consumption is presented. Experimental results and comparisons are described in Sect. 4 and finally, conclusions are provided in Sect. 5.

2 Literature review

In recent years, many works have done on clustering in WSNs. In this section we summarize some of them.

Tabatabaei et al. [7] proposed a new fuzzy-based routing protocol for MANET. The aim of this protocol was to improve system performance and fuzzy logic system is used in order to select a stable route. Three parameters including power of battery, speed of mobile nodes, and bandwidth are mentioned in route selection.

Since the energy consumption in WSNs is one of the most important issues for improving network lifetime, a neuro-fuzzy energy-aware clustering protocol named neuro-fuzzy energy-aware clustering scheme (NFEACS) is developed in [8].

This protocol creates energy aware clusters in two phases. The first phase is fuzzy logic in which energy-efficient clusters are made and the second phase is neural network system in which an effective training set is provided.

Esmaeeli et al. [9] used game theory and fuzzy logic (GTFL) to perform clustering in WSNs and proposed a centralized energy-based clustering protocol. The purpose of this method is to overcome energy resource limitations in WSNs.

Low-energy adaptive clustering hierarchy (LEACH) protocol is one of the well-known clustering protocols in which CH aggregates data and routs them in order to decrease the amount of communication and prolong the network lifetime. Abood et al. [10] proposed a new energy-efficient clustering method called “Fuzzy Logic Cluster Leach Protocol” (FUZZY-LEACH) to improve LEACH protocol. This protocol uses FIS in order to crate clusters.

A predefined value P (percentage of desirability of CH in network) is set before starting the algorithm. LEACH has two phases: a setup phase and a deployment phase. In the setup phase, each node decides whether or not to become a CH. Each node can select a random number between 0 and 1 that shows the probability of each node to be CH. If the probability P is less than threshold T(n), the node become CH in the current round r. T(n) is calculated as following:

$$\begin{aligned} T(n)=\left\{ {{\begin{array}{lll} \frac{P}{1-P\left( {\mathrm{r }\, \mathrm{mod}\frac{1}{p}} \right) }&{}\quad \mathrm{if} \,\, n \, \epsilon \,G \\ 0 &{}\quad \mathrm{otherwise} \\ \end{array} }} \right. \end{aligned}$$
(1)

G is the set of sensor nodes which are not CH in the last \(\frac{1}{p}\) rounds. Therefore, in the initial round (round 0), all nodes have the same probability P for becoming CH.

Current clustering methods select CH having more residual energy, but the problem arises when CHs forward their data to the BS, the CH closer to the BS become heavy with traffic and will die earlier. To overcome this problem, Wankhade and Choudhari developed a new protocol named novel energy-efficient unequal clustering routing (NEEUC) protocol in which the CHs closer to BS have smaller sizes than other CHs; therefore, they have enough energy for forwarding inter-cluster data [11].

In [12] the cluster formation is investigated and a new approach is proposed for cluster formation. This approach is based on FIS and named fuzzy logic cluster formation protocol (FLCFP). Authors demonstrated that use of multiple parameters in cluster formation reduces energy consumption.

It is shown that network lifetime increases through FLCFP approach. In addition, it has been shown that the energy of the sensor node is uniformly consumed in this approach. The main difference between FLCFP and LEACH during the setup phase is the formation of the cluster. Cluster formation phase in FLCFP and LEACH are different. Non-CH nodes compute the chance to become CH by using FIS. FIS design has three descriptors: energy level of CH, the distance between CH and BS, and the distance between the CH and node. After this step, the node is added to a CH having the highest chance. In LEACH, each non-CH node receives a “Attached Cluster” message from all CHs and provides responses to messages which are the strongest signals [12].

In clustering process, after assigning objects to clusters, it is necessary that users provide manually descriptions for clusters, but this process is time consuming and in most cases users cannot explain the results and this leads to inappropriate descriptions. For this, Huang et al. [13] proposed a clustering algorithm called fuzzy tree-based clustering approach in order to discover conjecturable rules and provide descriptions for clusters based on decision tree classification technique.

In WSNs, sensor nodes closer to the BS tend to die earlier. Therefore, a fuzzy energy-aware unequal clustering algorithm (EAUCF) is proposed in order to solve this problem in WSNs [14]. This algorithm uses fuzzy logic to handle uncertainties in CH radius estimation. The aim of this protocol is to reduce the intra-cluster work of the CH either closer to the BS or that has low remaining battery power.

Some factors have severe influences on networks. These factors include routing issues, severe resource limitations such as efficient energy utilization, lifetime of the network, and environmental conditions. Among all routing protocols in WSNs, clustering algorithms are more dominant for increasing network life time.

Singh et al. [24] investigated various LEACH routing protocols and classified all of them into two parts: single hop and multi-hop communications based on data transmission from the CH to the BS. They also analyzed these protocols using some parameters such as energy efficiency, overhead, scalability, complexity. On the other hand, Pantazis et al. [25] have worked on energy-efficient routing protocols and classified them into four types: network structure, communication model, topology based, and reliable routing. Each of these types can be further classified. The first category includes flat or hierarchical routing protocols. The second category includes query-based or coherent and non-coherent based or negotiation-based routing protocols. The third category includes location-based or mobile agent-based routing protocols. Finally, the fourth category includes QoS-based or multipath-based routing protocols.

In [26], the use of directed diffusion paradigm for a simple remote-surveillance sensor network is evaluated analytically and experimentally. All nodes in a directed-diffusion-based network are aware of their around and paths and select the best path. Results indicated the significant effect of directed diffusion on energy saving.

Younis and Fahmy [27] proposed a distributed clustering approach namely hybrid energy-efficient distributed clustering (HEED) for long-lived ad-hoc sensor networks without assumptions of the presence of infrastructure or the node capabilities which selects CH according to node residual energy of the second parameter for example the energy of the number of neighbors of each node.

Ye et al. [28] introduced an energy-efficient clustering scheme (EECS) for single-hop WSNs which selects CH according to more residual energy in an autonomous manner through local radio communication with no iteration and achieves good distribution on CH.

Hong et al. [29] proposed a threshold-based CH replacement scheme for clustering protocols of WSNs named T-LEACH that minimizes the number of CH selections by defining threshold for residual energy. The aims of this protocol were reducing the amount of head selection and replacement cost, and increasing the lifetime of the entire network.

In [30], several energy-efficient hierarchal routing protocols derived from conventional LEACH routing protocol are investigated and some obstacles faced by LEACH are addressed. Authors showed that these issues can be solved by the generalized versions of LEACH.

Anam and Yadav [31] proposed a new modified enhanced LEACH Algorithm in which threshold is calculated for next round by considering the total energy of nodes. The aim was increasing network lifetime.

Handy et al. [32] proposed an extension of LEACH for reducing the power consumption of wireless microsensor networks. Authors have changed the LEACH’s stochastic CH Selection method by using a deterministic component and also defined the lifetime of microsensor networks based on three metrics named first node dies (FND), half of the nodes alive (HNA), and last node dies (LND).

In [33], the use of solar power in WSNs is proposed in order to create solar-aware LEACH which can increase the lifetime of sensor networks significantly.

Kumar et al. [34] presented the taxonomy of energy-efficient clustering algorithms in WSNs and timeline and description of LEACH and its descendant in WSNs and finally compared them.

In another study, Mittal et al. [35] presented a new protocol named LEACH-sub-CH that divides the network into clusters; the cluster contains CH, sub-CH (the node that will become a CH of the cluster in case of CH dies), and cluster nodes. This protocol can reduce the number of created messages and increase the remaining network energy.

Liu and Ravishankar [36] proposed a GA-based adaptive clustering protocol with an optimal probability prediction named LEACH-G in order to reduce energy consumption and as a result increase the lifetime of WSNs. The proposed protocol includes two phases: setup phase and steady-state phase for each round. It also has an additional preparation phase before the beginning of the first round.

Abdulsalam and Ali [37] presented a new data aggregation algorithm that can run in different networks such as uniform, non-uniform, and evolving networks while maintaining data accuracy. The algorithm records the corresponding data about the whole event duration so that can handle sudden bursts in the underlying data. Authors claimed that their algorithm could extend the lifetime of the network, maintain the original distribution of the sensors as long as possible, maintain the accuracy of the sensed data, and also detect and handle sudden bursts of data.

In [38], an energy-efficient CB routing protocol is proposed for WSNs in order to improve network lifetime and reducing energy consumption.

Eletreby et al. [39] proposed a fast, decentralized, spectrum-aware, and energy-efficient clustering protocol called cognitive LEACH (CogLEACH) in order to cluster cognitive radio sensor nodes in a dynamic frequency environment set by the primary users. The proposed protocol is a spectrum-aware extension of the low-energy adaptive clustering hierarchy (LEACH) protocol that can improve the throughput and lifetime of the network.

In [40], authors improved the LEACH protocol for using in energy harvesting WSNs. This protocol selects CH according to the estimation of nodes harvested energy and consumed energy.

In [41], an energy-efficient approach for data transmission in WSNs is proposed by taking into account routing, multiple access control (MAC), physical, energy, and propagation issues. In this approach, information routing is performed based on a self-organized clustered structure and a carrier-sensing multiple access (CSMA) protocol is chosen at MAC layer. The purpose of this protocol was increase network lifetime and decrease packet loss rate.

In [42] another modification to LEACH protocol named two-level hierarchy for low-energy adaptive clustering hierarchy (TL-LEACH) is proposed for sensor networks by focusing on energy consumption. This protocol is a two-level hierarchy one in which a firmly distributes the energy load among the sensors and enables scalability and robustness.

Xiangning and Yulin [43] proposed two modifications on LEACH protocol, named energy-LEACH which improves head selection process by choosing nodes having more residual energy and multi-hop-LEACH which uses multi-hop communication between CH and sink.

Kumar et al. [44] improved LEACH-Mobile protocol based on a mobility criterion “remoteness” for CH selection that ensures high success rate in data transfer between CH and collector nodes while nodes are moving. Authors claimed that information inclusion of neighboring node can improve the routing protocol.

Farooq et al. [45] presented an energy-efficient routing protocol for WSNs named multi-hop routing with low-energy adaptive clustering hierarchy (MR-LEACH) in order to increase the lifetime of the network that partitions the network into different layers of clusters. CH in each layer communicates with adjacent layers in order to transmit data to the BS. Thus, it can be stated that MR-LEACH follows a multi-hop routing from CH to the BS and this leads to energy conservation.

Cell low-energy adaptive clustering hierarchy (Cell-LEACH) is another modification on LEACH protocol [46] in which every cluster is divided into seven subsections called cell and each cell has a cell-head communicating with CH directly and aggregate their cell information in order to prevent sensors communication.

Saminathan and Karthik [47] presented data aggregation-based optimal-LEACH (DAO-LEACH) protocol as an energy-efficient routing in WSNs having effective data ensemble and optimal clustering. In this protocol, energy-efficient route is obtained by combining the nodes having maximum residual energy.

Zhang et al. [48] proposed a clustering routing protocol for balancing energy in WSNs based on simulated annealing (SA) and genetic algorithm (GA). Firstly, sensor nodes are clustered by SA and GA, and then the cluster center of each cluster is calculated. In this protocol, CH is selected according to higher residual energy and the distance from the cluster center of the desired cluster.

In [49], the related works for sink tracking in WSNs are investigated and P-LEACH protocol is proposed as a CB prediction technique for WSNs with mobile sinks.

In [50], an energy-efficient routing protocol for WSNs based on the effective data ensemble and optimal clustering namely energy-efficient LEACH (EE-LEACH) protocol for data gathering is proposed which selects the highest residual energy nodes for sending data to BS. The better packet delivery ratio, lesser end-to-end delay and energy consumption are advantages of this protocol than its predecessors, and it can improve the network lifetime.

Khoshkangini et al. [51] focused on reduction of energy consumption and increasing network lifetime using a fuzzy logic approach and two parameters, namely energy level and centrality. This technique uses a controller that prevents unwanted concentration of CH in a particular region.

Geetha et al. [15] investigated the need for clustering in order to overcome several limitations of WSNs and compared two clustering protocols namely LEACH (distributed) and LEACH-C (centralized) in terms of latency and lifetime. Finally, they concluded that if localized coordination is more important, then LEACH is preferred; otherwise, LEACH-C is preferred (if having centralized and deterministic approach is mentioned in order to increase network lifetime and having desired number of clusters).

Existing systems for traffic information gathering have high cost and low scalability because of their characteristics such as size, power supply, and wired communication. In order to achieve low cost and high scalability, the use of traffic information of shopping systems based on WSNs has been proposed. Although WSN-based systems are important, there are some problems such as low computing power, limited battery capacity, and high latency in these systems [18].

The automotive industry is rapidly progressing because of WSNs applications. In automotive industrial, WSNs are used in order to control vehicle theft, vehicle pollution control, and control the intensity of the lights. Battery is the main source of sensor nodes which is included in smart nodes, low-power devices equipped with one or more sensors, processors, memory, power supply, radio, and actuators. Various mechanical, thermal, biological, chemical, optical, and magnetic sensors can be connected to the sensor nodes in order to measure the environmental properties. Since sensor nodes have limited memory and typically placed in difficult access environments, there is a radio for wireless communication in order to transfer data to a BS [19].

In the case of vehicle theft control using WSNs, we can prevent vehicle theft and also reduce the weakness of the existing system used to control vehicle theft. Vehicle pollution can be controlled via WSNs by automating the existing pollution control systems. On the other hand, the incidence of temporary blindness can be reduced by controlling the intensity of the headlight using the WSNs [19]. The challenges of WSNs in optimization are globally debated and concerned. In general, increasing lifetime is still faced with many challenges of WSNs. Clustering and routing protocols are presented as optimization solutions for increasing the lifetime of WSNs. In this study, a meta-heuristic approach based on a robust computing algorithm is considered as an optimization method for increasing the life of WSNs. The proposed method implements the meta-heuristic bat optimization algorithm in the existing population. This approach optimizes the network as a nonlinear problem and implements it in four WSNs. The proposed approach is compared with LEACH hierarchical clustering approach and routing protocol [20, 21].

There are some studies on WSNs lifetime such as particle swarm optimization (PSO)-based population optimization problems and inspired of nature or emulate from life that are new ways for global optimization.

Meta-heuristic methods such as GA, ant colony optimization (ACO), bat swarm optimization (BSO), and Bat are the most suitable algorithms for energy-aware clustering techniques in WSNs. In these methods, CHs are chosen based on the maximum residual energy. Moreover, finding the shortest path to the best BS dramatically increases the lifetime of WSNs [20].

The equivalence of a number of nodes and the selection of a suitable cluster is the primary aim of minimizing energy in PSO technique. But the main purpose of this technique is to reduce the latency of traffic transportation. To achieve better performance, dynamic clustering is used which increases the energy efficiency of nodes and monitors the power of network resources [21].

Siew et al. [16] presented some factors which affect the network lifetime and provided fuzzy logic-based CH selection in BS. Based on this approach, the BS considers two selection criteria from sensor nodes: (1) energy level (2) distance to the BS to select the suitable CH with the aim of increasing the first node die (FND) time, data stream guaranteed for every round and improves the throughput of BS before FND.

3 The proposed method

In this section, we present details of protocol design and structure of clusters. Proposed protocol is based on fuzzy logic and helps different nodes to calculate the chance of becoming CH and then select proper CB on the three mentioned parameters. Our main objective is to increase the lifetime of WSNs using FIS. This formulation process system provides mapping of some input to output by using fuzzy logic. In this paper, the structure of fuzzy clustering is divided into two parts including preparation and deployment. The main difference between our proposed method and other algorithms such as LEACH is preparation phase and especially the phase of creating cluster. As mentioned before, in the LEACH algorithm, each non-CH node receives a message of joining to cluster from all CH and then it responses to the massage which has the highest signal strength. In our proposed algorithm, creating a cluster is different from that in LEACH. In all non-CH nodes, the chance of each node to be CH is calculated by using a fuzzy inference system. In this system, three parameters: (1) the amount of energy, (2) the distance between the CH and BS and (3) connections of CH are considered in order to calculate this chance . Then, the cluster is joined the CH which has the highest chance. The pseudo-code of the proposed protocol is shown in Algorithm 1.

figure a

Algorithm 1 shows the pseudo-code of clustering in the proposed method.

Selection of clusters and creating CH operations are performed in each round. Operations related to CH selection are conducted up to the line 11. At the first, all nodes are the same and there are no CH and subcluster. Each node generates a random number between zero and one and if this number is smaller than T, then the related node is selected as CH and its state changes to “CH” state and distributes a message to announce that became CH. Operation related to creating cluster is presented in lines 12–27. The remaining nodes receive all messages of announcing became CH. Also, the chance of each CH is calculated and then, the identification number of the CH changes to the highest chance and its state changes to the connected one. Finally, in lines 28–34, non-CH nodes send a connection message to the selected CH to join the cluster.

3.1 Cluster head chance calculation

In fuzzy approach, the chance of becoming CH is calculated in four steps:

  • Fuzzification: at first, the parameters of CH are sent to inference system. Then the membership functions are obtained based on parameters and predetermined membership functions.

  • Role assessment: after fuzzification and obtaining membership values, the obtained values enter to if-then tables to produce fuzzy output set. We use AND operator to calculate the chances. So the minimum value of the parameters will be chance.

  • Aggregation: after completing fuzzification and assessment steps, accumulation step starts. At this step, the union of all chances obtained from if-then table is calculated. In fact, here we use OR operator and the maximum chance of if-then table is chosen.

  • Defuzzification: the last step is returning to the fuzzy state in which the value of chance is obtained. As already mentioned, we use centroid defuzzification method to calculate the final value according to Eq. (2):

$$\begin{aligned} \hbox {COA}=\int \mu _{A} \left( {x}\right) \times {x\mathrm{d}x}\,/\int \mu _{A} \left( {x} \right) \,\mathrm{d}x \end{aligned}$$
(2)

3.2 Designing fuzzy inference system (FIS)

FIS is a set of fuzzy rules (IF–THENs), a database containing membership functions of linguistic variables and a fuzzy reasoning. In addition, FIS is a very influential method designed to construct complex and nonlinear relationships between inputs and outputs. Three types of FIS: Sugeno, Mamdani and Tsukamoto have been used in many different applications [22]. The difference between these three types of FIS is in gathering process and destructibility. We chose Mamdani FIS because it is well known and widely used approach among mentioned three FISs. Mamdani FIS is popular because it is intuitive characteristic. FIS implementation has four stages: fuzzification, rule assessment, total production(s), and ultimately defuzzification.

This method allows us to explain in a simple mathematical way, how our system works. Figure 1 shows the inference techniques and design of a FIS. Some comparisons are made between the Mamdani and Sugeno.

The Sugeno Algorithm is commonly used in control systems and systems that require mathematical calculations, but in Mamdani Algorithm, logical results are expressed in a relatively simple structure, and it is commonly used in decision support systems and systems that can interpret rules. The output of Mamadan Algorithm is nonlinear and fuzzy but the output of Sugeno Algorithm is linear. Mamdani’s Algorithm does not work well in situations in which output accuracy and flexibility are important. But Toggio Sugeno’s inference engine is more flexible and more accurate. Sugeno Inference Algorithm is used for designing sensitive and control systems due to its high accuracy and flexibility, but Mamdani system is more likely to be used in human systems due to its interpretative property and fuzzy output of rules [23].

The fuzzy logic has four parts including the fuzzification, knowledge base, inference engine, and defuzzification. In this paper, we presented our proposed model based on Mamdani model that is the best known and most widely used method in fuzzy logic [6]. It is notable that Mamdani method is available as a toolbox in MATLAB modeling software. This method allows us to simply explain our system and avoid computational complexity. The presented fuzzy systems are presented in Fig. 1.

Fig. 1
figure 1

FIS system [17]

3.3 Rules and proposed FIS parameters

In the presented model, we use three parameters as input of system: the number of CH connections, CH energy and the distance between CH and BS. The reason for selecting the above parameters is their importance in increasing the lifetime of the network. In order to discover the influence of the mentioned parameters on lifetime of the network as well as to have more flexible parameters, we divided each of the language variables into three classes: the amount of energy of CH, the distance between CH and the BS and the number of connections between CH (low, medium and high). In addition, many membership functions can be found within the toolbox of MATLAB fuzzy logic such as triangular and trapezoidal membership function, and Gaussian, bell and ring distribution. In particular, triangle and trapezoid membership functions are widely used due to their degrees. Accordingly, in this paper, these functions are used in order to present the considered parameters. In the mentioned linguistic forms, the language variables of the mid-level were presented by a triangular membership function while for presenting the two other levels, the trapezoid membership functions were used. In order to provide flexibility on the proposed system, linguistic variables of chances are divided into nine categories: very weak, weak, little weak, less than average, average, larger than average, less than powerful, powerful, and very powerful.

In the worst case, if the energy of CH is low, then the distance among the BS–CH and the number of connections of CH is high, and subsequently, the chance is very low.

At best case, if energy of CH is high, the distance among BS–CH and number of CH connection are low and then the chance is very high. Each of the above rules has a weight between zero and one. In general, the weight is equal to one and has no effect on fuzzy process. Sometimes the weight of a law may influence other laws and changes the weights to the amount that is not equal to one.

It is noteworthy that triangular and trapezoidal membership functions are more practical due to their degrees. In the following, the equations of triangular and trapezoidal membership functions are presented:

Triangular membership function:

$$\begin{aligned} \mu _A \left( x \right) =\left\{ {{\begin{array}{ll} 0, &{}\quad x\le a \\ \frac{x-a}{b-a},&{} \quad a\,\le x\le b \\ \frac{c-x}{c-b},&{}\quad b\,\le x\le c \\ 0,&{}\quad c\le x \\ \end{array} }} \right. \end{aligned}$$
(3)

The following equation also can be used for triangular membership function:

$$\begin{aligned} \mu _A \left( x \right) =\mathrm{max}\left( \mathrm{min}\left( \frac{x-a}{b-a},\frac{c-x}{c-b} \right) ,0 \right) \end{aligned}$$
(4)

in which a and c are the height of triangle and b is its base.

Trapezoidal membership function:

$$\begin{aligned} \mu _A \left( x \right) =\left\{ {{\begin{array}{ll} 0,&{}\quad x\le a \\ \frac{x-a}{b-a},&{}\quad a\,\le x\,\le b\, \\ 1,&{}\quad \,b\,\le x\,\le c \\ \frac{d-x}{d-c},&{}\quad c\,\le x\,\le d \\ 0,&{}\quad d\le x \\ \end{array} }} \right. \end{aligned}$$
(5)

The following equations also can be used for trapezoidal membership function:

$$\begin{aligned} \mu _A \left( x \right) =\hbox {max}\left( {\mathrm{min}\left( {\frac{x-a}{b-a},1,\frac{d-x}{d-c}} \right) ,0} \right) \end{aligned}$$
(6)

in which a and d are the legs of trapezoidal; b and c are its side.

Figures 2, 3 and 4 show the mid-level linguistic variables of triangular membership function, while trapezoidal membership function is used for two other levels. For the flexibility of the proposed system, we have divided the linguistic variables of chances into 9 categories: too weak, weak, little weak, less than average, more than average, less than strong, strong and very strong. The same as parameters, the membership functions of chances are triangular membership function at mid-level and for the side levels, trapezoidal membership function is used (Tables 1, 2).

Fig. 2
figure 2

Fuzzy sets of the amount of energy

Fig. 3
figure 3

Fuzzy set of the distance from CH to BS

Fig. 4
figure 4

Fuzzy sets of the number of connections of CH

Figure 5 shows that, in the membership functions, middle is indicated by triangle membership function and trapezoid membership function is used to compute side levels. Since three parameters are used and each parameter has three levels, there are 27 possible values for a chance.

Table 1 Fuzzy IF–THEN rules
Table 2 Simulation parameters
Fig. 5
figure 5

Fuzzy set of the values of chances

In the worst case, if energy of CH is low, the distance among the BS–CH and number of connections of CH are high and then the chance is very low.

At best case, if energy of CH is high, the distance among BS–CH and the number of CH connections is low and then the chance is very high. Each of the above rules has weight between zero and one. In general, the weight is equal to one and has no effect on fuzzy process. Sometimes, the weight of a law may influence other laws and changes the weight to an amount that is not equal to one.

For example, in this paper we have three parameters: energy, distance to BS, and the number of connections. If energy is high, the distance is short and the number of connections is low and then chance increases. Parameters and weighs have influence on each other.

4 Experimental result

In this section, the simulation result of the proposed algorithm and the comparison with other algorithms are discussed. Proposed algorithm is simulated in MATLAB software and compared with LEACH [5], FLCFP [17]. Results indicate that the proposed algorithm could compete with other algorithms. The results are shown in the following.

Table 3 FND comparison of the first simulation

A network includes 100 sensors with initial energy of 0.5 J is distributed in a \(100 \times 100 \hbox { m}^{2}\) environment. In order to obtain more accurate results, the proposed algorithm has been repeated ten times for each scenario. In each round of running algorithm, energy of each node ends after sending 4000 bits of data to CH. In addition, CH sends data toward BS which is located at a distance of 50–200 m of the network.

  • Hypothesis:

Proposed system model uses the following defaults:

  1. 1.

    All nodes in WSNs have the same hardware, communications and computational capabilities.

  2. 2.

    Nodes are randomly placed in a two-dimensional space using a uniform distribution.

  3. 3.

    All nodes have the same initial energy.

  4. 4.

    BS is outside the WSNs.

  5. 5.

    Node positions’ are unknown, meaning they are not equipped with any global positioning system (GPS).

4.1 Simulation 1

In order to achieve better results, we considered FND criteria for the comparison of the algorithms. FND is a standard criterion of sensor in evaluating the modeling results of WSNs that means the death of the first node. Table 3 shows FND results of algorithms. Note that in order to achieve better evaluation, results of ten runs have been captured. The results show that the mean value of FND for LEACH has been 561.7 rounds, it is 612 for Fuzzy Logic Cluster Formation Protocol (FLCFP), and this amount is equal to 628 for the proposed algorithm. Figure 6 shows the FND values of simulation 1.

The mean values of FND results of simulation 1 are presented in Table 4. Note that these values are presented in order to understand the mathematical difference between the proposed algorithm, FLCFP algorithm, and LEACH algorithm.

Fig. 6
figure 6

FND values of the first simulation

According to the values presented in Table 4 and Fig. 6, we conclude that the proposed method causes 11% delay on FND time in comparison with LEACH algorithm and 2% improvement in comparison with FLCFP algorithm, which is a good improvement in the lifetime of the network. The reason for this improvement is that LEACH protocol uses the distance from nodes to cluster, while in the proposed method, we use three important parameters (the amount of energy in CH, the distance between CH and BS, and the number of CH connections). Notably, in the LEACH algorithm if a node receives several massages from the CH, then the nearest CH will be selected, while the proposed algorithm considers different parameters and it calculates the chances of CH according to them. In order to understand the energy consumption of sensor nodes we investigated the remaining energy level of nodes. The nodes in the proposed method consume energy more uniformly. In the other words, in the LEACH algorithm, some nodes have still a lot of energy and some others have been died, while in the proposed algorithm, all nodes have a certain level of energy.

In the fuzzy algorithm, unlike the LEACH algorithm, the amount of energy is calculated in order to select a node that has higher chance.

4.2 Simulation II

In this simulation, all parameters are similar to the previous simulation. However, we reduced the probability of CH to 0.05 and doubled the number of nodes (i.e., 200).

The purpose of this simulation is to study the effect of density and the number of CH on wireless sensor network in the proposed method. As the previous simulation, an FND criterion is considered in order to compare the algorithms. Table 5 shows FND results for the algorithms. Note that each algorithm is executed ten times in order to achieve better results.

Results show that the LEACH mean value for FND is 589, it is 634 for FLCFP algorithm, and it is equal to 649 for the proposed algorithm.

Table 4 The mean of FND in the first simulation
Table 5 FND comparison of the second simulation

As explained, in the simulation 1, the mean values of FND in simulation 2 are presented in Table 6.

Table 6 The mean of FND in the second simulation

Table 5 and Fig. 7 show the achieved improvement on FND time.

Fig. 7
figure 7

Nodes’ energy consumption in the second simulation

5 Conclusion

In this paper, WSNs, their challenges, and applications as well as the concept of clustering are introduced. Also, some fuzzy algorithms networks are described for clustering in sensor networks, especially in terms of energy consumption. In WSNs, energy constraints play important roles in the design of networking, clustering algorithms, and generally the introduction of any protocol. In this paper, a new method is presented in order to create clusters in WSNs and then fuzzy logic is used to improve the energy consumption of network nodes. In the presented model, three parameters are used to create clusters including the amount of energy in CH, the distance between CH and BS, and the number of CH connections. These parameters are used due to their importance in the lifetime of the network. In order to examine and analyze the proposed method, simulations are carried out using MATLAB software. We compare the proposed algorithm with LEACH and FLCFP algorithms. Experimental results show 2\(\sim \)12% improvement in network lifetime compared with LEACH and FLCFP. Also, we indicated that energy consumption of nodes is uniformed by using the above parameters. This is achieved by examining the energy of remaining nodes.