This study explores the integration of Wireless Sensor Networks (WSN) and Machine Learning (ML) in smartfarming to address critical agricultural challenges. By leveraging real-time data collection and advanced analytical tools,the research demonstrates the potential of ML algorithms—Decision Trees, Naive Bayes, Support Vector Machines(SVM), Logistic Regression, and Random Forests—in enhancing crop management, including yield prediction, soilquality assessment, and pest and disease detection. The study finds that Naive Bayes achieves the highest accuracy andbalanced precision-recall metrics, while ensemble methods like Random Forests effectively reduce overfitting andimprove prediction accuracy. Despite the promising results, the research identifies challenges such as data accessibility,model integration, and user interface design that must be addressed to fully realize the potential of smart farmingtechnologies. Overall, the findings provide valuable insights into optimizing resource utilization, reducing crop losses,and promoting sustainable farming practices, thereby supporting global food security and economic stability.