Wireless sensor networks (WSNs) play a critical role in cyber-physical systems, enabling communication between autonomous sensors. When integrated with the Internet of Things (IoT), WSNs unfortunately become vulnerable to various attacks, such as blackhole, grayhole, flooding, and scheduling, thereby posing significant security threats. Existing methods for intrusion detection in WSNs often suffer from low detection rates, significant computational overhead, and false alarms, primarily due to resource constraints and data correlations. This study introduces IDS-CNN, a novel intrusion detection method leveraging Convolutional Neural Networks (CNNs). The proposed IDS-CNN model, designed to optimize efficiency and reduce processing time, comprises nine convolutional neural network layers and six Max-Pooling1D layers. To alleviate computational demands, dimensionality reduction techniques, specifically Principal Component Analysis and Singular Value Decomposition, are applied to raw traffic data. The IDS-CNN model is then employed to classify and categorize network threats. Experimental evaluations suggest that the IDS-CNN approach yields a high accuracy rate of 99% compared to existing methods, based on tests performed on two datasets, WSN-DS and UNSW-NB15. Notably, with the UNSW-NB15 dataset, accuracy rates were further improved to 99.99% and 100%. By leveraging deep learning techniques to enhance intrusion detection in WSNs, this study presents a significant contribution to the field. The IDS-CNN model advances our understanding of WSN security by exceeding the accuracy rates of prior models. As it addresses the limitations of existing methods, the implications of this research are substantial, offering a more reliable and efficient solution for WSN intrusion detection. The findings underscore the potential of IDS-CNN in safeguarding WSNs and IoT systems from sophisticated and evolving cyber threats.