Wireless Sensor Networks (WSNs) consist of multiple sensor nodes, each of which has the ability to collect, receive and send data. However, irregular data sources can lead to severe network congestion. To solve this problem, the Proportional Integral Derivative (PID) controller is introduced into the congestion control mechanism to control the queue length of messages in nodes. By running the PID algorithm on cluster head nodes, the effective collection of sensor data is realized. In addition, a fuzzy control algorithm is proposed to solve the problems of slow parameter optimization, limited adaptive ability and poor optimization precision of traditional PID controller. However, the parameter selection of the fuzzy control algorithm relies too much on expert experience and has certain limitations. Therefore, this manuscript proposes the Cuckoo Fuzzy-PID Controller (CFPID), whose core idea is to apply the cuckoo search algorithm to optimize the fuzzy PID controller’s quantization factor and PID parameter increment. Simulation results show that in comparison with the existing methods, the instantaneous queue length and real-time packet loss rate of CFPID are better.