An essential component of the Indian economy is agriculture. Precision farming, another call for smart farming, is a novel method of farming that incorporates modern innovations to improve production, sustainability, and performance over traditional techniques. These involve strong data security measurements, the reliance on high-quality sensor data, and possible integration issues with current farming systems. This study proposed a methodology for smart farming using IoT sensor statistics incorporated with a unique Dynamic Artificial Fish Swarm Driven XGBoost (DAFSXGBoost) model. Initially, research was conducted on a Kaggle dataset. Substantially, the "Crop recommender CSV" file, containing vital IoT sensor records, which include temperature, humidity, rainfall, soil potential of Hydrogen (pH), and nutrient ratios, changed into utilized. Data cleaning procedures were implemented to rectify inaccuracies, incompleteness, and redundancy. The dataset has been split into subsets for testing and training to improve the model. The proposed DAFSXGBoost approach, carried out with the use of MATLAB, is designed to enhance predictive accuracy while maintaining low latency and efficient hardware usage. The findings demonstrated that the proposed DAFS-XGBoost method achieves effective recall, accuracy, precision, f1-score, training time, and MSE rates as 93.76%, 96.73%, 94.61%, 90.12, 0.0006, and 0.19. The framework’s potential to combine outstanding performance and a hardware-friendly design to promote the longterm viability of smart farming is confirmed by simulations.