1 Introduction

Anthropogenic activities pose an escalating threat to freshwater resources through pollution. Despite the uneven distribution of freshwater worldwide, it remains a pivotal asset for sustaining livelihoods and fostering economic development. The primary contributors to the deterioration of freshwater quality are human actions and lifestyles [1]. The growing demand for vibrant clothing has spurred the expansion of textile industries, which, in turn, consume substantial amounts of water and consequently discharge considerable volumes of wastewater. Wastewater originating from textile plants possesses distinctive characteristics, typically containing various dyes and heavy metals [2]. Dye molecules have become a significant factor contributing to the critical issue of water pollution, largely due to the expansion of the textile industry in the contemporary world [3].

Wastewater resulting from dyeing processes is predominantly produced by industries such as textiles, papermaking, dyeing, cosmetics, electronics, and printing. Textile wastewater contains numerous hazardous organic pollutants, including azo dyes such as Rhodamine B, methylene blue, methyl orange, congo red, and malachite green. Additionally, heavy metals like chromium, mercury, and cadmium, as well as inorganic salts, are present. These organic dyes exhibit highly toxic and carcinogenic properties. Moreover, their complex chemical structures make natural degradation difficult. The treatment and removal of these persistent organic pollutants and heavy metals present in textile effluents are imperative to mitigate their environmental and health impacts. Without effective control and treatment, these pollutants have the potential to disturb ecological balance, resulting in water pollution and posing serious threats to human health [4].

Rhodamine B (RhB) belongs to the xanthene class of dyes and is among the earliest synthetic dyes created [5]. RhB is classified as a textile dye with an azo chemical structure, boasting not only excellent water solubility but also a high binding energy that allows for the formation of coloration clusters that remain stable in aqueous solutions for a considerable duration [6]. Dyes are categorized as cationic, anionic, and non-ionic dyes due to their particle charge [3]. RhB is a commonly used cationic dye with broad industrial applications in textiles, paper, and pharmaceuticals. It possesses a stable chemical structure that is resistant to degradation. Additionally, RhB exhibits relatively low toxicity compared to other industrial dyes. Its popularity coupled with its persistence in the environment makes RhB a priority dye for the development of effective treatment methods [7, 8]. The release of untreated wastewater containing the dye RhB into environmental waters raises substantial health and safety concerns. RhB exposure can lead to hazardous effects including skin and organ congestion, respiratory issues, gastrointestinal damage, and potentially even fatalities. Developing effective treatment methods to remove RhB from textile effluents before discharge is crucial to mitigate these risks and protect aquatic ecosystems and human health [9]. The prolonged presence of RhB in aquatic environments can hinder the ability of underwater flora to undergo photosynthesis, resulting in diminished levels of dissolved oxygen, an increase in the proliferation of bacteria and viruses, and an ongoing deterioration of water quality [10]. Consequently, it is essential to purify effluent with RhB dye before it is discharged into waterways to protect aquatic life and enhance the safety of the environment for the general public [11].

Adsorption is regarded as an alternative technology among the several treatment methods available, primarily due to its simple equipment, low operational costs, and high efficiency [7, 12, 13]. There are numerous materials that have demonstrated potential as adsorbents for removing water contaminants. These include chitosan, zeolite, activated carbon, cellulose aerogel, mesoporous silica, bio-composites, metal–organic frameworks (MOFs), and bentonite. Research efforts continue to identify and optimize novel adsorbents to effectively eliminate hazardous pollutants from wastewater through adsorption processes. Selecting appropriate adsorbents depends on the target contaminants as well as water composition and conditions. Further development of cost-effective, high-capacity adsorbents is needed to improve wastewater treatment and enable water reuse [12, 14, 15]. Standard criteria for selecting a new adsorbent typically involve considerations such as large surface area, high pore volume, regenerability, ease of disposal, and low cost [16,17,18]. Biochar, a carbon-dense substance derived from biomass such as wood, agricultural residues, and other organic matter through the process of pyrolysis, exhibits diverse and valuable characteristics. Notably, its high surface area, porosity, and cation exchange capacity render it a material of significant interest for various applications. These applications span across fields such as energy production, agriculture, and environmental remediation. Current research focuses on the production, characterization, and utilization of biochar, highlighting its role as an environmentally friendly and efficient catalyst for the removal of various pollutants [5, 19, 20]. Agricultural by-products have emerged as promising low-cost adsorbents, enabling waste recovery and reuse [21]. The future use of modified biochar for removing organic dyes from contaminated water requires large-scale, long-term field studies and further research to confirm its industrial scalability, including biochar regeneration and waste management techniques [22].

Aligning with this approach, modified biochar pine nut shell (MPNBC) was synthesized from pine nut shells. MPNBC offers a high surface area and specific affinity for adsorbing dyes from water, demonstrating its potential as a sustainable and economical adsorbent alternative to commercially available activated carbons for dye removal from wastewater.

This research developed a sustainable adsorbent derived from agricultural waste to efficiently remove the textile dye RhB. The effects of various process parameters on adsorption efficiency were investigated by conducting adsorption studies at different pH levels, dye concentrations, adsorbent dosages, and contact times. The adsorption characteristics of RhB onto the MPNBC adsorbent were analyzed using kinetic and isotherm models. The experimental results were subsequently modeled using artificial neural network (ANN) techniques.

2 Materials and methods

2.1 Materials

Rhodamine B ≥ 95% (C28H31ClN2O3, MW 479.01 g/mol) dye was obtained from Sigma-Aldrich. All the other chemicals utilized in this work were reagent grade.

2.2 Preparation of the modified biochar

Biochar was synthesized from pine nut shells sourced from the mountainous regions of Turkey. Initially, the pine nut shells were cleaned, crushed, and sieved to obtain particles of 425 µm in size. The modified pine nut shell biochar was then prepared by pyrolyzing 20 g of these 425 µm particles with 60 g of NaOH as the activating agent in a muffle furnace at 600 °C for 2 h under a nitrogen flow of 0.15 mL/min. After pyrolysis, the biochar was allowed to cool, washed with distilled water to achieve neutral pH, and subsequently oven-dried at 120 °C for 24 h to produce the final adsorbent sample. Figure 1 summarizes the preparation of MPNBC.

Fig. 1
figure 1

The preparation of MPNBC

2.3 Characterization of the adsorbent

Scanning electron microscopy (SEM) imaging was conducted on an Elementar Unicube microscope to characterize the surface morphology of the prepared MPNBC. The surface elemental composition of activated carbon was examined by the Xplore 30 energy-dispersive X-ray spectroscopy (EDX) system. Surface functional groups were identified by Fourier transform infrared (FTIR) spectroscopy with the PerkinElmer instrument. Nitrogen adsorption isotherms were measured at 200 °C on an autosorb iQ analyzer to determine the BET surface area and monolayer volume. X-ray diffraction (XRD) patterns were obtained on a Rigaku Smart Lab instrument under Bragg–Brentano geometry at a scan speed of 5 °C/min and 2θ range from 5 to 60° with 0.01° scan intervals.

2.4 Adsorption studies

2.4.1 The effect of pH, contact time, modified pine nut shell biochar dosage, and initial dye concentration

The RhB has a molecular formula of C28H31ClN2O3 and a molar weight of 479.02 g/mol. Figure 2 demonstrates the three-dimensional geometry of RhB species.

Fig. 2
figure 2

Three-dimensional geometry of RhB species

Experiments were conducted using 100 mL samples in conical flasks. Batch adsorption experiments were performed on a Julabo SW22 laboratory shaker at 200 rpm. Kinetic adsorption experiments were first carried out at 10 mg/L dye concentration and pH 3.0 to evaluate the impact of contact time over a range of 5 to 240 min. Then, the dosage of modified pine nut shell biochar was tested for the selected appropriate period of time. For this purpose, 6 different dosages were used (0.1–1 g/L). Adsorption isotherm experiments were then carried out over an initial Rhodamine B concentration range of 5 to 50 mg/L. Furthermore, the effect of pH was also examined. After each adsorption experiment, the samples were filtered and analyzed using a Hach-Lange DR6000 UV–VIS spectrophotometer to measure absorbance at 554 nm. Rhodamine B concentrations were determined from a calibration curve. Kinetic experiments were performed at 25 °C over 5 to 240 min of contact time using an initial dye concentration of 10 mg/L. Equilibrium isotherm experiments were performed at 25 °C with a 60-min shaking time at initial dye concentrations ranging from 5 to 50 mg/L. All batch adsorption experiments were performed in duplicate to verify reproducibility, and average values were used for analysis. The quantity of adsorbed RhB onto MPNBC (1) and the percentage of dye removal (2) was calculated by the following equations:

$$qe= \frac{\left(C_{0}-Ce\right)\times V }{m}$$
(1)
$$\text{Removal }({\%}) = \frac{(C_{0}-Ce)}{m} \times 100{\%}$$
(2)

In the equations, C0 and Ce symbolize the starting and final equilibrium concentrations in milligrams per liter for Rhodamine B, V is the volume (L) of the solution, m is the mass (g) of modified pine nut shell biochar (MPNBC) adsorbent, and qe signifies the equilibrium adsorption capacity (mg/g) of Rhodamine B.

2.5 Artificial neural networks (ANNs)

Artificial neural networks (ANNs) are computational models inspired by biological neural systems that exhibit exceptional abilities to learn and adapt. ANNs approximate complex relationships between weighted inputs and corresponding outputs to enable predictive modeling. This is achieved through interconnected nodes resembling neurons in a brain that process and transmit signals. By adjusting the weighted connections during training, ANNs can model intricate nonlinear relationships between multiple variables. This makes ANNs a versatile predictive tool across diverse applications [23, 24]. The core components of an ANN are the input layer, hidden layer(s), and output layer. The number of input layer neurons corresponds to the independent variables used for prediction. The output layer contains neurons representing the predicted target variables. Hidden layers in between comprise interconnected neurons that function as feature detectors to approximate complex relationships. Multiple hidden layers can extract higher-level features and model highly nonlinear systems. The weights linking neurons are iteratively adjusted during network training to minimize errors in predicting the target outputs. This multilayer architecture provides ANNs with powerful function approximation capabilities [25, 26].

ANN model was developed in this work to simulate and predict the adsorption capacity of Rhodamine B dye onto the modified pine nut shell biochar adsorbent. Throughout the learning phase, the network weights underwent modifications using a supervised learning approach based on backpropagation (BP). The Levenberg–Marquardt algorithm was used to train the artificial neural network model. The optimal number of neurons in the hidden layer was determined separately for each training run. This approach was adopted to ascertain which backpropagation (BP) training method produced the most effective outcomes. A feedforward backpropagation neural network model was developed using a hyperbolic tangent sigmoid activation function (tansig) in the hidden layer and a linear activation function (purelin) in the output layer. The network training process involved employing a trial-and-error approach across multiple epochs (trials) to attain optimal results, focusing on maximizing R2 and minimizing root-mean-square error (RMSE). Figure 3 shows an ANN structured with input, hidden, and output layers in a parallel distributed arrangement. The input layer accepts the data features serving as inputs. The hidden layers comprise interconnected neurons that identify patterns and extract higher-order features from the input data. The output layer generates the target prediction variables that the ANN model is trained to produce based on the detected patterns. The layers are fully connected by adjustable weighted parameters or connections. By iteratively updating these weights during training, the ANN can learn complex nonlinear relationships between the input variables and outputs. This multilayer architecture provides neural networks with powerful modeling and function approximation capabilities for diverse applications.

Fig. 3
figure 3

The optimized structure of the artificial neural network

All artificial neural network computations were executed using the MATLAB (2021b) program. The input layer comprised 12 neurons representing initial RhB dye concentrations, pH, carbon dosage, and contact time. The output layer contained a single neuron representing the adsorption capacity, which was the target output variable predicted by the ANN model.

3 Results and discussion

3.1 Characterization of the modified pine nut shell biochar

3.1.1 Structures and functional groups

The surface functional groups of the adsorbent play a major role in facilitating the adsorption mechanism. These groups serve as interactive sites for adsorbate binding, enabling their retention. Hence, Fourier transform infrared spectroscopy (FTIR) finds utility in characterizing materials by identifying the functional groups present in adsorbent substances [16, 17]. The wavenumbers and profiles of FTIR absorption peaks, which correspond to the bending and stretching of specific bonds, exhibit variations determined by the functional group and structural attributes of the molecule being analyzed [17].

Fourier transform infrared (FTIR) spectroscopy was utilized to characterize the surface functional groups present on the modified pine nut shell biochar (MPNBC) adsorbent and Rhodamine B (RhB) dye. The FTIR spectra obtained over the range of 650 to 4000 cm−1 (Fig. 4a) revealed several key functional groups. Intense broad bands from 3070 to 3600 cm−1 in both samples originate from overlapping O–H stretches (carboxyl, phenolic) and N–H stretches [27]. The band at 2987 cm−1 corresponds to the methyl C–H stretching vibration, while the band at 2917 cm−1 corresponds to the methylene C–H stretching vibration [23, 28]. Absorbance peaks at 1500 and 1400 cm−1 can be assigned to C–C skeletal vibrations [29]. Additionally, bands ranging from 1260 to 1050 cm−1 represent C–O stretches in various oxygen-containing functional groups [29].

Fig. 4
figure 4

FTIR spectra (a) and XRD pattern (b) of MPNBC

The MPNBC sample displayed a more pronounced and sharper diffraction peak at 25.29° (2θ), suggesting a higher degree of graphitized carbon structure compared to other samples. This organized graphite structure may promote the formation of π-π bonds, thus improving the adsorption capacity for pollutants with conjugated structures during the adsorption process [30]. The X-ray diffraction (XRD) pattern of the modified pine nut shell biochar (MPNBC) adsorbent is displayed in Fig. 4b. The diffractogram shows characteristic peaks at 2θ values around 25.29°, which can be attributed to the overlapping crystal planes of carbon. This organized graphite structure may promote the formation of π-π bonds, thus improving the adsorption capacity for pollutants with conjugated structures during the adsorption process [30].

The weight loss behaviors during the carbonization and activation processes at a temperature of 600 °C were monitored using a thermogravimetric analyzer (TGA, TA Instruments, Q5000). MPNBC sample was first weighed and placed in a tray with a weight of 5–7 mg. The sample was heated with nitrogen from 25 to 600 °C at a constant heating rate of 10 °C/min. The results of thermogravimetric analysis (TGA) are shown in Fig. 5. During the initial thermal treatment (25 to 80 °C), a slight weight loss was observed due to the desorption of adsorbed water. This finding corroborates previous studies, which found no significant differences among the MPNBC samples in this temperature range. The second stage of weight loss occurred uniformly across all samples, characterized by a rapid decrease in weight (70% to 95%). This drop is attributed to cellulose degradation, involving depolymerization, dehydration, and decomposition of glucose units, leading to the formation of char, resulting in rapid weight loss from 80 to 100 °C [31].

Fig. 5
figure 5

TGA results of MPNBC

3.1.2 Morphologies and elemental composition

Scanning electron microscopy (SEM) images of the pine nut shell activated carbon (MPNBC) are shown in Fig. 6a, revealing the surface morphology. Energy-dispersive X-ray (EDX) spectroscopy results (Fig. 6b) demonstrate that MPNBC has an elemental composition comprised of 87% carbon, 11.8% oxygen, 0.9% sodium, 0.2% calcium, and 0.1% magnesium. As indicated in Table 1, the microporous volume of MPNBC (Vµ) is 0.350 cm3/g, the total pore volume (VT) is 0.9539 cm3/g, and the specific surface area (SBET) reaches 1280.189 m2/g.

Fig. 6
figure 6

SEM images (a) and EDX spectrum (b) of MPNBC

Table 1 Summary of BET surface area, total pore volume, micropore volume of PNAC

The nitrogen adsorption–desorption isotherms for MPNBC are shown in Fig. 7a. It has been observed that the nitrogen adsorption–desorption isotherm belongs to type 2 according to the IUPAC classification. This is associated with nonporous or macroporous structures [32]. The nitrogen desorption isotherms were utilized with the Barrett-Joyner-Halenda (BJH) method to determine the pore size distribution of the synthesized MPNBC adsorbent. As shown in Fig. 7b, MPNBC exhibits a narrow pore size distribution with a substantial fraction of micropores under 20 Å, indicating the prevalence of small pores in the prepared activated carbon.

Fig. 7
figure 7

Nitrogen adsorption–desorption isotherms (a) and pore diameter distribution (b) of MPNBC

3.2 Adsorption study

3.2.1 Effect of pH

The adsorption process is significantly influenced by the solution pH, as it alters both the molecular structure of the dye and the surface properties of the adsorbent [33, 34]. At varying pH levels, different concentrations of H+ and OH ions will be present in the solution. The ions clash with dye molecules to fill the active binding sites present on the adsorbent’s surface [35]. Therefore, solution pH is a critical parameter influencing adsorption performance. The effect of pH was investigated by conducting adsorption experiments in the pH range of 3.0 to 9.0 to assess and optimize the uptake of RhB dye. Experiments were conducted at a RhB concentration of 10 mg/L for 60 min. Figure 8a displays RhB uptakes and removal efficiencies across different solution pH values, while Fig. 8b presents the pH spectrum. The adsorption capacity results displayed in Fig. 8a demonstrate that RhB uptake decreased from 20.16 to 19.49 mg/g with increasing solution pH from 3.0 to 9.0. Similarly, the removal efficiencies were found to be 100% at pH 3.0, decreasing to 96% at pH 9.0.

Fig. 8
figure 8

Effect of pH on the adsorption of RhB on MPNBC removal efficiency (a) and adsorption capacity (b) UV − VIS absorption spectra (adsorbent dosage = 0.5 g/L, initial dye concentration = 10 mg/L, contact time = 60 min)

3.2.2 Effect of contact time

Kinetic experiments were performed with a contact time in the range of 0–240 min to determine the time required to reach adsorption equilibrium using RhB concentration of 10 mg/L at pH 3.0. As shown in Fig. 9a, the adsorption capacity and removal efficiency increased sharply within the first 40 min of contact. Maximum removal of 100% was attained at 40 min, with an equilibrium capacity of 20.16 mg/g. Only minimal further uptake occurred beyond 40 min, reaching 20.20 mg/g at 240 min. The initial rapid phase can be attributed to abundant available binding sites initially. The system gradually reaches saturation as sites become occupied over time. Equilibrium was thus effectively achieved in 40 min under the conditions studied [33, 36].

Fig. 9
figure 9

Effect of contact time on the adsorption of RhB on MPNBC removal efficiency (a) and adsorption capacity (b) UV − VIS absorption spectra (pH = 3.0, adsorbent dosage = 0.5 g/L, initial dye concentration = 10 mg/L)

3.2.3 Effect of initial dye concentration

The influence of initial Rhodamine B dye concentration was studied over a range of 5–50 mg/L to determine equilibrium adsorption capacity. Batch experiments were conducted at optimal conditions with 0.5 g/L modified pine nut shell biochar dosage and 60 min contact time. As depicted in Fig. 10a, the efficiency of dye removal decreased from 100 to 65% as the initial concentration increased from 5 to 50 mg/L. This decreasing trend can be attributed to the limitation of available binding sites on the adsorbent, which became saturated at higher dye concentrations with an excess of RhB molecules in the solution. The equilibrium adsorption capacity is contingent on the maximum uptake efficiency of the adsorbent for the target contaminant [33]. As depicted in Fig. 10a, the adsorption capacity exhibited a notable increase, rising from 9.65 to 59.89 mg/g, with an elevation in the initial RhB concentration from 5 to 50 mg/L. The greater driving force for mass transfer at higher dye concentrations leads to enhanced uptake. Fundamentally, the acceleration of the diffusion and transportation of dye molecules into the pores and surfaces of the modified biochar derived from pine nut shells enhances the mass transfer rate and extends the coverage of adsorption sites. However, at higher concentrations, intensified repulsive forces among dye molecules hinder the interactions with binding sites [37]. Additionally, active sites become saturated as concentration increases, limiting further uptake. This reduces the removal efficiency at higher initial dye loadings, although equilibrium capacity continues to rise [38, 39].

Fig. 10
figure 10

Effect of initial dye concentration on the adsorption of RhB on MPNBC removal efficiency (a) and adsorption capacity (b) UV − VIS absorption spectra (pH = 3.0, adsorbent dosage = 0.5 g/L, contact time = 60 min)

3.2.4 Effect of adsorbent dosage

To investigate the effect of MPNBC dosage on Rhodamine B adsorption, a contact time of 60 min, a starting dye of 10 mg/L, and pH 3.0 were kept constant, while the amount of adsorbent was varied between 0.1 and 1 g/L. As shown in Fig. 11a, an inverse correlation exists between adsorbent dose and equilibrium adsorption capacity, whereas dye removal efficiency exhibits a directly proportional relationship with increasing dosage [38]. Removal efficiency rose markedly from 43 to 100% as mass was increased from 0.1 to 0.5 g/L, attributed to the greater availability of binding sites and surface area. However, no significant change occurred above 0.5 g/L, suggesting saturation. Additionally, adsorption capacity increased from 8.75 to 20.16 mg/g over 0.1 to 0.5 g/L, indicating enhanced RhB uptake with more adsorbent until the optimum dose is met. Thus, raising the MPNBC dosage positively affected both efficiency and capacity up to 0.5 g/L under the studied conditions.

Fig. 11
figure 11

Effect of adsorbent dosage on the adsorption of RhB on MPNBC removal efficiency (a) and adsorption capacity (b) UV − VIS absorption spectra (pH = 3.0, contact time = 60 min, initial dye concentration = 10 mg/L)

3.3 Adsorption kinetics and isotherms

Kinetic modeling is vital for unraveling adsorption mechanisms and identifying the rate-limiting steps, including mass transfer and chemical interactions [40]. Models describe the correlation between adsorbate uptake and contact time. Fitting the data to different kinetic equations reveals whether physisorption or chemisorption governs the process. As shown in Fig. 12a and Table 2, the applicability of pseudo-first-order, pseudo-second-order, and Elovich models was examined for the adsorption of RhB onto MPNBC [41]. The pseudo-second-order model provided the best fit, with high R2 values approaching 1 (0.997) and excellent agreement between predicted and experimental adsorption capacity. This suggests chemisorption controls the adsorption rate, whereby electron exchange occurs between dye and adsorbent functional groups. Thus, the pseudo-second-order kinetics successfully describe the chemisorption mechanism for the effective removal of RhB by MPNBC.

Fig. 12
figure 12

Different a adsorption kinetics of RhB adsorption onto MPNBC (pH = 3.0, initial dye concentration = 10 mg/L, adsorbent dosage = 0.5 g/L) and b adsorption isotherms of RhB adsorption onto MPNBC (pH = 3.0, adsorbent dosage = 0.5 g/L, contact time = 60 min)

Table 2 Kinetic parameters of RhB adsorption on PNAC

The adsorption isotherm model is an essential tool in designing adsorption systems, offering insights into the interaction between adsorbate species and adsorbent materials, and is crucial for estimating the theoretical maximum adsorption capacity. Adsorption isotherm fitting is a reliable method to assess the feasibility of adsorption systems, evaluate adsorbent performance, and predict adsorption mechanisms [41]. There are commonly used two-parameter and three-parameter adsorption isotherms for determining the adsorption mechanism in aqueous environments. Equilibrium adsorption isotherms describe the interactive behavior between adsorbates and adsorbents. Langmuir, Freundlich, and Temkin are two-parameter models, while Redlich-Peterson and Khan incorporate three parameters. As shown in Fig. 12b, these five isotherms were fitted to the experimental data for RhB uptake by MPNBC. As observed in Table 3, all models provided good fits with a high coefficient of determination (R2 > 0.9). The Langmuir, Redlich-Peterson, and Khan models exhibited the highest R2 values. The Langmuir model assumes monolayer formation on the homogeneous surface, with equivalent binding sites and equal activation energy. The good fit suggests the applicability of the monolayer coverage assumptions to describe the adsorption mechanism of RhB on MPNBC [42, 43]. The Redlich-Peterson isotherm incorporates features of both the Langmuir and Freundlich models, representing a hybrid isotherm. The adsorption mechanism does not follow an ideal single-layer adsorption mechanism. This isotherm works in both homogeneous and heterogeneous environments [43, 44]. The Khan isotherm is a generalized model proposed for adsorbate adsorption in pure solutions, representing both Langmuir and Freundlich isotherms [45].

Table 3 Isotherm parameters of RhB adsorption on PNAC

3.4 Comparison of dye adsorption using modified biochar derived from agricultural wastes

According to Xiao et al. [46], research findings indicate that activated carbon derived from white sugar exhibits the highest efficiency, reaching 98%, in removing RhB within a 12-min period [47]. A sulfur-doped tapioca peel biochar (S@TP) adsorbent was synthesized and applied to remove organic dyes malachite green (MG) and RhB from water. Equilibrium adsorption isotherm analysis showed excellent dye uptake capacities of 30.18 mg/g for MG and 33.10 mg/g for RhB by the S@TP biochar. Optimal adsorption performance was achieved at pH 8.0, with the adsorption process reaching saturation within 120 min. Diao et al. [48] investigated the adsorption behavior of three dyes on activated carbon derived from sweet potato residue. The isotherm analysis indicated that the activated carbon demonstrated an adsorption capacity of 30.18 mg/g for carmine dye molecules. Effective adsorption was observed at pH 7.0, with saturation reached within a timeframe of 60 min. In their study, Dimbo et al. [49] explored the use of activated carbon from Spathodea campanulata for removing methylene blue dye from wastewater. Optimization studies revealed 99.95% maximum dye elimination under conditions of pH 9, 120 min contact time, 90 mg/L methylene blue concentration, and 0.2 g of adsorbent per 100 mL solution. These parameters were determined to be optimal for the adsorption process through detailed testing. Bello et al. [50] prepared activated carbon from ackee apple pods to adsorb methylene blue (MB) dye. Equilibrium isotherm results showed the activated carbon had a substantial MB uptake capacity of 47.17 mg/g. Maximum adsorption rate and extent occurred at pH 6, reaching saturation in 90 min of contact time. Waghmare et al. [51] prepared activated carbon from papaya peels using phosphoric acid (H3PO4) and utilized it for the biosorption of methylene blue (MB) dye. An adsorption capacity of 46.95 mg/g for methylene blue was attained with papaya peel activated carbon (PSPAC). Optimal dye removal conditions were determined to be 0.3 g of PSPAC adsorbent dose per 10 mg/L of MB at pH 6.0, with 90 min of contact time. Bouzid et al. [52] employed activated carbon derived from chemically activated rosemary roots using H3PO4 as an adsorbent. Optimal adsorption conditions were determined with a contact time of 30 min and a carbonization time of 120 min. An admirable adsorption capacity was attained using 15 mg of the adsorbent at pH 3.25, 328.15 K temperature, and 50 mg/L dye concentration. Khalfaoui et al. [53] used ZnCl2-activated Moringa oleifera shells, calcined at different temperatures, as adsorbents for removing methyl red dye. Moringa shells calcined at 200, 300, 400, and 500 °C exhibited maximum monolayer capacities of 25.45, 27.10, 28.13, and 28.67 mg/g, respectively. The adsorbent prepared at the highest temperature of 500 °C achieved the maximum methyl red uptake of 28.67 mg/g. In the present study, modified biochar obtained from pine nut shells (MPNBC) was investigated for the removal of RhB through adsorption. Approximately 100% removal efficiency was achieved at an adsorbent dosage of 0.5 g/L at pH 3.0 with an initial RhB concentration of 10 mg/L, and isotherm analyses revealed that the MPNBC exhibited an adsorption capacity of 123.46 mg/g. Table 4 presents the adsorption capacities of dyes by different activated carbons and modified biochars synthesized from agricultural waste materials.

Table 4 Adsorption of dyes by different activated carbons derived from agricultural waste materials

3.5 Statistical model artificial neural networks (ANNs)

The data is randomly divided into three categories: learning (70%), testing (15%), and validation (15%). The learning dataset is utilized for training the artificial neural network model, while the testing dataset enables the evaluation of the ANN model’s prediction capabilities. The ANN model performance was evaluated based on statistical measures, including root-mean-square error (RMSE) and coefficient of determination (R2). As shown in Table 5, the root-mean-square error and correlation coefficient were examined for different numbers of neurons in the hidden layer. The minimum error was attained with 12 hidden neurons. Therefore, this optimal configuration of 12 hidden layer neurons was utilized for the ANN modeling.

Table 5 Effect of the number of neurons in hidden layer on the performance of the neural network

In recent years, ANN models have been employed to establish comprehensive models for adsorption equilibria. The weights, tailored for activation functions derived from ANNs, play a crucial role. Neurons are interconnected, with the weight multiplying the input to each neuron. The assessment of the impact of different input variables on the output variables was conducted through analysis of the neural weight matrix. The subsequent equation, derived from the distribution of connecting weights, was employed for this purpose:

$$Ij=\frac{{\sum }_{m=1}^{m=Nh}\left(\left(\left|{W}_{jm}^{ih}\right|/{\sum }_{k=1}^{Ni}\left|{W}_{km}^{ih}\right|\right) \times \left|{W}_{mn}^{h0}\right|\right)}{\sum_{k=1}^{k=Ni}\left\{{\sum }_{m=1}^{m=Nh}\left(\left|{W}_{km}^{ih}\right| / \sum_{k=1}^{Ni}\left|{W}_{km}^{ih}\right| \times \left|{W}_{mn}^{h0}\right|\right)\right\}}$$
(3)

The relevance of the jth input variable to the output variable is quantified by the importance index Ij. The connection weights between neurons are denoted as Ws. Ni and Nh represent the number of input and hidden layer neurons, respectively. The superscripts “i,” “h,” and “o” indicate neurons belonging to the input, hidden, and output layers, while subscripts “k,” “m,” and “n” denote the kth input, mth hidden, and nth output neurons [54]. A network architecture containing twelve hidden neurons was adopted, with the corresponding weights and biases detailed in Table 6.

Table 6 Matrices of weights: W1, weights between input and hidden layers; W2, weights between hidden and output layers

The accuracy of the ANN model was evaluated using the ratio of the coefficient of determination (R2) to the root-mean-square error (RMSE). The optimal network was selected based on model performance parameters. RMSE and R2 values obtained on the evaluation dataset were used to identify the best-performing ANN configuration. The calculations for R2 and RMSE were as follows:

$${R}^{2}=1 -\frac{\sum_{\dot{\text{I}}=1}^{N}{\left({Y}_{i,\text{pred}-}{Y}_{i,\text{exp}}\right)}^{2}}{\sum_{\dot{\text{I}}=1}^{N}{\left({Y}_{i,\text{pred}-}{Y}_{m}\right)}^{2}}$$
(4)
$$\text{RMSE}={\left[\frac{1}{N}\sum\nolimits_{\dot{\text{I}}=1}^{\dot{\text{I}}=N}{\left({Y}_{i,\text{pred}-}{Y}_{i,\text{exp}}\right)}^{2}\right]}^{1/2}$$
(5)

Here, the number of data points shown as N, yi,pred is the predicted output, yi,exp is the experimental output, ym represents the mean of experimental outputs, and i indexes the data points [24].

Figure 13a compares the ANN-predicted adsorption capacity values against experimental data for the test set. The strong correlation indicates reliable prediction capability. Among the input variables, initial dye concentration was found to be the most influential parameter governing adsorption capacity with a relative importance of 68% (Fig. 13b). The pH, dose, and time also exhibited substantial impacts of 3%, 24%, and 5%, respectively, on adsorption capacity.

Fig. 13
figure 13

a Comparison between the experimental results and those predicted by the neural network model is presented for the test sets. b Importance of dependent variables of ANN model

The solid line in Fig. 13a represents the line of best fit determined from regression analysis by minimizing squared residuals. The correlation coefficient R2 quantifies how closely the predicted capacities agree with experimental values. R2 approaching unity signifies improved model performance. For the test set, R2 equaled 0.9985 confirming accurate prediction of adsorption capacity by the optimized ANNs across the range of operating conditions.

4 Conclusion

Organic dyes pose serious environmental risks due to their toxicity, carcinogenicity, and resistance to conventional removal techniques. Treating these pollutants before releasing them into water bodies is essential. Modified biochar has emerged as a promising and sustainable method for effectively removing organic dyes from industrial wastewater. The focus of the present investigation was on the preparation of agricultural waste as an adsorbent derived from pine nut shell (MPNBC). Characterization of MPNBC was conducted using FTIR, EDX, XRD, and BET techniques. The MPNBC demonstrated a BET surface area of 1280.189 m2/g, indicating a favorable surface area. Analysis of the N2 adsorption–desorption isotherm revealed a mesoporous pore distribution in MPNBC. Parameters including pH, initial dye concentration, adsorbent dose, and contact time were optimized to maximize Rhodamine B removal by pine nut shell activated carbon (MPNBC). Approximately 100% dye elimination was achieved at optimal conditions of pH 3.0, 0.5 g/L adsorbent dose, and 60 min of contact time. Equilibrium isotherm analysis revealed a maximum MPNBC uptake capacity of 110.68 mg/g based on the Langmuir model, which showed the closest fit to experimental data. Kinetic modeling indicated pseudo-second-order rate kinetics with the highest regression fit. The artificial neural networks (ANNs) accurately predicted adsorption capacity, with a root-mean-square error of 0.9985 and R2 of 0.983 between modeled and experimental values. Overall, MPNBC demonstrated excellent performance for efficient Rhodamine B elimination under suitable conditions. All examined parameters exhibited a significant effect on adsorption capacity. Notably, the initial dye concentration emerged as the most influential parameter for adsorption, with an importance rating of 68%. This observation suggests that ANN modeling can effectively simulate and predict the performance of adsorption capacity processes. Overall, MPNBC derived from agricultural waste showed promising potential as a cost-effective adsorbent for RhB removal from wastewater.