Global food security is under increasing threat from pest organisms that target agricultural production. The broad-spectrum pesticides traditionally used to combat these pests cause permanent damage to ecosystems, pose risks to human health, and lead to a critical decline in biodiversity. Precision agriculture technologies, as part of the Agriculture 4.0 revolution, offer innovative solutions to these problems. This study focuses on developing a novel artificial intelligence model capable of detecting and classifying pest insects with high accuracy, to serve as the intelligence for autonomous spraying systems. Within the scope of this research, a comprehensive and diverse dataset of over 12,000 images was meticulously compiled, featuring a total of 11 insect species, including 8 economically significant pests and 3 beneficial species for the ecosystem. To enhance the robustness and diversity of the dataset, advanced Generative Adversarial Networks (GANs) such as StyleGAN2-ADA were used alongside traditional data augmentation techniques to generate synthetic images. On this rich dataset, VGG-16 and ResNet152 V2 models, representing the transfer learning approach, were developed and comparatively analyzed against a lightweight Convolutional Neural Network (CNN) architecture custom-designed for resource-constrained edge computing devices. While the ResNet152 V2 model achieved the highest accuracy (92.4%) in laboratory tests, the custom-designed CNN model proved to be the most practical and effective solution in real-world field tests conducted with a Raspberry Pi-based prototype, delivering 82.5% accuracy, a much smaller model size (31 MB), and superior processing speed (7.5 FPS). These results strongly demonstrate that application-specific, lightweight models can exhibit more robust and efficient performance in real-world scenarios compared to complex and large transfer learning architectures. The developed system has the potential to make significant contributions to agricultural sustainability and food security by optimizing pesticide use.