In Wireless Sensor Networks (WSN), the denial of sleep attack consumes more amount of energy which leads to depletion of battery power. This consumption of power makes the nodes more susceptible to the vulnerabilities and hence denial of service through denial of sleep. If a large percentage of network nodes, or a few critical nodes, are attacked in this way, the network lifetime can be reduced severely. In order to overcome the denial of sleep attack in this paper, we propose to develop a swarm based defense technique for denial of sleep attack. Initially an anomaly detection model is developed which determines the affected traffic between the nodes and based on this, the frequency hopping technique is initiated. Ant agents of Swarm intelligence are applied in each channel to collect the communication frequency and the frequency hopping time. Based upon the frequency hopping time the faulty channel is identified and the when the administer node gets this information it deletes the faulty channel. From our simulation results, we prove that this technique proves to be efficient in detecting the faulty channel and consumes less energy since the information about the all the attackers can be known using ants.