*3.3. Control System*

At first level, the embedded control system is based on a S7-1200 PLC which controls solar emulator and relays. This allows experimental tests to be carried out according to real-time weather data or with historical data.

At the second level, the overall control of the PV system is performed within MATLAB Simulink programs using the embedded PLC as a slave. Data communication is carried out using OPC-UA and Industrial Communication Toolbox™.

Figure 4 describes the unified architecture proposed in this work.

**Figure 4.** Digital Twin architecture overview.

#### **4. PV System Modeling**

This section details our approach to modeling the PV system. The aim is to develop the digital replica counterpart of the Digital Twin.

#### *4.1. Solar Panels*

A photovoltaic (PV) power system consists of two solar panels (SPR-215-WHT). PV parameters of each panel are given in Table 2.


**Table 2.** Parameters of the SPR-215-WHT solar panel at STC form datasheet.

PV panel is composed of several cells. Each PV cell is made up of semiconductor materials which can convert solar irradiance into electrical energy. Based on the electronics theory of semiconductor p-n junction, it can be described by a current source. The studied panel model in this work is represented by an equivalent circuit. It consists of a single diode for the cell polarization function and two resistors (series and shunt) for the losses (Figure 5). The equivalent circuit is composed of an ideal current source *Iph* in parallel, reverse diode, series resistance *Rs* and parallel resistance *Rsh*.

**Figure 5.** Equivalent circuit model. (**a**) PV cell; (**b**) PV panel composed of *ns* cells in series.

The *Ipv* = *f* - *Vpv* characteristic of this model is given by the following equation:

$$I\_{\rm p\upsilon} = I\_{\rm p\text{h}} - I\_D - \left(\frac{V\_{\rm p\upsilon} + R\_s I\_{\rm p\upsilon}}{R\_{sh}}\right) \tag{1}$$

where:


$$I\_{ph} = (I\_{phn} + \alpha\_{sc} \Delta T) \frac{G}{G\_{nl}}$$


$$I\_D = I\_0[\exp\left(\frac{qV\_{pv}}{AKT}\right) - 1] \tag{2}$$

 where: *I*<sup>0</sup> is the PV cell reverse saturation current that mainly depends on the temperature, q is the electronic charge of an electron (1.6 × <sup>10</sup><sup>19</sup> C), *<sup>T</sup>* is the temperature of the PV cell, *<sup>k</sup>* is Boltzmann's constant (1.38 × <sup>10</sup><sup>23</sup> J/K), and A is the diode ideality factor.

A PV panel is made up of numerous identical PV cells connected in series to provide a higher voltage. A PV module composed of *ns* identical cells in series can also be represented by the equivalent circuit shown Figure 4a but the circuit needs to be modified [43] as follows (Figure 5b):

$$R\_{\rm s\\_ns} = n\_{\rm s} R\_{\rm s\nu} \ R\_{\rm s\underline{h}\\_ns} = n\_{\rm s} R\_{\rm s\underline{h}\prime} \ A\_{\rm ns} = n\_{\rm s} n\_{\rm \nu} \ I\_{0\\_ns} = I\_{0\prime} \ I\_{\rm p\underline{h}\\_ns} = I\_{\rm p\underline{h}} \tag{3}$$

The solar panel datasheet does not include some important parameters, such as *Rs* and *Rsh*. To obtain them, we used the PV array tool of Matlab by setting the PV parameters of the studied solar panel. Table 3 shows the extracted parameters.

**Table 3.** Parameters of the SPR-215-WHT solar panel at STC form datasheet.


The mathematical model of the studied solar panel is then implemented under MAT-LAB Simulink and the results are compared to datasheet data as shown in Figure 6.

**Figure 6.** Actual data vs. data computed by the model: (**a**) I-V characteristics from datasheet; (**b**) actual I-V characteristics vs. computed I-V characteristics; (**c**) actual P-V characteristics vs. computed P-V characteristics.

The dotted curves in Figure 5 represent data from the datasheet and the continuous ones come from the mathematical model. These results show a good correlation between the model and the solar panel manufacturer's data.

To assess the model's effectiveness, we conducted indoor tests of the PV panel. The PV panel was illuminated using an artificial light source, while its output was connected to a rheostat. To obtain the I-V curves, measuring instruments were integrated, as depicted in Figure 7a.

**Figure 7.** Experimental test and comparison of I-V curves: (**a**) experimental components of the tested PV panel; (**b**) comparison between real test and the mathematical model.

Figure 7b shows the simulation and experimental results, confirming the accuracy of the implemented mathematical model.

## *4.2. Batteries Bank*

Due to the inherent variability of PV power, the battery plays a crucial role in standalone PV systems. In this system, two 12 V AGM batteries are installed and connected in a series configuration. The utilization of AGM batteries provides additional benefits, as they facilitate recombination and effectively mitigate gas emissions during overcharge. Consequently, the demand for room ventilation is reduced, and the batteries do not emit any acid fumes during normal discharge operations [44].

The battery model in Figure 8 considers a constant internal resistance. This resistance is connected in series with the internal voltage source which depends on various parameters [45].

**Figure 8.** Nonlinear Battery model.

The terminal voltage of the battery is given by:

$$V\_{\text{bat}} = E - RI\_{\text{bat}}(t) \tag{4}$$

where:


The controlled voltage source *E* is described by the following equation:

$$E = E\_0 - K \frac{Q}{Q - \int I\_{bat}(t)dt} + A \exp(-B \int I\_{bat}(t)dt) \tag{5}$$

where:


The parameters of this equivalent circuit can be identified by considering the discharge characteristics with a nominal current.

We use a lead-acid battery, which features a nominal voltage of 12 volts (*E*0), a capacity of 14 Ah (*Q*), a rated current of 0.7 A, and an internal resistance of 14 mΩ (Table 4).

**Table 4.** Parameters of an AGM battery from datasheet.


The model parameters (K = 0.12, A = 0.66, B = 7) are obtained through graphical estimation based on the rated current discharge characteristic curve. The simulation results are depicted in Figure 9. The Q-V discharge curve is composed of three sections. The first section represents the exponential voltage drop if the battery is initially fully charged. The second phase represents the charge that can be extracted from the battery until the voltage drops below the battery nominal voltage. Finally, the third section represents the total discharge of the battery, when the voltage drops quickly. The width of these sections depends on the battery type.

**Figure 9.** (**a**) Discharge curve (Q-V); (**b**) Discharge curve (Hours-V).

To estimate the state of charge of the battery (SoC), the well-known Coulomb counting method is used due to its simplicity. It relies on measuring the current and the estimation of the initial state of charge of the battery.

$$So\mathbb{C}(t) = SoC\_0 - \frac{1}{\mathbb{C}\_{nom}} \int\_{t\_0}^{t} i\_{batt}(t)dt \,\*\,100\tag{6}$$

### *4.3. Power Electronics*

Figure 10 illustrates the simplified PV system architecture, comprising a solar panel, a battery for energy backup, and power converters (MPPT regulator) that connect these components to the DC load.

**Figure 10.** Simplified PV system architecture.

We determined the converter topology based on the current state of the art since it was not specified by the manufacturer. Photovoltaic energy harvesting relies primarily on irradiance and solar panel temperature, resulting in variable PV voltage. Therefore, implementing Maximum Power Point Tracking (MPPT) is essential to maximize power extraction regardless of weather conditions. A DC-DC converter is used to enable voltage adjustment from the photovoltaic panels to match the battery voltage. This converter performs step-up and step-down functions by controlling the input-to-output voltage ratio through the variation of the converter switching device's on-off duty cycle. Another converter is required to supply and regulate the voltage for the DC load. In the literature, this configuration is commonly referred to as a two-stage DC-DC converter (Figure 11), as reported in [46].

**Figure 11.** Topology of stand-alone hybrid PV system.

#### *4.4. EMR Representation of the Digital Replica*

In the proposed system, the battery imposes a constant voltage, and the PVs relates to the battery through the buck converter. It enables effective Maximum Power Point Tracking (MPPT) control for the PV panels. Moreover, RC (*Rcpv*, *Cpv*) and RL (*Rlpv*, *Lpv*) filters are inserted between the PV and the buck converter to reduce voltage and current ripple. Finally, the battery is connected with the DC Load via a chopper and a RL (*Rldc*, *Ldc*) filter.

EMR (Energetic Macroscopic Representation) is a graphical formalism for organizing models and control of subsystems within a complete system [47]. The advantage of the EMR formalism lies in its ability to provide a comprehensive and systematic approach for modeling and analyzing complex energy systems. Firstly, each component is translated into EMR elements, and their inputs and outputs are defined according to the causality principle (action/reaction). Moreover, the system is decomposed into basic subsystems with interactions using colored pictograms (orange and green). Furthermore, the control blocks are depicted as blue parallelograms. Table 5 depicts the main EMR elements.

**Table 5.** Some elements of EMR and of control pictograms [48].


Based on the information on all parts of the demonstrator and hypothesis, the EMR (Energetic Macroscopic Representation) of the studied system is designed. The modeling methodology and the EMR organization method are provided in [49]. In Figure 12, the entire EMR organization of the Digital model is depicted.

The control chains are deduced using inversion control theory [50] where the control structure of a system is considered as an inverse model of the system (Figure 13).

**Figure 13.** Inversion-based control principle.

The tuning paths (yellow lines in Figure 14) are defined according to the following objectives:


The control scheme of the hybrid system is obtained by inverting the EMR element by element according to the tuning chains (see lower part of Figure 14).

Conversion elements are inverted directly as they have no time-dependence behavior. The accumulation elements (rectangle with forward slash) cannot be inverted physically to avoid derivation. Thus, an indirect inversion is made by using IP controller. Table 6 shows three examples of direct and indirect inversion.

**Figure 14.** EMR and deduced control of the studied hybrid system.


**Table 6.** Direct and indirect inversion of EMR blocks.

The MPPT (Maximum Power Point Tracking) algorithm is widely used in PV systems. In this study, the Perturb and Observe (P&O) method is implemented. As shown in Figure 15a, the power curves versus the PV panels output voltage present maximum power points (empty circles). A Perturb and Observe Maximum Power Point Tracking strategy [51] is implemented to define the reference voltage imposed on PV panels to obtain the maximal

PV power whatever the irradiance and temperature are (Figure 15b). The P&O algorithm begins by sensing PV voltage and current voltage. The value of the current power (V(k) X I(k)) is then compared to the previous power measurements. If the difference between the two measurements is equal to zero, then the value of the voltage is used as a reference to control the PV voltage thanks to the chopper. If the value of the difference is not equal to zero and if an increase in PV voltage generates an increase in power, this means that there is a convergence to MPP (Maximum Power Point). However, if the power decreases, the PV voltage reference must be reduced to converge to the MPP. The developed algorithm is implemented by the MPPT strategy block (dark blue block) as shown in Figure 15a.

**Figure 15.** (**a**) PV Power versus solar panel voltage for different irradiance (T = 25◦) (**b**) Flowchart of perturb and observe algorithm.

The following figure (Figure 16) presents the implemented digital model under MAT-LAB Simulink thanks to a Simulink library containing the EMR basic pictograms.

**Figure 16.** MATLAB Simulink model of the studied hybrid system and its control.

To evaluate the effectiveness of the developed digital model, simulations have been carried out with real-time solar irradiance and temperature data (Figure 17a) for a typical day (30 June 2022). The digital model can be run and connected to real time weather conditions thanks to Simulink Desktop Real Time. This latter provides a real-time kernel for executing Simulink models on a laptop or desktop running Windows or Mac OS X.

**Figure 17.** (**a**) Monitored irradiance and temperature profiles; (**b**) PV, battery, and load power curves.

Figure 17b shows simulation results of *Ppv*, *Pbat*, *PDCl*. PV panels cannot provide enough energy to feed the DC load (*Ppv* < *PDCl* = 10 W) before the time 0.1 s, 6:30 a.m. Thus, the battery provides the DC load during this period. After 6:30 a.m., the photovoltaic panels begin to produce electricity and the battery provides the difference to satisfy the battery. When PV power exceeds the load demand, the battery is charging.

Figure 18a shows simulation results for *Ipv*, *Ibat*, *IDCl* while Figure 18b shows the state of charge of the battery. The battery is discharging when PV panels output is insufficient, and it is charging when PV power is higher than DC load demand.

**Figure 18.** (**a**) PV, Battery, and DC load currents; (**b**) Battery state of charge.

#### **5. Experimental Results and Discussion**

Real-time measurements were carried out to show the effectiveness of the proposed unified framework, where the three electromagnetic relays are activated. These measurements are subsequently compared in real time with the digital model data, as outlined in Figure 1.

The applied solar irradiance is presented in Figure 19. From the figure, we can see that the artificial source causes a slight delay and behaves like a first-order system with non-linear behavior depending on the increase or decrease in light. This is due to the light dimmer.

**Figure 19.** Applied solar irradiance (artificial light source).

Figure 20 represents the measured PV current and the PV numerical model, highlighting a slight deviation observed in the illumination levels around 300 W/m2. This difference is due to both the approximation of the mathematical model and the non-uniform illumination of the PV panels. Furthermore, it should be noted that the maximum relative error is approximately 6%, and the maximum absolute error is around 0.1, which is considered low.

**Figure 20.** Digital model PV current vs measured PV current.

In Figure 21, the measured and digital model load currents are depicted. The tests were initiated by activating a single lamp and subsequently both lamps. This led to an increase in the DC current from 0.23 A to 0.46 A.

**Figure 21.** Digital model vs measured load currents.

Measured and digital model battery currents are depicted in Figure 22. A positive current refers to a battery discharge, while a negative current refers to the charging phase.

**Figure 22.** Digital model battery current vs measured battery current.

Figure 23 represents PV power, battery power and DC load power, respectively. From 0 to 50 s, the demanded power is higher than the PV power. The battery is then in discharging mode. However, when the PV power is higher than the demanded DC power, the battery is charging. The comparison between real data and the digital model data shows a good correlation between them. Indeed, the maximum relative deviations between the real and digital model data are 8% for PV power, 12% for battery power, and 2% for load power.

**Figure 23.** Digital model data vs measured PV, battery, and load power.

To establish a feedback loop between the virtual and real word of the digital twin, we implement an energy management algorithm in MATLAB Simulink. The rule-based energy management algorithm sends control signals to the PLC (s7 1200). The advantage of using a rule-based control approach is its ease of implementation in real-time [52]. The flowchart of the energy management algorithm is illustrated in Figure 24. It receives measurement data as inputs and generates relay control signals as outputs, which are subsequently transmitted to the PLC.

**Figure 24.** Rule-based algorithm flowchart.

The energy management system generates five different modes. They are described in Table 7.


**Table 7.** Different modes of the energy management system.

To assess the effectiveness of the energy management system, the initial load is set to 112 W. Figure 25 displays the recorded external solar irradiance for a one-hour period on a cloudy day. Subsequently, these data are transmitted to the dimmer, enabling the generation of adjustable artificial lighting.

**Figure 25.** Measured irradiance.

Initially, the total power required by the load is provided by both the battery and solar power sources, as the PV alone cannot fully support the load (Figure 26). During the period from 0 to 757 s, the system operates in mode II.

**Figure 26.** Measured PV, battery, and load power.

Between 757 s and 876 s, as well as from 932 s to 1317 s, the solar irradiance remains below 50 W/m2, leading the system to switch to mode V (system OFF). From 1317 s to 3508 s, the system once again operates in mode II. During the period from 3508 s to 3600 s, the load demand gradually decreases from 111 W to 60 W, causing the battery to generate less power to meet the load requirements.

Figure 27a shows the battery voltage waveform, while Figure 27b displays the battery State of Charge. The battery primarily operates in discharging mode, except during periods when the system is not in operation (mode I).

**Figure 27.** (**a**) Battery voltage; (**b**) Battery state of charge.

#### **6. Conclusions**

In this work, we discussed the challenges of implementing IoT in renewable energy systems and the potential of digital twins for predicting energy production and consumption. We proposed a framework that combines the use of Internet of Things (IoT) and Digital Twin (DT) technologies for standalone photovoltaic systems. The digital twin is defined as the combination of the physical system and its digital model, allowing for

bidirectional data communication. Furthermore, we designed a digital model of the PV system by using Energetic Macroscopic Representation formalism. Experiments performed in real time and their analysis demonstrate the effectiveness of the proposed framework. As future work, we plan to use this platform to explore machine learning's potential to enhance energy management of PV systems.

**Author Contributions:** Conceptualization, L.C. and A.S.; Formal analysis, L.C., A.S. and A.R.; Methodology, L.C.; Investigation, L.C., A.S. and A.R.; Software, L.C. and A.S.; Supervision, L.C.; Writing—original draft, L.C.; Experimental tests, L.C., Writing—review and editing, L.C., A.S. and A.R. All authors have read and agreed to the published version of the manuscript.

**Funding:** This research received no external funding.

**Institutional Review Board Statement:** Not applicable.

**Informed Consent Statement:** Not applicable.

**Conflicts of Interest:** The authors declare no conflict of interest.

#### **References**


**Disclaimer/Publisher's Note:** The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
