View full-text article in PMC Sensors (Basel). 2018 Mar 19;18(3):907. doi: 10.3390/s18030907 Search in PMC Search in PubMed View in NLM Catalog Add to search Copyright and License information © 2018 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/). PMC Copyright notice Algorithm 1 Leader Election Algorithm. 1:Kopt←n2×π×20.765 2:Popt←Koptn 3:ThresholdLEACH←Popt1−Popt×(rmod(1Popt)) 4:MaxNumberElection←GetMaxNumberOfElections() 5:ElectionCounter←0 6:while “Node without a leader” do 7: ThresholdEnergy←GetCurrentBatteryPowerLevel()GetFullBatteryPowerLevel() 8: Threshold←ThresholdLEACH×α+ThresholdEnergy×(1−α) 9: RandomNumber←random(0,1) 10: ElectionCounter←ElectionCounter+1 11: if RandomNumber<Threshold or ElectionCounter>MaxNumberElection then 12: SetNodeAsLeader() 13: else 14: wait(random(0,1)) 15: end if 16:end while