Given the high importance of wireless sensor networks in various applications, it is necessary to examine the important challenges of these networks. The challenges of these networks are the short life of the nodes, which leads to shortening the life of the network and ultimately disrupting the network. One of the ways to increase efficiency and reduce energy consumption in the network is to use clustering methods. In this research, using clustering methods and selection of efficient clusters by DEEC algorithm and optimization of this algorithm using cuckoo algorithm. The results of the study showed an improvement in reducing energy consumption in this type of network, so that the energy remaining in the network after the simulation in routing with the new protocol is about 13% more than TTDD routing about 11% more than routing with APTEEN protocol. If we consider the life of the network when the first node in the network is turned off, in the new protocol, the first node is turned off 7 seconds later than the TTDD protocol and 13 seconds later than the APTEEN protocol. This means that, on average, the lifespan of the network has been increased by about 10% with the new protocol.