The development of wireless sensor networks (WSNs) technology comes with inherent limitations and vulnerabilities that make it exploitable by intruders. The fundamental goal of this article is to solve security problems related to black hole attacks, which interfere with the proper performance of the network and can lead to data leakage and loss. The proposed solution in this article is to apply IDS to a WSN for the first time. We also used the NS2.35 simulator to compare the three routing protocols, AODV, AODV under Hacker Node (HNAODV), and the proposed solution (IDSHNAODV) in the WSN model to reduce the effects of black hole attacks.