Modified LEACH in WSN to Reduce Energy Consumption


This MATLAB code improves the LEACH protocol for energy consumption minimization in WSN. We have used BAT optimization algorithm for this purpose. The new cluster head is elected with minimum intracluster distance, minimum energy consumption and the maximum number of nodes under its influence.

This repository contains :

  • MATLAB code for modified LEACH with BAT optimization
Download Code  Discuss Code


A wireless sensor network (WSN) is used to monitor physical or environmental conditions. It consists several numbers of sensor nodes that monitor the temperature, humidity, and light parameters. The received information is passed through the WSN to the base station. In WSN all the sensor nodes are powered by the battery which consumes high energy for the data transmission. This energy consumption can be reduced by using hierarchical approaches. We selected LEACH (Low-energy adaptive clustering hierarchy) scheme for the minimization of energy consumption.

Thesis Statement

LEACH[1] improves energy efficiency and increase the lifetime of the network. The clusters are formed in the LEACH scheme in which distributed sensor nodes are placed in a group. The sensor node which has maximum residual energy selected as the cluster head (CH). All the cluster nodes transmit data to CH, and then CH is forwarding through the other CHs or directly to the base station.The cluster head selection procedure is not optimal in the LEACH scheme. So we proposed BAT optimization algorithm for the optimal selection of CH in LEACH protocol.


LEACH is a MAC protocol which implemented with clustering and simple routing protocol in WSN. The key function of LEACH is to minimize the energy consumption necessary to form clusters to increase lifetime of WSN. Most of the sensor nodes transmit to the cluster head in LEACH protocol. The cluster head compresses the received sensor nodes data and forwarded to the sink node (Base Station). The remaining nodes of the clusters communicate with the cluster head in TDMA (Time Division Multiplexing Access) manner as per CH generated scheduled [1].

The working of LEACH is divided into two phases. The first phase is the setup phase in which clusters are formed in WSN. The second phase is known as steady phase in which information or data is transferred to sink. The cluster head selection phase and clustering phase are the key parts of the LEACH protocol. Each sensor node is having threshold energy as per the formulation

In equation 1, p is cluster head percentage in all nodes, r is the round and G is set of non selected cluster head nodes.

The energy model is followed by LEACH protocol with the two-channel model; free space (d2) for single hope path and multipath fading (d4) for the multihop path. So the energy consumption of l bit packets over distance d is estimated as

Where efs = free space energy loss, emp = multipath fading loss, d= distance between source and destination node, d0= crossover distance =square root of (efs/emp). The energy variable depends on the node distance, so via optimizing node distance, we can minimize the energy consumption at every sensor node in WSN.

BAT optimized LEACH

An objective function is necessary for the optimization algorithm. It must satisfy the condition and constraints of the design network. As per equation 2 the energy depends on the distance of sensor nodes, so objective function shows the relationship between energy and distance variable. Equation 3 shows the fitness function of the LEACH protocol

Here a1 and a2 are the tradeoff factors, and their fixed value is considered as 0.4. The objective function shows the energy consumption with respect to the node distance.

We proposed a BAT optimization algorithm to minimize the LEACH protocol objective function as written in equation 3. The BAT is a Metaheuristic optimization algorithm developed in 2010. It is inspired by the echolocation nature of microbats with increasing pluses rate of emission and loudness.

The testing of the BAT optimization algorithm for different benchmark function MATLAB code is available at

All BATS are used echolocation to measure distance and also know the difference between food and background barriers. Bat flies randomly having velocity at fixed position, with fixed frequency and increasing wavelength and loudness to search for food. The wavelength of bats emitted pluses is adjusted automatically and adjusts the rate of pulse emission. The loudness of bats varied from higher range to constant minimum range. The main task of optimization is to allocate cluster headsin each cluster. The node which consumed less energy in data transmission and reception is selected as the cluster head.

The objective function written in equation 3 is minimized by the BAT algorithm. The position of Bats allocates the position of cluster head in each cluster. The position of Bats has updated the position of cluster heads are also changed.

Figure 1 Architecture of BAT optimized LEACH module


A geographical area of 100*100 is developed in the MATLAB 2018a. The sensor nodes are randomly placed in that area. The implementation steps are described below

  1. Initialize the parameters of LEACH protocol like Initial Energy, Number of Nodes, rounds in LEACH, energy for transferring/receiving of each bit, transmit amplifier free space/multipath energy, aggregation energy, and the packet length. Using these network parameters a network with randomly placed nodes is created as shown in figure 2
  2. Placed the nodes into the developed geographical area.
  3. Consider 5% of the total nodes as the clusters. So, among 100 nodes 5 cluster are formed using LEACH protocol.
  4. Initialize the random position of Bats in the BAT algorithm.
  5. The limits of searching space are equal to the number of the cluster formed. The 5 clusters heads are elected among the 100 nodes.
  6. Initialize the distance and loudness parameters of the BAT algorithm.
  7. Calculate the objective function value for each bat in each iteration and saved the output.
  8. Update the best position of bats as per the BAT algorithm and estimate the best fitness value of objective function in next iteration.
  9. If the fitness value is lower than the previously estimated fitness value, than this value is considered as the best value.
  10. All the process is repeated until the final iteration finished. We obtained the minimum value of the objective function in terms of energy and distance.

Figure 2 WSN network generated for 100 nodes placed randomly


In this dissertation, we proposed a BAT optimized LEACH protocol for the selection of cluster head in WSN. This method is used to minimize energy consumption in transmitting/ receiving node data. The BAT algorithm has optimized the distance among the cluster nodes. The minimum node distance provides lower energy consumption. The proposed algorithm is provided with better outcomes than the existing approach. So the efficient LEACH protocol is achieved by BAT algorithm optimization. The residual energy is reduced in LEACH protocol via the optimal selection of cluster head



  1. Jiang, Shuyu. “LEACH Protocol Analysis and Optimization of Wireless Sensor Networks Based on PSO and AC.” In 2018 10th International Conference on Intelligent Human-Machine Systems and Cybernetics (IHMSC), vol. 2, pp. 246-250. IEEE, 2018.
  2. Beiranvand, Zahra, Ahmad Patooghy, and Mahdi Fazeli. “I-LEACH: An efficient routing algorithm to improve performance & to reduce energy consumption in Wireless Sensor Networks.” In The 5th Conference on Information and Knowledge Technology, pp. 13-18. IEEE, 2013.
  3. Mann, Palvinder Singh, and Satvir Singh. “Improved artificial bee colony metaheuristic for energy-efficient clustering in wireless sensor networks.” Artificial Intelligence Review51, no. 3 (2019): 329-354.
  4. Chawla, Mridul, and ManojDuhan. “Bat algorithm: a survey of the state-of-the-art.” Applied Artificial Intelligence29, no. 6 (2015): 617-634.

admin is an innovative and first of its kind platform created by Vidhilekha Soft Solutions Pvt Ltd, a Startup recognized by the Department For Promotion Of Industry And Internal Trade, Ministry of Commerce and Industry, Government of India recognised innovative research startup.


There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.