Introduction

In the nineteenth century, coffee cultivation in Brazil began to expand into the Cerrado region. The Cerrado is a vast region of savanna with poor soils. However, Brazilian coffee farmers developed new techniques for improving the soil, such as using lime and fertilizer. As a result, the Cerrado is now the world's largest coffee-producing region. The components nitrogen, phosphorus, potassium, calcium, magnesium, Sulphur, and iron can all be found in soil that is considered fertile1. The optimal soil for growing coffee is loamy soil, found in the state of north Karnataka, India which has a good combination of texture, drainage, and water retention. Coffee plantation soil requires well-drained soil to prevent waterlogging and root rot. Coffee plants have extensive root systems that extend deep into the soil to absorb nutrients and water2. The presence of nutrient-rich soil serves as the fundamental basis for the optimal growth and development of coffee plants, hence facilitating the production of superior-grade coffee beans. Fertility refers to the soil's ability to provide essential nutrients for plant growth, such as nitrogen, phosphorus, and potassium. Healthy soil leads to healthier coffee plants, which produce higher yields of high-quality beans. Coffee plants thrive in slightly acidic soil with a pH of 5.0–6.5.

Crop covering, composting, organic fertilizer, reduced tillage, water conservation, and shade management are ancient soil fertility strategies. Restoration of dry land to rich soil using IoT sensors to monitor and enhance coffee plantation soil health is creative and successful3. Soil sensors measure nitrogen, phosphorus, and potassium. Soil temperature sensors show how temperature affects plant growth and nutrient uptake. Farmers can protect coffee plants from extreme temperatures by tracking soil temperature patterns. Soil temperature sensors show how temperature affects plant growth and nutrient uptake. Analyzing soil temperature patterns protects coffee plants from extreme temperatures4. IoT sensors help farmers optimize irrigation, fertilization, and other soil management activities for healthier soil and higher crop yields by giving real-time soil data. Recurrent neural networks (RNNs) are a type of artificial neural network (ANN) that are well-suited for processing sequential data like IoT sensor time-series data. RNNs are useful for time series prediction, anomaly detection, and natural language processing because they can learn and understand temporal patterns and interdependencies in datasets. Recurrent neural networks (RNNs) provide the capability to analyze records of soil moisture data, enabling the prediction of forthcoming moisture levels. Conduct a comprehensive examination of soil nutrient data to predict potential nutrient deficits, hence facilitating the efficient and effective application of fertilizers by farmers. This research gap identifies characteristic patterns in soil sensor data, with a special emphasis on sudden changes in moisture and nutrient levels. Regular soil monitoring will monitor the alterations in soil condition and prompt safeguards will be implemented5. Develop predictive models that provide suggestions for optimal irrigation, fertilization, and other soil management practices. The limited scope of traditional soil testing often focuses on soil organic matter, microbial activity, and soil structure. However, the use of organic improvement in soil may result in delayed progress. Generalized suggestions derived from past data may not consider the particular soil characteristics, regional climate, or contemporary methods of management. The information provided Erroneous interpretation of soil test findings and suggestions might result in misguided conclusions and unproductive actions. Insufficient historical analysis, which fails to account for previous management techniques and local environmental conditions, can have an influence on evaluations of soil health status and long-term patterns. This paper is organized as follows: “Literature review” section presents a review of related work in Recurrent Neural Networks with the Internet of Things using deep learning. “The proposed model” section describes the proposed RNN-IoT approach in detail. “Results and discussion” section presents the experimental setup and results. “Conclusion” section discusses the results and compares RNN-IoT with existing methods. “Challenges and future possibilities” section concludes the paper and discusses future research directions.

Literature review

Aarthi, R., Sivakumar, D., et al., proposed the optimal watering schedule and fertilizer application rate. IoT software platforms that can be used to develop smart soil property analysis systems such as Thing Speak, Blynk, Cayenne, Node-RED, and Azure IoT Hub. Smart soil property analysis systems can provide real-time soil conditions data, allowing farmers to respond quickly to any changes. Future work is to develop more sophisticated machine learning models to improve the accuracy of the predictions6. Na, A., Isaac, W., Varshney, S, et al., proposed an Internet of Things (IoT)-based system for remote monitoring of soil characteristics a system that employs sensors to collect data on soil properties, such as pH, electrical conductivity (EC), moisture, temperature, and then communicates this data to a cloud platform or another remote location. These soil qualities include electrical conductivity (EC), pH, and temperature7. Jain, N., Awasthi, Y et al., proposed an IoT-based soil analysis system using optical sensors and multivariate regression is a system that uses optical sensors to measure the color and reflectance of soil and then uses multivariate regression to predict soil properties, such as pH, organic matter, and nutrient content. IoT-based soil analysis systems can be made small and portable, making them ideal for field use. Future work on IoT-based soil analysis systems could focus on making IoT-based soil analysis systems more affordable and accessible to small-scale farmers8. Patil, P et al., proposed the implementation of IoT to determine the level of bicarbonate in the soil a system that uses sensors to measure the pH and electrical conductivity (EC) of soil and then uses this data to calculate the bicarbonate level. IoT-based bicarbonate detection systems can provide users with the data they need to make informed decisions about irrigation, fertilization, and other agricultural practices9. Adrian Z et al. proposed integrating soil pH measurement into an Internet of Things (IoT) application a concept that involves using sensors to measure soil pH and then transmitting this data to a cloud platform or other remote location using a wireless communication protocol. The dataset collected by IoT-based soil pH measurement systems typically includes soil pH, Temperature, Humidity, Electrical conductivity (EC), and Timestamp10 as illustrated in Table 1.

Table 1 Literature review for soil health based on different proposed models.

IoT (Internet of Things) is a key enabling technology for smart agriculture, as it allows for the collection and analysis of data from sensors in real-time. IoT-based soil parameter measurement systems can provide real-time data on soil parameters, which allows farmers to respond quickly to changes. Future work on IoT-based soil parameter measurement systems could focus on making the systems easier to set up and maintain18. The materials and methods section describes how the soil is fertilized using IoT sensors and Cloud storage.

The proposed model

The primary objective of this research study was to monitor the overall condition of the soil and to design an advanced algorithm called RNN-IoT. The present techniques for measuring soil health based on existing and past guidelines have yielded inaccurate results. The suggested approach has successfully addressed all of the aforementioned limitations and obtained a predictable outcome in transforming barren land into sustainable and rich soil suitable for coffee cultivation.

Build an IoT sensor network to monitor soil health

  • Moisture and temperature sensors, Purpose: Measure soil moisture and temperature, Version used: N95S31B outdoor NB.

  • Carbon dioxide level sensors, Purpose:Measure CO2 concentration, Version used: CO2 concentration transmitter with 0–10 V, Measurement: CO2 concentration (0–10 V).

  • Soil water level indication, Purpose: Indicate soil water level, Version used: Nordic nRF9160 SiP.

  • GPS sensors, Purpose: Record location data, Version used: U-blox NEO-M8N.

  • LDR soil color sensors, Purpose: Measure NPK color value, Version used: MNS2-9-W2-CM-020.

  • Time stamps, Purpose: Record timestamps, Version used: Maxim Integrated DS3231.

  • GPS units, Purpose: Record location data.

Sensors measure soil potassium, phosphorus, and nitrogen levels and concentrations together with NPK color value indicators19. As demonstrated in Fig. 1, the N95S31B NB-IoT outdoor temperature and humidity sensor accurately measures air temperature and relative humidity.

Figure 1
figure 1

Working prototype for testing soil fertility.

It subsequently sends data to an IoT server over NB-IoT. CO2 sensors measure CO. The waterproof, sturdy CO2 concentration transmitter outputs 0–10 V. Nordic nRF9160 SiP is a low-power, single-chip cellular IoT solution. Its Arm Cortex-M33 CPU, low-power RF transceiver, and multiple ports make it adaptable. The Nordic nRF9160 SiP's ADC peripheral measures soil moisture. SiP receives soil moisture sensor data20. The Soil EC NPK PH Sensor monitors NPK, EC, and pH. Soil electrical conductivity (EC) may indicate salt concentration. Higher EC values imply plant-harming soil salt. Growing plants need nitrogen, phosphorus, and potassium. It means 20% nitrogen, phosphorus, and potassium in the soil. Soil pH indicates acidity or alkalinity. Acidic soils have pH < 7, while alkaline soils have pH > 7. Electrical conductivity sensors detect soil solution. NPK sensors evaluate soil solution light absorption at different wavelengths. This data can track soil health trends and identify areas that need specialist soil management. LDR soil color sensors like the MNS2-9-W2-CM-020 improve coffee plantation soil health monitoring21. The Maxim Integrated DS3231 time stamp may improve coffee plantation soil health monitoring in numerous ways. Plantation operators can use time stamps to find patterns and trends in soil health data as indicated in Fig. 2.

Figure 2
figure 2

Virtual abstract for proposed system.

Protocol for interfacing serial technology (IST)

Soil moisture sensors measure volumetric water content. Two electrodes detect soil electrical resistance, which fluctuates with water content. Sensor output is usually a soil moisture-proportional voltage or frequency as indicated in Eq. (1). Where VWC is the volumetric water content which finds the percentage of soil volume occupied by water, can be calculated based on the weight of the wet soil minus the weight of the dry soil which divides the weight of the dry soil. εa is the apparent dielectric permittivity of the soil, εb is the dielectric permittivity of dry soil, εc is the dielectric permittivity of water. Where ρn is the neutron count rate in the soil, ρd is the neutron count rate in dry soil, and ρw is the neutron count rate in water as indicated in Eq. (2).

$${\text{VWC}} = \left( {\upvarepsilon {\text{a}} -\upvarepsilon {\text{b}}} \right)/\left( {\upvarepsilon {\text{w}} -\upvarepsilon {\text{c}}} \right)$$
(1)
$${\text{VWC}} = \left( {\uprho {\text{n}} -\uprho {\text{d}}} \right)/\left( {\uprho {\text{w}} -\uprho {\text{d}}} \right)$$
(2)
$${\text{VWC}} = {\text{M}} + {\text{N}}*{\text{R}}$$
(3)

where R is soil electrical resistance and M and N are calibration constants from Eq. (3). A soil temperature sensor is needed to understand soil activity and plant growth22. It employs thermistors or thermocouples, whose resistance changes with temperature. Equation (4) shows that the sensor's voltage or current output is proportional to soil temperature. Where T is soil temperature, R is thermistor electrical resistance, and A and B are calibration coefficients.

$${\text{T}} = {\text{A}} + {\text{B}}*\ln \left( {\text{R}} \right)$$
(4)

Water level indicators assess soil water table depth. It employs a pressure transducer or ultrasonic sensor to detect water-induced pressure or sound reflection. Sensor output is generally a water level-proportional voltage or frequency. An NPK color value indicator evaluates soil nitrogen, phosphorus, and potassium levels. It measures soil extract color with a colorimetric sensor. Sensor output is generally an RGB color value or a numerical NPK level value. A GPS sensor locates the soil monitoring spot. GPS satellites inform it of its latitude, longitude, and altitude. The sensor sends NMEA messages with location coordinates as indicated in Eqs. (5), (6), and (7).

$${\text{Latitude}}={\text{ArcTan}}2\left({\text{sin}}\left({\upvarphi }\right),{\text{cos}}\left({\upvarphi }\right)*{\text{cos}}\left(\uplambda \right)\right)$$
(5)
$${\text{Longitude}} = {\text{ArcTan}}2\left( {\sin \left(\uplambda \right),\cos \left(\uplambda \right)*\cos \left( {\upvarphi } \right) - \sin \left( {\upvarphi } \right)*\sin \left(\updelta \right)} \right)$$
(6)
$${\text{Altitude}} = {\text{R}}*\left( {\sin \left( {{\upvarphi } - {\upvarphi }_{0} } \right) - \left( {{\text{R}}_{0} + {\text{h}}} \right)/{\text{R}}*\sin \left( {{\upvarphi }_{0} } \right)} \right)$$
(7)

where \({\upvarphi }\) is the geodetic latitude, \(\uplambda\) is the longitude, \(\updelta\) is the sun’s declination, R is the Earth's mean radius (6371 km), R0 is its equatorial radius (6378 km), h is the GPS antenna’s height above the Earth’s surface, and \({\upvarphi }_{0}\) is the reference ellipsoid’s latitude (43.66° LDRs (light-dependent resistors) measure soil color to determine nutrient content. It usually uses an LDR, which changes resistance when exposed to different wavelengths of light. Sensor output is generally a resistance value that fluctuates proportionately with soil color as indicated in Eq. (8).

$${\text{R}}=({\text{Cr}}+{\text{Cg}}+{\text{Cb}})/({\text{Cw}}+{\text{Cg}}+{\text{Cb}})$$
(8)

where R is the reflected light, Cr is the red light component of the incident light, Cg is the green light component of the incident light, Cb is the blue light component of the incident light, and Cw is the white light component of the incident light. Soils with higher organic matter content tend to reflect more red light and less blue light, while soils with lower organic matter content tend to reflect more blue light and less red light. A pH sensor monitors the acidity or alkalinity of the soil. Typically, it employs a glass electrode that generates a voltage that varies by the pH of the solution that it is surrounded by. The output of the sensor is often in the form of a voltage, and its magnitude is typically proportional to the pH of the soil as shown in Eq. (9).

$${\text{pH}}=-{\text{log}}10\left({\text{aH}}+\right)$$
(9)

pH is soil acidity or alkalinity and pH+ is hydrogen ion activity in the soil solution. Each soil health measurement is timestamped. Even when the gadget is off, its real-time clock (RTC) preserves precise time. Synchronizing soil health data with other sources and tracking changes requires the timestamp. Table 2 estimates dry land-rich soil in coffee plantations2. IoT sensors may be connected to Arduino using IST. The simple and efficient IST protocol is ideal for connecting many sensors to an Arduino microcontroller. It includes Master Out Slave, in Master in Slave Out, Slave Select, and Serial Clock. SCLK synchronizes master–slave data transfer. MOSI and MISO signals send data from master to slave and slave to master. The owner chooses the slave via SS. A start condition from the master device starts IST communication with the slave. Most starts are high-to-low SS signal changes. After supplying the start condition, the master device can send a MOSI bit per SCLK clock pulse to the slave device. The slave device receives MISO data and delivers a bit to the master device for each SCLK clock pulse. Stop signals from master devices to slave devices halt IST communication. SS signals typically rise during a standstill. Arduino microcontroller board with enough computing power for data handling and communication interfaces. Use appropriate cables to connect each sensor to the microcontroller board for proper pinout and voltage. In Algorithm 1, each sensor's communication protocols are configured for data acquisition.

Table 2 Parameters to fertile the coffee plantation soil from dry land.
Algorithm 1
figure a

Interfacing Serial Technologies (IST)

Configuration of sensor data transmission for arduino microcontroller

For analysts to collect precise measurements of crucial soil characteristics like temperature, moisture, PH, CO2, fertilizer level, and nutrient concentrations, sensors are submerged far below the surface of the soil23. The Arduino microcontroller serves as the system's primary central processing unit (CPU). It is in charge of gathering information from the sensors, processing that information, and then sending it to a computer or Laptop, Mobile Phone for utilization as indicated in Fig. 3. Arduino Uno, Wi-Fi module ESP8266, Jumper wires, breadboard, and 5 V Power Supply.

Figure 3
figure 3

Sensors connected to an Arduino microcontroller.

From an Arduino microcontroller to a Node MCU to the cloud

Arduino microcontrollers capture soil health data from connected sensors as the main data acquisition unit communicating with linked sensors, reading output values, and processing sensor data as requested. Arduino microcontrollers gather soil health data from sensors as the main data-collecting unit communicating with linked sensors, reading output values, and processing sensor data24. The Node MCU stores data in the cloud and uses AWS IoT Core for visualization, and these services are accessed through the Node MCU as indicated in Fig. 4.

Figure 4
figure 4

The connection between Arduino board to cloud storage.

Cloud Interface provides dashboards or visualization tools to monitor the uploaded sensor data in real time or over time. The data can be analyzed to identify patterns, trends, and anomalies, providing valuable insights into the monitored environment or process. Analyzed sensor data can be used to trigger actions, such as sending alert messages based on soil health conditions.

Recurrent neural network

The raw data was delivered to the input layer, where it was often preprocessed and normalized to ensure network interoperability. Load the CSV file into Panda’s data frame. Preprocess the data by performing necessary steps such as cleaning, handling missing values, and feature selection. Sequence formation has sequence length is a variable that determines the length of each sequence to be created. An empty list called sequences is initialized to store the generated sequences. Formula for GRU-based Soil Health Monitoring where, h_t is the hidden state of the GRU at time step t, h_{t − 1} is the hidden state of the GRU at time step t − 1, h_t̃ is the candidate hidden state at time step t, gate_update is the update gate, gate_reset is the reset gate.

$${h}_{t}=gat{e}_{update}*{h}_{\left\{t-1\right\}}+gat{e}_{reset}*{h}_{\widetilde{t}}$$
(10)

The update gate controls which information is allowed to flow into the hidden state from the previous time step where W_h is the weight matrix for the hidden-to-hidden state connection, U_x is the weight matrix for the input-to-hidden state connection, b_h is the bias vector for the hidden state, x_t is the input at time step t.

$${h}_{\widetilde{t}}=tanh\left({W}_{h}*{h}_{\left\{t-1\right\}}+{U}_{x}*{x}_{t}+{b}_{h}\right)$$
(11)

Loops from 0 to len(data)—sequence length + 1. This loop generates dataset sequences. Unfold the RNN into interconnected layers with input, forget, cell, and output gates. Input the current input into the input gate to regulate information flow into the hidden state. Apply the forget gate on the previous hidden state to determine how much to remember. Update the cell state depending on the input gate, forget gate and previous hidden state cell state that stores sequence long-term memory.

$${C}_{t}={f}_{t}*{C}_{\left\{t-1\right\}}+{i}_{t}*tanh\left({W}_{h}*{h}_{\left\{t-1\right\}}+{U}_{x}*{x}_{t}+{b}_{c}\right)$$
(12)

Consider Ct as the cell state at time step t, \({C}_{\left\{t-1\right\}}\) at time step t − 1, and \({h}_{\left\{t-1\right\}}\) as the forget gate \({i}_{t}\) is the input gate, tanh is the hyperbolic tangent activation function, \({W}_{h}\) and \({U}_{x}\) are the hidden-to-hidden and input-to-hidden weight matrices, respectively. At time step t, \({b}_{c}\) is the bias vector for the cell state, \({x}_{t}\) is the input, and \({h}_{\left\{t-1\right\}}\) is the hidden state. Use the output gate to create the current time step output that passes cell state information. Gated recurrent units (GRUs) architecture trains the dataset properly depending on soil prediction features. At each time step, calculate the error between expected and actual output. Back propagates the error via the unrolled RNN to calculate weight error gradients. Update weights to reduce inaccuracy. Prediction and Analysis in the RNN model increase warnings and suggestions by predicting soil health metrics from real-time sensor inputs. Historical sensor data, growth trends, and FFNN soil health results train the model25. Change specifics to simulate scenarios.

Counter-factual recommendation generation

Parameters within historical data to represent various ‘what-if’ situations. It compares with the actual generated out with historical data to generate recommendations. They are comparing the recommendation using three ways Present data—Historical data, Historical data—Historical data, and Present data—Present data as illustrated in Fig. 5.

Figure 5
figure 5

Counter-factual recommendations.

For example, let us contemplate a hypothetical situation in which a soil health monitoring system, based on feedforward neural network (FFNN) architecture, provides a recommendation for the optimal application rate of fertilizer for a particular agricultural area. Counterfactual suggestion has the potential to be employed to generate alternative fertilizer recommendations. Manhattan distance, often known as taxi cab distance, is calculated by adding the absolute coordinate differences of two places. Imagine traveling solely horizontally or vertically in Manhattan’s grid. Distance is calculated using present and historical data. Consider N points in K-dimensional space, where 2 <  = N <  = 10^ {5} and 1 <  = K <  = 5. Find the location with the lowest Manhattan distance from the N places. Manhattan distance is two points measured along right-angle axes. It is |x1 − x2| +|y1 − y2| on a plane with p1 at (x1, y1) and p2 at (x2, y2). Sorting the points in all K dimensions and outputting the middle components of each dimension reduces the Manhattan distance.

$$Manhattan\;Distance = \left| {s1 - s2} \right| + \left| {r1 - r2} \right|$$
(13)

The Manhattan Distance, which indicates the dissimilarity between the current suggestion and several alternative fertilizer options, may be calculated as shown in Eq. (13), where |s1 − s2| denotes the absolute difference between the two points’ s-coordinates. |r1 − r2| is the absolute difference in r-coordinates. The calculation considers nutritional content, application rates, and environmental effects. The system may create counterfactual suggestions with Manhattan Distances below a threshold. This keeps alternate options comparable to the original advice while allowing for varied perspectives. The implementation phase collects and analyzes data.

Results and discussion

The field implementation of the AI-powered system involved deploying IoT sensors in selected infertile agricultural fields to collect real-time soil data. These sensors continuously monitor soil properties such as moisture, temperature, pH, nutrient levels, and electrical conductivity. XG-booster is used for the pre-training model for predicting specific soil properties (e.g., nutrient content, and moisture levels) based on sensor data. The collected data was then fed into the AI system, which employed RNNs and GRUs to identify patterns and trends in soil health indicators as indicated in Fig. 6.

Figure 6
figure 6

Agriculture land setup for testing soil fertility. (a) Agricultural infertile land, (b) 5-week monitoring land, (c) 6–10 week monitoring land, (d) 11–15 weeks monitoring land, (e) 16–20 weeks monitoring land, (f) Fertile soil.

Evaluation setup

Hardware setup has a Microcontroller—Arduino Uno heart of any IoT device, and it is responsible for collecting data from sensors, processing that data, and sending it to the cloud. Sensors- Soil moisture sensor, soil temperature sensor, pH sensor, and nutrient sensor. Wireless Communication Modules—Wi-Fi communication module, Bluetooth communication module, cellular communication module, Irrigation system actuator, fertilizer applicator actuator. AC power supply, DC power supply, battery, SD card, USB flash drive. Software setup has Windows operating system, python 3.6 Amazon Web Services (AWS)0.5, Data Visualization Tools—Matplotlib, simulates the suggested model on PC i5-8600 k, GeForce 1050Ti 4 GB, 16 GB RAM, 250 GB SSD, and 1 TB HDD. The suggested model is evaluated using False Negative, True Positive, True Negative, and False Positive metrics using the Recurrent Neural Network and Counter-Factual Recommendation Generation.

Field setup for improving soil fertility

Enhancing the fertility of the soil is essential for achieving sustainable agriculture and achieving maximum crop yields. To evaluate and enhance the fertility of the soil throughout a range of monitoring periods, this experiment describes a field design that makes use of several land portions. Datasets are collected in real-time from Madikeri, Coorg, Karnataka total of 640, monthly monitoring based on historical data from the past three years recorded around 300582.

Performance evaluation compared with RNN

A proposed model is compared to existing models to determine its accuracy. Table 3 shows random forest, SVM, K-means clustering, GAN, and feed-forward neural network. This performance is measured using several metrics, including accuracy, precision, recall, and F1 score. Accuracy is the most straightforward metric, measuring the proportion of correct predictions made by the model. Precision measures the proportion of correct positive predictions. Recall, also known as sensitivity, measures the proportion of actual positive instances that are correctly identified as positive.

Table 3 Performance analysis for the proposed model.
$$Accuracy = (True\; Positives + True \;Negatives) / (Total\; Samples)$$
(14)
$$Precision = True\; Positives / (True\; Positives + False\; Positives)$$
(15)
$$Recall = True\; Positives / (True \;Positives + False \;Negatives)$$
(16)
$$F1 \;Score = 2 * (Precision * Recall) / (Precision + Recall)$$
(17)
$$Specificity = True \;Negatives / (True \;Negatives + False\; Positives)$$
(18)

The proposed method achieves 94.25% accuracy, while random forest, SVM, K-means clustering, GAN, and FFNN obtain 81.22%, 81.66%, 82.12%, 88.12%, and 89.73%. Existing approaches take longer to calculate all datasets. Figure 7 shows that the suggested technique detects events better than current methods. High EC and TDS readings indicate excessive salinity, which can stress and reduce coffee plant output. Most of the 30-day monitoring period had optimum EC and TDS values. NPK levels reflect coffee plant nutrient availability. Low nitrogen, phosphorus, and potassium (NPK) levels can decrease coffee plant output. The reduction in NPK levels from day 11–30 suggests dietary replenishment. During days 1–10, the soil moisture was a little dry, but otherwise, it was excellent. The rain prevented soil desiccation and reduced coffee plant stress. Figure 8 shows that soil temperature also affects coffee plant development. Coffee plants like soil temperatures between 20 and 25 °C. During the monitoring period, soil temperature stayed within the optimal range, promoting root growth and nutrient absorption.

Figure 7
figure 7

Result analysis for the proposed approach.

Figure 8
figure 8

Mobile application.

Optimization of the model

To keep the coffee plants healthy and the farm skiing, it is important to monitor the soil health of the plantations. Beans with more robust scents and tastes are a product of soil that is both healthy and well-tended. Farmers may maximize water and fertilizer efficiency and cut down on production expenses by learning what their soil requires to be healthy. To maintain healthy and fertile soil over the long term, it is important to evaluate it regularly for signs of nutrient imbalances. Weekly data analysis utilizing the RNN model is used to monitor soil conditions, and farmers are updated on health-related information and comments about soil quality. For a more precise prediction, we compare the soil condition from the second week of monitoring with that from the first week. In a similar way comparing week 2 with week 1 generates correct results, comparing week 3 with week 2 and so on also yields accurate results.

Measurements taken to enrich the soil of coffee plantations in arid regions

When substantially monitoring and tracking various essential indicators such as electrical conductivity (EC), total dissolved solids (TDS), nitrogen (N), phosphorus (P), potassium (K), soil moisture, soil temperature, carbon dioxide (CO2), and soil pH, agricultural practitioners can promptly detect potential issues and implement appropriate measures to uphold an optimal ecosystem for their coffee crops. The soil solution's EC and TDS levels indicate salt content as indicated in Table 4.

Table 4 Measurement Range to fertile the coffee plantation soil from dry land.

CO2 levels rose somewhat from day 11–20, indicating a healthier soil microbial community. Coffee plants thrive best at 5.5–6.5 soil pH as illustrated in Fig. 9. The soil pH remained within the correct range during the monitoring period, ensuring that coffee plants could easily obtain nutrients as shown in Table 5. Rainfall is vital to soil hydration. The monitoring period was without significant precipitation from day one to day fourteen. This shows that irrigation was needed to maintain soil moisture levels throughout this era. Day 15 brought 15 mm of rain, restoring soil moisture. Coffee plant soil health measurements were within optimal levels for most of the 140-day monitoring period from week 1 to week 20.

Figure 9
figure 9

Weekly monitoring using the IoT Platform.

Table 5 Parameters to fertile the coffee plantation soil from dry land.

Counter-factual recommendation

RNN-IoT model uses historical data and real-time sensor readings to predict future soil states and potential crop threats. Based on these predictions, the system generates counterfactual recommendations—alternative actions your farm could take to achieve desired outcomes.

Mobile application sample

The mobile application was created with the open-source Google framework Flutter, employing JavaScript. The RCNN model has been integrated and implemented, resulting in the generation of recommendations. These recommendations are created using Counterfactual suggestions.

Figure 10 is a discussion based on the question raised by the agriculturist from various parts of the coffee plantation growers. Soil-rich mobile-based applications will provide recommendations after analyzing sensor data. Agriculturist question was “How do soil conditions that are too dry, too wet, too cold, or too hot affect coffee plants”. The recommendation is generated as High or low soil pH can make it difficult for coffee plants to absorb nutrients. Solution: Apply soil amendments to adjust the pH to the optimal range. The specific type of soil amendment to apply will depend on the current soil pH and the desired pH range. Similarly, “How does rainfall affect coffee plants, and what can coffee growers do to mitigate the negative effects of extreme rainfall events”. The recommendation is generated as Insufficient or excessive rainfall can lead to water stress or soil erosion. Irrigate during periods of low rainfall and implement erosion control measures during periods of high rainfall. Monitoring rainfall patterns is important to ensure that coffee plants receive the right amount of water26. The proposed model is trained using the Training Set, which enables it to discover hyperlinks and patterns in the data. To minimize loss and enhance predictions. To evaluate the model's performance and adjust its hyper-parameters, a validation set is utilized during its development. Evaluates the model's ability to be extrapolated to new data, which helps avoid excess fitting. The testing set is utilized for the final and unbiased evaluation of the model's performance once all training and hyper-parameter adjustments have been finished. Ensures the model's ability to apply knowledge to unfamiliar data and offers an accurate evaluation of its capabilities as shown in Fig. 11. The total dataset is divided into 60% for training, 20% for validation, and 20% for testing. The difference between predicted and actual values is computed using a loss function by mean square error. The loss is propagated backward through time, updating model parameters (weights and biases) to minimize the loss.

Figure 10
figure 10

Farmer’s query-based recommendation.

Figure 11
figure 11

Training and validation loss versus accuracy of RNN over counterfactual recommendation.

A confusion matrix is an illustrative format that exhibits the success of a proposed theory27. The data represents the observed vs projected results for each week of monitoring. Within the realm of soil fertility, weekdays may be classified as several tiers of fertility. For instance, weeks 1–7 exhibit low fertility, weeks 8–14 demonstrate medium fertility, and weeks 15–20 showcase high fertility, making them suitable for cultivation as shown in Fig. 12.

Figure 12
figure 12

Multiple confusion matrix for monitoring soil accuracy.

By using IoT sensors to track soil moisture, temperature, pH, and nutrient levels, coffee farmers can gain valuable insights into their crops' health and needs. Figure 13 data can then be used to make informed decisions about irrigation, fertilization, and other agricultural practices—a 20-week soil monitoring study that tracks the soil condition in a coffee plantation. The study was conducted in a coffee plantation in Madekari, Coorg, and Karnataka, India. Ten IoT sensors were installed on the plantation, and data was collected every hour for 20 weeks. The sensors measured soil moisture, temperature, and pH at a depth of 10 cm throughout 20 weeks. Due to heavy rainfall in the early weeks of the research, soil moisture was maximum. Dry weather diminished soil moisture. The study's soil temperature peaked in the first weeks and then dropped as the weather cooled. pH was almost consistent throughout the investigation.

Figure 13
figure 13

IoT sensors monitoring land view.

20-week. The investigation produced soil moisture, temperature, and pH maps. These maps helped identify under and over-watered crop regions and regulate the irrigation system. The maps were also utilized to identify acidic and alkaline soil on the farm and adapt the fertilization program.

Conclusion

The foreseeable future of coffee production demands beyond merely cultivating a diverse range of coffee beans; it involves establishing a sustainable and lucrative coffee business that will endure for future generations. Utilizing sophisticated sensors allows for the monitoring of environmental variables, including precipitation, humidity, and temperature, to optimize agricultural productivity. Internet of Things (IoT) devices have the potential to accurately assess the levels of water and nitrogen present in soil. Furthermore, by assessing the CO2 concentration in agricultural areas, it is possible to accurately monitor evapotranspiration rates, therefore enhancing the monitoring of soil health. This requires equipping coffee growers with the necessary tools and expertise to develop intelligent soil—a flexible and robust ecosystem that supports the growth of healthy coffee plants while reducing environmental harm. Farmers are provided with immediate updates on the condition of their soil and receive alerts on any potential issues. This enables farmers to promptly address any early signs of soil degradation. The Recurrent Neural Network and Counterfactual Recommendations utilize advanced algorithms to forecast future trends and provide tailored soil cures for youthful agriculturists. Knowledgeable farmers make well-informed choices regarding their soil, leading to higher crop production, better quality, and more profitability. The proposed method has overcome all of the above drawbacks and achieved the predictable result for converting infertile land to fertile land sustainable for coffee plantations.

The future direction is moving towards installed outside Internet of Things devices are subject to severe weather, dust, wind, temperature, and other environmental hazards. This is one of the main issues with these devices. Unexpected mechanical failure of the complex devices could occur as a result of unfavorable environmental circumstances. Therefore, the raw materials used to construct the Internet of Things (IoT) devices used in smart farming must be able to endure such harsh climatic conditions. This will ensure that the devices last longer and provide more consistent results. Coffee cherry early detection and recommendation based on advanced deep learning technology which empowers farmers to cultivate a sustainable future for coffee, one smart earth revolution at a time.

Challenges and future possibilities

Global research on the Internet of Things (IoT) and sensor-based smart farming have revealed positive results. It is employed in several small-scale agricultural domains a rural farm, where farmers have less technological expertise, may provide more challenges. Even so, the execution of the project on a broad scale is still awaiting completion. An obstacle of great importance is the financial burden associated with the deployment and installation of IoT-tagged sensors and accessories in vast agricultural areas. Furthermore, there is ambiguity regarding the expenses associated with implementation and the monetary benefits that may be obtained. Deploying IoT-enabled technology incurs substantial expenses for hardware, software, and system operation. Supplementary costs may encompass energy usage, system upkeep, service enrollment, and labor fees for operating combined hardware and software. Enhancing farmers' digital literacy on a global scale is crucial to facilitating the extensive use of IoT technologies. Lack of comprehension and consciousness of IoT-based technologies in agriculture might result in the underutilization of intelligent systems in farming28. Government policymakers should develop economic strategies to facilitate the successful and efficient implementation of Internet of Things (IoT) technology by farmers in agricultural areas. Data privacy and security issues might hinder large-scale IoT and smart system adoption. Attackers can manipulate cloud server data to harm automated agricultural activities in farmlands. Attacks can negatively impact agricultural output and prevent good environmental management. IoT data security concerns contribute to the sluggish adoption of smart farming systems. Encryption is crucial for protecting critical data and digital systems in smart farming from global cyberattacks. Integrating cryptography with strong keys can reduce cyber threats on cloud systems. Additional methods, such as integrating multiparty computing with homomorphic encryption or block-chain, can yield accurate results.

Experimental statement

No plants and Animals are disturbed for research work. All image datasets information regarding plant-based processes or applications was obtained from publicly available and ethically sourced data and publications. Plant Collection materials are complying with institutional, national, and international guidelines and legislation. So we confirm that all methods were performed in accordance with the relevant guidelines/regulations/legislation.