Many researchers have implemented various machine learning algorithms and verify their results with the existing algorithms to control congestion in Wireless Sensor Networks. The major challenge lies in developing an algorithm which optimizes the value of the objective function on the basis of parameters like network throughput, residual energy and packet loss rate of the nodes in the network. An objective function based on these parameters is proposed in the present work. Water wave optimization algorithm is applied on the objective function and an optimum solution is obtained. The proposed approach is compared with the Congestion Detection and Avoidance algorithm (CODA) and Particle Swarm Optimization Algorithm (PSO). The proposed solution outperforms both algorithms on the basis of various performance parameters.