## 5 Proposed Dynamic Cluster Head Election Algorithm
### Proposed Dynamic Re-Clustering and Self-Organization Method
#### 5.2.2 Dead Nodes and Re-Clustering Organization  
During the verification of the remaining energy of each node, after discovering a dead node the proposed algorithm deletes the dead node from the topology list and then notifies the Base Station. Therefore, the dead node will not be checked the next time, thus overcoming the false election problem (black holes), which wastes energy and time. After this deletion, the cluster is reconfigured and organized according to the new situation, which makes the cluster lighter and more energy-saving. The pseudo-code presented in Algorithm 2 shows how to delete the dead nodes from the topology list, and the processes of Base Station notification and re-clustering configuration. ```
END

**Algorithm 2** Deletes the Dead Sensors from the Cluster

#### 5.2.3 Multiple Cluster Organization

The previous operations were concerning a single cluster, whereas in the case of multiple clusters, the cluster is determined to elect the appropriate CH first, then move among the rest of the clusters to apply the same scenario. Moreover, data of all the clusters are sent to the sink node. The pseudo-code of Algorithm 3 presents how to move between the other Custers to elect the appropriate CH for each one. Figure 6: The proposed Dynamic Cluster Self-Organization Method’s data flow diagram. ```
Input:DevicePower,NUMBEROFCLUSTERS Output:Moving between the Clusters to detect the optimum CH for each FOR each Cluster i of the network DO IF (CHcount[i] == NUMBEROFCLUSTERS) THEN CH [i] = CALL f_AssignClusterHead (i, DevicePower) RETURNING elected CH prevCH[i] = CH[i] CHcount[i] = 0 ELSE CHcount[i]++ IF (prevCH[i] = 0) CH[i] = prevCH[i] END IF END FOR END
```
**Algorithm 3** Multiple Cluster Algorithm

#### 5.2.4 Data Collection Phase

After selecting the CH, the sink node uses a time programming (TDMA), giving a time limit for each node to transmit its data to the elected CH. In the second stage, the elected CH transmits the received data to the sink node as scheduled (TDMA). The cluster head, before transmitting the data to the SN, avoids transmitting (Etra) data. The mathematical model and analysis in the coming Section illustrate these ideas precisely. The pseudo-code of Algorithm 4 shows how to determine the current cluster, while the pseudo-code in Algorithm 5 shows how to transmit all cluster data to the sink node (SN). ```
Input:DeviceId,ClusterElements Output:Identify the cluster of each sensor fn_IdentifyCluster (DeviceId) BEGIN For each Cluster i of the network DO For each sensor j of the Cluster DO IF (DeviceId == ClusterElements[j][j]) THEN RETURN i END FOR END FOR END
```

**Algorithm 4** Identify the cluster of each sensor

**Scheme 2 (Multiple Cluster Algorithm):**

The sensor network is split into different groups; the data is collected from the sensor nodes in each group and transmitted to the corresponding cluster head. In turn, the head of the group sends the collected data to the central management unit sink node. In this case, the energy consumed can be calculated as:

\[E_{CH\text{-}SN}\!=\!\sum_{m=1}^{M}\!\left[\begin{array}{c}\sum\limits_{i}^{ N_{m}-1}\left(



where \(M\) indicates the cluster's number, \(N_{m}\) indicates the nodes' number in the corresponding cluster, \(dist_{i}\) indicates the distance between the node and its CH, \(dist_{m}\) indicates the distance between the CH and the SN, and \(N_{trans\_bits_{m}}\) indicates the number of data bits in the transmitted packet data. For example, Figure 4 also illustrates the Multiple Cluster Algorithm, which is a process of managing and monitoring the precision agriculture platform, where the network divides into different groups. Each agriculture platform in this scheme is identified as a cluster. The rest of the sensors transmit the obtained data to the corresponding cluster head, then the cluster head transmits the data (service and commands) to the sink node.