This study presents an innovative approach integrating Internet of Things (IoT) and machine learning for optimized water management in precision agriculture, focusing on jasmin, date and pomelo farming in a drought-prone area where Imjai Organic Garden is located (Chachoengsao, Thailand). The research addresses a critical need for efficient water use in agriculture, particularly in regions facing spells of both drought and flooding. Using a multi-depth and multi-sensor IoT setup, the real-time data from soil moisture, temperature and water levels at the site were collected and transmitted via NB-IoT technology. The data facilitated the development of virtual soil moisture sensors through machine learning models, specifically Linear Regression, Random Forest, Support Vector Regression (SVR) and Long Short-Term Memory (LSTM) networks. Such models demonstrated a high accuracy in predicting soil moisture levels, thus reducing the need for frequent physical sensor maintenance. The study's novelty lies in its comprehensive approach combining IoT and advanced machine learning to provide actionable insights for water management, thus enhancing both agricultural productivity and sustainability. Quantitatively, the integration of machine learning models improved water usage efficiency by 37% for jasmine flowers, 28% for date palms, and 19% for pomelo trees. This research contributes to the body of knowledge in precision agriculture, and it also offers practical solutions for sustainable water resource management in Thailand's agricultural sector.