In the current era of computer and communication rapid development, network security has become one of the most important factors to consider. Security considerations in wireless sensor networks (WSNs) have been an interesting point in research especially with the fast spread of WSNs. In this paper, an efficient two-layer and three-layer intrusion detection models are introduced. The two-layer model represents the levels of the sensor and sink nodes. The three-layer model represents the levels of the sensor, sink and base station. The models are elaborated and examined through a set of experiments. A supervised learning algorithm is introduced to be used in the sensor node layer and an unsupervised learning algorithm is introduced to be used in the other layers. The learning algorithms used only 10% of the data for training and gave a high detection accuracy on the used dataset, using lesser number of features compared to other approaches.