1 Introduction

Corrosion is a natural process, where steel broke down and became damaged. In industrial applications, the undesirable and severe traits of steel surfaces caused by corrosion cost many billions to governments [1]. It was attended by the flow of electrical current resulting in the conversion of a metal to a more chemically stable form (oxides) in corrosive media. The significant financial loss developed the corrosion control methods to protect metals, such as inhibitive and sacrificial coating, alloying, cathodic protection, plating, corrosion inhibitors, galvanizing, greasing [2]. Unfortunately, corrosion cannot be fully inhibited, but the usage of one of these strategies is a possibility to slow down the kinetics and/or alter the corresponding corrosion mechanism [3]. Nowadays, researchers have established that the usage of corrosion inhibitors is the most useful and effective strategy to protect metals [4,5,6]. They offer the highest protection at the lowest possible cost due to their less expensive compositions, availability, and high mechanical properties.

To prevent corrosion, metal oxide nanoparticles have been highly used due to their outstanding performance and remarkable optical, electrical, catalytic, and corrosion resistance properties [1]. Nanoparticles of ZnO [7], SiO2 [8], and Fe2O3 [9] significantly improved the corrosion resistance of the coated steel. MgO was found to be an efficient corrosion inhibitor in HCl solutions with an inhibition of 70% [10]. The redox characteristics of Zr-doped ceria nanoparticle solid solutions were due to the oxygen vacancies that improved the anti-corrosion activity [11]. Similarly, Zn–Ni–CuO composite thin films provided good corrosion protection due to their high surface area, mechanical strength, durability, and availability [12]. Also, they shed light on the Raman studies of steel surfaces before and after corrosion inhibition. Varvara et al. [13] demonstrated that Raman spectroscopy provides a significant and reliable strategy for the identification of corrosion damage on steel surfaces. They also demonstrate a considerably diminished degradation of carbon steel surface in the presence of 5-(4-pyridyl)-1,3, 4-oxadiazole-2-thiol inhibitor in 1 M HCl solutions, as verified from the surface analysis exposed by Raman spectra. Li and Peng [14] declared that iron corrosion was successfully inhibited by the adsorption of Tagetes erect extracts onto the steel surface in 3.5% NaCl solutions, confirming using Raman spectra.

Among metal oxides, copper oxide (CuO) nanoparticle has a vital and potential role in anti-corrosion applications, due to their large surface area, good chemical stability, and superior catalytic activity [15]. The most vastly used alloy is mild steel, which is found extensively in the industrial section, storage tanks, manufacturing, buildings, and pipelines, because of its incredible mechanical properties, availability, and inexpensive cost [16, 17]. On the contrary, this steel is one of the types that are most exposed to corrosion, which provokes a major crisis in the industrial field and massive economic losses. When mild steel is exposed to different types of acids, it suffers from intense deterioration, especially with hydrochloric and sulfuric acids. The combination of mild steel and acids is actively happening in different situations, including acid descaling, cleaning, oil refinery, and buildings [3].

Indeed, at present, there are no published studies dedicated to synthesizing CuO nanoparticles doped with Mg used in the anti-corrosion area. Therefore, in this work, ethylenediaminetetraacetic acid (EDTA)-capped Cu1-xMgxO nanoparticles with x = 0.000, 0.005, 0.010, 0.015, and 0.020 were prepared through the effective, simple, and low-cost method, i.e., the co-precipitation method. Furthermore, this study aims to investigate the electrochemical corrosion behavior of 10 ppm of these nanoparticles with the addition of 1% of sodium dodecyl sulfate (SDS) as a surfactant of mild steel in 0.5 M HCl and H2SO4 solutions using electrochemical impedance spectroscopy (EIS) and potentiodynamic polarization techniques. This method was used due to its high yield and better control of the particle size along with the addition of the capping agent ethylenediaminetetraacetic acid (EDTA). These aspects may play a critical role in the enhancement of the anti-corrosion activity of nanoparticles. In this concern, the main object of this work is to study electrochemically the anti-corrosive behavior of the synthesized pure and Mg-doped CuO nanoparticles on mild steel in acidic media by using impedance and polarization techniques, where the mild steel surface and the corrosion products were studied using Raman spectra.

2 Experimental Techniques

2.1 Nanoparticles Preparation and Characterization

Cu1-xMgxO nanoparticles with x = 0.000, 0.005, 0.010, 0.015, and 0.020 were prepared using co-precipitation method as described previously [18, 19]. The nanoparticles were measured by the Raman technique using a confocal microscope (Alpha 300R from WITEC). The spectra were collected using Nd-YAG laser excitation source (λ = 532 nm), and 50 × magnification objectives were used. To minimize any damage in the sample, the laser power was adjusted to a minimum (around 5 mW), where several positions were investigated for each sample. A silicon reference material was used. The clustering type is used in Raman studies where it is a type of unsupervised machine-learning technique that involves grouping similar data points into clusters based on their similarities. Also, clustering is helpful for identifying patterns, trends, and outliers in large datasets.

2.2 Solution Preparation

Two corrosive solutions of HCl and H2SO4 were used in performing the electrochemical studies. The pure and Mg-doped CuO nanoparticles were used as corrosion inhibitors. Prior each experimental test solution, 0.5 M HCl or H2SO4 is added to an appropriate mass (10 ppm) from each of the prepared nanoparticles with the presence of 1 g of sodium dodecyl sulfate (SDS) surfactant, that will act as a surfactant to support the adhesion of the inhibitor to the steel surface easier. Then, double distilled water was added in 100 mL volumetric flask to obtain a solution of 0.5 M HCl or 0.5 M H2SO4 solutions and the required concentration of the nanoparticles. Finally, the solutions were sonicated using a Bandelin Sonoplus ultrasonic stirrer for 15 min in order to obtain homogeneous solutions.

2.3 Electrochemical Techniques

Electrochemical impedance and polarization measurements were achieved using frequency response analyzer (FRA)/potentiostat supplied from ACM instruments (UK). During electrochemical measurement, the cell involves the gathering of three electrodes: platinum wire electrode, saturated calomel electrode (SCE), and the mild steel used as auxiliary electrode, reference electrode, and working electrode, respectively. The data is measured at 30°C, using water bath. The EIS measurements were immediately performed under measured Ecorr, start-up frequency ranges from 0.1 to 3 × 10 kHz, with applied potential signal amplitude of ± 10 mV around the rest potential. In the entire experiment, the Nyquist diagrams were fitted based on an equivalent circuit. Polarization curves were obtained at a sweep rate of 1 mVs−1 where these measurements were done within a potential range of ± 250 mV around the rest potential. The mild steel composed of an area of 0.7853 cm2 which was set up in a Teflon rod by which only one face of the mild steel was left in contact with the solution. Its elemental analysis are as follows (wt. %): Fe: 98.8; Mn: 0.57; Si: 0.085; C: 0.198; P: 0.02; S: 0.038. Before each test solution, the electrode was hand-polished using grade emery papers of different grit sizes 320, 600, and 800 to get a mirror finish. Then, it is cleaned and immersed in 100 ml of the prepared solution. The cell was connected to the Gill AC sequencer instrument which was controlled by a laptop for data logging and analysis.

2.4 Nanoparticles Characterization

According to our previous literature [18], the impact of Mg2+ dopants on CuO nanoparticles was explored by X-ray diffraction (XRD), transmission electron microscopy (TEM), X-ray photoelectron spectroscopy (XPS), Raman spectroscopy, UV–visible spectroscopy, and Vibrating sample magnetometer (VSM). The XRD patterns confirmed the monoclinic structure with the successful incorporation of Cu2+ ions by Mg2+ dopants, without the formation of any secondary phases. Additionally, several structural parameters were extracted from the XRD analysis, and listed in Table 2. The slight variations of the lattice parameters a, b, and c, the cell volume V, and the cell angle \({\beta }_{L}\) were linked to the almost matching ionic radii of the dopant Mg2+ ions (Mg2+: 0.072 nm) and the native Cu2+ ions (Cu2+: 0.073 nm). However, Mg2+ ions have affected the crystallite size by raising it by a factor of 20%, and reducing the agglomeration of the spherical particles, as detected by TEM images. Moreover, the Mg2+ ions have altered the surface stoichiometry of CuO nanoparticles, by which it generated more oxygen vacancies, which were perceived by XPS investigation. The Raman spectroscopy unveiled the existence of the three active Raman modes in CuO nanoparticles, in the range 277, 331, and 610 cm−1. The Mg2+ ions have affected the Raman spectra of Mg-doped CuO nanoparticles by shifting the peaks to higher wavenumber and intensifying their heights, due to quantum confinement effects. All the samples demonstrated high absorbance in the UV range, a peak around 244-247 nm, and less absorbance in the visible region. Further, the band gap energy was tailored by changing the concentration of the dopant, as seen in Table 2. These variations were allocated to the change in the crystallite size, following quantum confinement effects. Besides, all the samples demonstrated combined paramagnetic and weak ferromagnetic behaviors, with reduced coercivity and retentivity by means of Mg2+ dopants, as shown in Table 1. Additionally, the saturation magnetization was determined by several methods, including the law of approach-to-saturation, and the ferromagnetic contribution. It was registered that the non-magnetic Mg2+ dopants have reduced the saturation magnetization with x = 0.015, then it increased with higher concentration (x = 0.020), as listed in Table 1. This enhancement was mainly attributed to the increase in the crystallite size.

Table 1 Structural, optical, and magnetic parameters of pure and Mg-doped CuO nanoparticles

3 Anti-Corrosion Behavior of the Pure and Mg-doped CuO Nanoparticles in HCl and H2SO4 Solutions

3.1 Open Circuit Potential Measurements (OCP)

Open circuit potential (OCP), also known as open-circuit voltage, zero-current potential, corrosion potential, equilibrium potential, or rest potential, is a passive approach. It is frequently used to determine a system’s resting potential, which serves as the foundation for future studies. The variation of OCP with exposure time of the mild steel in both media (0.5 M HCl and H2SO4) in the absence and presence of 10 ppm of Mg-doped CuO nanoparticles, are shown in Fig. 1. As can be observed, after immersion, a steady potential related to the free corrosion of the mild steel in both acidic solutions, was easily reached. In the presence of 10 ppm of the doped nanoparticles, the steady-state potential was changed to positive values. This modification is a sign of these nanoparticles' impact on the anodic process and its capacity to prevent acid corrosion of mild steel [20].

Fig. 1
figure 1

Variation of open circuit potential as a function of time for mild steel in 0.5 M hydrochloric acid and sulfuric acid solutions in the absence and presence of 10 ppm of Mg-doped CuO nanoparticles at 30 °C

3.2 Potentiodynamic Polarization Measurements

Figure 2 a shows the potentiodynamic polarization curves for mild steel in 0.5 M hydrochloric acid solutions in the absence and the presence of 10 ppm of pure and Mg-doped CuO nanoparticles with the presence of 1% of sodium dodecyl sulfate (SDS). SDS was used as a potential electrostatic stabilizer to preserve the stable dispersion of the nanoparticles on the surface. The presence of SDS claimed the successful formation of an adsorption layer on mild steel [7]. Both the cathodic and anodic branches of the polarization curves showed an active response with the corrosion current density, \({i}_{corr}\), determined by Tafel extrapolation. Where the anodic part includes the mild steel dissolution, and the cathodic part represents the hydrogen evolution processes. Consequently, these nanoparticles behave as mixed-type inhibitors in both media (hydrochloric acid and sulfuric acid solutions). Since it both retarded the anodic and cathodic parts of the polarization curves, this demonstrated the existence of a protective layer on the mild steel surface with the presence of the prepared nanoparticles. Moreover, a similar observation was reported in 0.5 M sulfuric acid solution as shown in Fig. 2 b. Where also, the presence of these nanoparticles retards both the anodic and cathodic branches of Tafel plots, claiming that they act as mixed-type inhibitors.

Fig. 2
figure 2

a Potentiodynamic polarization curves of mild steel in the absence and presence of 10 ppm of pure and Mg-doped CuO nanoparticles in 0.5 M hydrochloric acid solutions at 30 °C. b Potentiodynamic polarization curves of mild steel in the absence and presence of 10 ppm of pure and Mg-doped CuO nanoparticles in 0.5 M sulfuric acid solutions at 30 °C

The potentiodynamic polarization curves were analyzed to determine the polarization parameters, including the corrosion current density (\({i}_{corr})\), anodic and cathodic polarization slopes (\({\beta }_{a}\) and \({\beta }_{c}\)), and the corrosion potential (\({E}_{corr})\). Also, the percentage of corrosion inhibition (η) was calculated according to the following equation [3]:

$$\% \eta = \frac{i_0 - i}{{i_0 }} \times 100$$
(1)

where \({i}_{0}\) and \(i\) are the corrosion current densities in the absence and presence of these nanoparticles, respectively, these obtained data are listed in Table 2.

Table 2 Potentiodynamic polarization parameters of mild steel in 0.5 M hydrochloric acid and sulfuric acid solutions containing 10 ppm of pure and Mg-doped CuO nanoparticles at 30 °C

Table 2 illuminates that, upon increasing the Mg dopant concentration, the corrosion current density \({i}_{corr}\) decreases along with the increase in the values of inhibition efficiency \((\boldsymbol{\%}\eta )\). Hence, these nanoparticles are efficient corrosion inhibitors in 0.5 M hydrochloric acid and 0.5 M sulfuric acid solutions. Furthermore, the presence of these nanoparticles did a slight variation of \({E}_{corr}\) values, verifying that the pure and Mg-doped CuO nanoparticles act as pickling-type inhibitors [3]. The simple blocking of the anodic and cathodic sites on the surface of the mild steel was proved by the small variation of the anodic and cathodic polarization slopes (\({\beta }_{a}\) and \({\beta }_{c}\)) [21]. The kinetics of the corrosion reaction is linked to slopes \({\beta }_{a}\) and \({\beta }_{c}\) of the Tafel. The values of \({\beta }_{c}\) are around 126 mV and 85 mV in 0.5 M hydrochloric and sulfuric acid solutions, respectively, indicating a single electron exchange during the cathodic reaction. However, the values that are approximately 93 mV and 62 mV in 0.5 M hydrochloric and sulfuric acid solutions, respectively, indicate the exchange of two electrons throughout the metal dissolution process, by the simple blockage of the metal surface's available cathodic and/or anodic sites [21]. Potentiodynamic polarization data revealed that the corrosion inhibition efficiency of these nanoparticles reached 79 and 67% with x = 0.020 of Mg dopant concentration in 0.5 M hydrochloric acid and 0.5 M sulfuric acids, respectively. Consequently, the data reveals that the pure and Mg-doped CuO nanoparticles are more effective in 0.5 M hydrochloric acid than in 0.5 M sulfuric acid solutions.

3.3 Electrochemical Impedance Spectroscopy Studies (EIS)

The electrochemical impedance spectra are used to determine the anti-corrosion behavior of pure and Mg-doped CuO nanoparticles on mild steel in both media. Figure 3a and b show the electrochemical impedance spectra for mild steel in 0.5 M hydrochloric acid and sulfuric acid in the absence and presence of 10 ppm of pure and Mg-doped CuO nanoparticles in the addition to 1 g of SDS at 30°C. As observed, the impedance response consists of characteristic depressed semicircles of a capacitive type, indicating that the dissolution process took place under activation control and frequency dispersion due to surface roughness and inhomogeneity [22]. Upon increasing the Mg dopant concentration, the diameters of the semicircles increased. This can be explained based on the adsorption of Mg dopant on the mild steel surface producing a barrier, and this barrier increases with increasing the concentration. The corrosion mechanism remains the same in the presence and absence of the inhibitors, that was confirmed from the resemblance of the presented semicircles regardless of the presence of the inhibitor. The Nyquist plots were fitted and analyzed in terms of an equivalent circuit as represented in Fig. 4. The circuit comprised solution resistance (\({R}_{s}\)), connected in series to a charge transfer resistance \({(R}_{ct})\), which is in turn, connected in parallel to the constant phase element (CPE). The CPE consists of non-ideal double-layer capacitance \({(Q}_{dl})\) and constant \(\left(n\right)\),to compensate for non-homogeneity in the system. The electron transfer measure across the surface is measured through \({(R}_{ct})\) values. The corrosion inhibition efficiency (\(\%\eta )\) was calculated according to the following equation [3]:

$$\% \eta = \frac{{R_{ct} - R_{ct0} }}{{R_{ct} }} \times 100$$
(2)

where \({R}_{ct0}\) and \({R}_{ct}\) are the charge transfer resistances in the absence and presence of the nanoparticles, respectively. The electrochemical impedance parameters, along with the corrosion inhibition efficiencies (\(\%\eta )\) are listed in Table 3.

Fig. 3
figure 3

a Nyquist impedance plots of mild steel in the absence and presence of 10 ppm of pure and Mg-doped CuO nanoparticles and the inset shows the Nyquist plot for the blank solution in 0.5 M hydrochloric acid solutions at 30 °C. b Nyquist Impedance plots of mild steel in the absence and presence of 10 ppm of pure and Mg-doped CuO nanoparticles and the inset shows the Nyquist plot for the blank solution in 0.5 M sulfuric acid solutions at 30 °C

Fig. 4
figure 4

Schematic for the equivalent circuit

Table 3 Electrochemical impedance parameters of mild steel in 0.5 M hydrochloric acid and sulfuric acid, containing 10 ppm of pure and Mg-doped CuO nanoparticles at 30°C

The presence of these nanoparticles causes an increase in \({R}_{ct}\) values from 10.85 to 42.53 Ω cm2 and from 11.23 to 37.13 Ω cm2 in 0.5 M HCl and H2SO4 solutions, respectively. This increase caused a decrease in the corrosion process. The corrosion rate (\({C}_{R})\) values were calculated from the reciprocal of the charge transfer resistance values [23]. Also, the Mg-doping cause an overall decrease in the \({Q}_{dl}\) values as well as in the corrosion rate (\({C}_{R})\) values, indicating the successful adsorption of the nanoparticles on the mild steel surface in both media (0.5 M HCl and H2SO4 solutions) [23]. The inhibition efficiencies (\(\%\eta\)) estimated from EIS are comparable to those calculated previously from potentiodynamic polarization curves as shown in Fig. 5. The corrosion inhibition efficiency reached its maximum and the corrosion rate reached its minimum with the highest Mg dopant concentration (x = 0.020) with 75 and 70% in hydrochloric acid and sulfuric acid, respectively. Furthermore, the EIS data reveal that the Mg-doped CuO nanoparticles enhanced the corrosion protection of mild steel in 0.5 M hydrochloric acid as compared with the results of 0.5 M sulfuric acid solutions.

Fig. 5
figure 5

Polarization and EIS inhibition % (\(\%\eta )\) in 0.5 M hydrochloric acid and sulfuric acid, containing 10 ppm of pure and Mg-doped CuO nanoparticles at 30°C

Furthermore, Table 4 compares the anti-corrosion behavior of some pure and doped CuO nanoparticles with the present study. Deepa et al. [15] prepared Mn-doped CuO nanoparticles that improved a superior anti-corrosive performance of zinc fabricated composite in 3.5% NaCl solutions. Also, Zn-doped CuO nanoparticles acted as mixed-type inhibitors that inhibited both the anodic and cathodic reactions of the corrosion process with 83% corrosion inhibition on mild steel in 0.5 M HCl solutions [24]. In addition, the green synthesized CuO acted as a potential corrosion inhibitor with 58.15% efficiency on Ti-6Al-4V dental alloy [25]. Surendhiran et al. [26] reported that the green synthesized CuO nanoparticles had shown an effective anti-corrosive behavior with 53.57% of mild steel in 3.5% NaCl solutions. For this, it is the first time to synthesize Mg-doped CuO nanoparticles and be used as corrosion inhibitors in different media as in the present study, where they inhibited corrosion successfully with 75% and 70% in 0.5 M HCl and H2SO4 solutions, respectively.

Table 4 Literature comparing the anti-corrosion behavior of some pure and doped CuO nanoparticles

3.4 Standard Free energy (\({\varvec{\Delta}}{\mathbf{G}}_{\mathbf{a}\mathbf{d}\mathbf{s}}^{0}\)) Measurements and Suggested Inhibition Mechanism

The standard free energies (\(\Delta {\mathrm{G}}_{\mathrm{ads}}^{0}\)) of adsorption of the nanoparticles on the mild steel surface in both media (0.5 M HCl and 0.5 M H2SO4) were studied using the following equation [27, 28]:

$$K_{{\text{ads}}} = \frac{1}{55.5} e^{\frac{{ - \Delta G_{{\text{ads}}}^0 }}{{{\text{RT}}}}}$$
(3)

where \({K}_{ads}\) is the equilibrium constant for the adsorption–desorption process, 55.5 is the molar concertation of water in mol/L, R is the gas constant, and T is the absolute temperature in Kelvin.\({K}_{ads}\) values were calculated according to the following relation [27, 28]:

$$\frac{{C_{{\text{inh}}} }}{\theta } = \frac{1}{{K_{{\text{ads}}} }} + C_{{\text{inh}}}$$
(4)

where \({C}_{inh}\) is the inhibitor concertation, i.e., the nanoparticles concertation, \(\theta\) is the surface coverage ratio that was calculated according to the following equation:

$$\theta = \frac{\% \eta }{{100}}$$
(5)

such as \(\%\eta\) is the inhibition efficiency of these nanoparticles that was calculated before.

The effectiveness of the Mg-doped CuO nanoparticles is also dependent on the magnitude of its binding constant \({K}_{ads}\). Low values of \({K}_{ads}\) are a clear sign that the contact between these nanoparticles and mild steel is poor, whereas the high values denote a stronger and better interaction [28]. In contrast, the \({K}_{ads}\) value in HCl solution (2.38 × 104 M−1) is higher than that in H2SO4 solution (1.85 × 104 M−1). This might be attributed to the basis of these nanoparticles adsorption on the whole surface, while in H2SO4 solution, it happens on the exposed (the bare) mild steel surface [3]. The calculated \(\Delta {\mathrm{G}}_{\mathrm{ads}}^{0}\) values were -35.50 kJ/mol and -34.87 kJ/mol for the nanoparticles in 0.5 M HCl and H2SO4 solutions, respectively. These values support the adsorption process spontaneity as well as the layers of the adsorbed nanoparticles' stability on the mild steel surface in both corrosive media. Additionally, this adsorption is a complex adsorption mechanism (physicochemical adsorption), not just a simple physisorption or chemisorption process [3, 28].

It is possible to attribute the 10 ppm of pure and Mg-doped CuO nanoparticles' inhibitory impact to the metallic cations adsorption reaction on the mild steel surface. It was discovered that these nanoparticles improved the mild steel corrosion resistance in acidic media (HCl and H2SO4 solutions). Such behavior is explained in light of the typical oxidation potential of the various metals present in the nanoparticles. Revealing the ability of Mg2+ ions to deposit onto the mild steel surface, where it has a positive charge in acidic media. Therefore, the guest ions will deposit through a closed-packed triple layer in which the negative (chloride or sulfate ions) will be first adsorbed, followed by the Mg2+ ions through a physicochemical adsorption [7, 29].

3.5 Surface and Raman Spectra Investigations

The mild steel surface characterization was studied before and after its immersion in the corrosive media (0.5 M HCl and 0.5 M H2SO4) with the absence and presence of pure and Mg-doped CuO nanoparticles, as shown in Figs. 6 and 7. In addition, the Raman spectra were studied and collected in the two corrosive media (0.5 M HCl and 0.5 M H2SO4), to identify the main phases present in the corrosion films.

Fig. 6
figure 6

ad Optical images and e Raman spectra of mild steel with the absence and presence of pure and Mg-doped CuO nanoparticles (x = 0.000 and x = 0.020) in 0.5 M HCl

Fig. 7
figure 7

ad Optical images and e Raman spectra of mild steel with the absence and presence of the pure and Mg-doped CuO nanoparticles (x = 0.000 and x = 0.020 doped samples) in 0.5 M H2SO4

Figure 6a shows a clear surface for the clean mild steel with some scratches that are attributed to the cleaning process. Upon immersion of the mild steel in the corrosive media of 0.5 M HCl, corrosion layer was observed clearly due to the presence of chloride ions (Fig. 6b). Consequently, the dissolution process of the mild steel transpired, where the surface was clearly observed etched and damaged.

For the blank solution, the peaks at 217, 283, and 1305 cm−1 are associated with the main peak of iron oxides, the hematite (α-Fe2O3) phase as represented in Fig. 6e and Table 5 [8]. The identification of the goethite (α-FeOOH) is obvious with the very narrow 393 cm−1 peak [8]. The maghemite (γ-1 Fe2O3) is produced with the present peaks at 496 and 693 cm−1 as demonstrated in Table 4 [30]. The green rust is assigned with the peaks present at 583 cm−1 (Table 5) [30]. The green rust had been organized as a function of the additional ions, i.e., chloride ions. However, the presence of the prepared nanoparticles as corrosion inhibitors made an adsorption layer on the surface as present in Fig. 6b. This assures that the corrosion inhibition process occurred. Furthermore, the presence of Mg-dopant shows a higher inhibition effect compared with the pure sample, where a strong inhibition layer was created on the mild steel surface. The Mg-doped sample constructs an outer inhibition layer and surface boundary on the metal. In addition, the adsorption of the nanoparticles onto the surface is verified by several peaks in the Raman spectra of the mild steel immersed in the inhibited solution by the presence of the prepared nanoparticles, as mentioned in Table 4. These peaks in Fig. 6c and d became sharper with higher intensity, as compared to the uninhibited surface. This might be assigned to the large surface area of the nanoparticles that dispense more on the mild steel surface, clarifying the corrosion inhibition. Accordingly, the corrosion products are hindered by the presence of the nanoparticles, where they form an inhibition layer. Such bands demonstrated substantial surface adsorption and the subsequent polymerization of the nanoparticles. Furthermore, in 0.5 M H2SO4 solutions, the corrosion and etched layer was presented in the blank solution where the presence of sulfate ions did these etching and damage to the surface, as shown in Fig. 7b. The corrosion products obtained are the same as that obtained in HCl solution. All the Raman peaks are demonstrated in Table 5. The hematite (α-Fe2O3), goethite (α-FeOOH), maghemite (γ-1 Fe2O3), and green rust are associated with the peaks present at (215, 275, and 1292 cm−1), (390 cm−1), (487 cm−1), and (580 cm−1), respectively, as represented in Table 5 and Fig. 7e [30]. Moreover, the addition of the pure and Mg-doped CuO nanoparticles significantly improved the mild steel surface, where a barrier film was formed, due to the adsorption of these nanoparticles as shown in Fig. 7c and d.After the addition of the nanoparticles to these solutions, the peaks became sharper with higher intensity. Consequently, the adsorption of the nanoparticles onto the surface is confirmed by shifting these peaks, as shown in Fig. 7e [13].

Table 5 Raman peak assignments in 0.5 M HCl and H2SO4 solutions

Furthermore, map scan analysis was used in this study to generate kinetic profiles from analysis of intensity valued from confocal line scans. This part was done to maximize sensitivity and fit into tight spaces. It is also used to configure the depth analysis of the highest Raman peaks and the main corrosion products present in these samples before and after corrosion inhibition, using the prepared nanoparticles in both media (0.5 M HCl and 0.5 M H2SO4). The main presented peaks (215, 285, and 1295 cm−1) were studied as shown in Fig. 8 in both media. As mentioned before, these peaks belong to hematite (α-Fe2O3) product. Starting with HCl medium, their intensity at the beginning was small, then, it increased in the depth range between 6 and 9 µm in the blank solution (Fig. 8a). This means that the corrosion process occurs at this level, where these products are present in high amount. The peak at 1295 cm−1 has the highest intensity compared to the other peaks, indicating that it is the dominant peak. Beyond 9 µm, the intensity of all the peaks decreased, indicating the reduction on the corrosion process. On the other hand, the intensity of these peaks increased highly upon the addition of the pure and Mg-doped CuO nanoparticles (x = 0.000 and 0.020) to the solutions, compared with the blank solution, in the depth range between 4 and 7 µm and between 6 and 9 µm, respectively, as shown in Fig. 8b and c. This confirms that the inhibition layer is successfully formed by the nanoparticles on the mild steel surface. Thus, they hinder, with their higher percentages, the corrosion process at this depth successfully. As more depth was investigated, the corrosion is inhibited highly and the mild steel is being protected perfectly. Also for the other media (in 0.5 M H2SO4), the map scan analysis is studied. A similar manner is obtained in the blank solution (0.5 M H2SO4) compared with that of 0.5 M of HCl solution, as presented in Fig. 8d. These peaks are strongly visible in the same depth range (6 and 9 µm). However, the addition of pure and Mg-doped CuO nanoparticles vastly affected their intensities, as they extensively increased, compared with 0.5 M HCl solutions. But in this case, the peak at 215 cm−1 is the prevalent one, that presented with highest intensity. Moreover, these nanoparticles slow down the corrosion process on the mild steel surface, having high rate in the range of 6 and 9 µm as a depth level, as shown in Fig. 8e and f.

Fig. 8
figure 8

af Map scan depth analysis of the highest Raman peaks present before and after corrosion inhibition in both media (0.5 M HCl and 0.5 M H2SO4). Each color is assigned to averaged spectra of each peak

4 Conclusion

This work demonstrated that the pure and Mg-doped CuO nanoparticles act as potential corrosion inhibitors. These nanoparticles displayed an anti-corrosive behavior under 0.5 M hydrochloric and 0.5 M sulfuric acids solutions on pitting corrosion for mild steel. The mild steel corrosion was inhibited by up to 75% and 70% in 0.5 M hydrochloric and sulfuric acids, respectively. As confirmed from Tafel plots, they served as mixed-type inhibitors in both media, where the dissolution process occurred under activation control. Also, they behaved as pickling-type inhibitors, where they did not affect the potential corrosion as proved from EIS results. Moreover, the prepared nanoparticles were more effective in HCl than in H2SO4 solutions, where the Mg-doping (x = 0.020 sample) give the highest inhibitory effect in both media. The Raman analysis of the prepared nanoparticles provided the characteristic functional groups of Mg-doped CuO nanoparticles. Furthermore, the mild steel surface studies confirmed the formation of a protective barrier against the corrosive environment upon the addition of the prepared nanoparticles. This barrier prevented the corrosion process by blocking the reaction between the mild steel and the acidic media. Also, the corrosion products were identified by Raman spectra in both media, where hematite, goethite, maghemite and green rust were detected and analyzed. These nanoparticles retarded the mild steel corrosion with the highest rate between 6 and 9 µm as a depth level.