# Design of a Partially Grid-Connected Photovoltaic Microgrid Using IoT Technology
## 3 Microgrid Modeling and Design
### Smart Meters  
Smart metering aims to provide effective and continuous monitoring of resource usage, and it sends the collected data to the Internet or local server through IoT technology. Smart meters are the most common name for these metering devices. While there is a wide range of devices on the market today, the most difficult part is integrating them into a useful smart metering solution for a specific application. The IoT-based smart meter should be able to accommodate all smart meter features in near real-time in addition to guaranteeing two-way communication with a sample rate of roughly 1 s. In residential load demand settings, two types of electric loads are commonly used: linear and non-linear loads. The present design of the smart meter accounts only for monitoring residential linear loads (lighting, refrigerator, air conditioner, fan, heater, etc.). The expressions for voltage and current in the AC time domain can be represented by the following equations:  
\[V(t)=V_{m}cos(\omega t) \tag{29}\]  
and  
\[I(t)=I_{m}cos(\omega t+\theta) \tag{30}\]  
Figure 10: Schematic diagram of SSTS.  
where \(V_{m}\) denotes the maximum voltage amplitude and \(\omega\) denotes the voltage's angular frequency, which should be fixed by the utility provider. \(I_{m}\) is the current amplitude, and \(\theta\) is the phase angle between the voltage and current. The apparent power (\(S\)) can be calculated using the root-mean square (\(rms\)) values of the voltage and current as follows:  
\[S=V_{rms}I_{rms} \tag{31}\]  
The rms values of the current and voltage can be estimated after the instantaneous values of the current and voltage have been collected, using discretization techniques:  
\[V_{rms}=\sqrt{\frac{1}{N}\sum_{n=1}^{N}v_{n}^{2}}\ \ \text{and}\ \ \ \ \ \ I_{rms}=\sqrt{\frac{1}{N}\sum_{n=1}^{N}i_{n}^{2}} \tag{32}\]  
where \(N\) denotes the sample size of the discrete voltage and current values \(v_{n}\) and \(i_{n}\), respectively. On the other hand, the real power (\(P\)) is simply the average value of the multiplied discrete values of the voltage and current:  
\[P=\frac{1}{N}\sum_{n=1}^{N}v_{n}i_{n} \tag{33}\]  
Therefore, the power factor (\(PF\)) is obtained by:  
\[PF=cos(\theta)=\frac{P}{S} \tag{34}\]  
The reactive power (\(Q\)) is calculated by:  
\[Q=S\times sin(\theta)=\sqrt{S^{2}-P^{2}} \tag{35}\]  
Figure 11a illustrates the prototype design of the smart meter, which was implemented using ZMPT101B voltage sensor and ACS712-30A current sensor. Microcontroller (ATmega328) and microcomputer (Raspberry Pi 3 model B) devices each equipped with XBEE-S1C module, using ZigBee communication protocol, were set up to transmit the measured data to an IoT server. The Raspberry Pi 3 model B was chosen here because of its features, which include a quad-core 64-bit ARM Cortex-A53 clocked at 1.2 GHz along with 1 GB RAM. Moreover, it is equipped with graphics capabilities provided by its GPU VideoCore IV. Regarding its compact size, ease of configuration, low cost, high speed, and low power consumption, which makes it is suitable for many IoT applications and prototyping. More recently, Pi 4 model with 8 GB RAM is also available with improved capability and reliability. The metering data were saved and pre-processed at the edge before being uploaded to an application operating on a cloud middleware platform (Blynk IoT). The platform has all the needed functions to remotely manage IoT devices such as provisioning, over-the-air firmware update, secure data storage, data analytics, and visualization. Blynk supports many hardware devices including Arduino and Raspberry Pi. We used the Blynk mobile application to display the manipulated data for consumer load profiling, energy demand, and appliance remote control in the dashboard shown in Figure 11b. The data collected by the meter are represented by 10-bit accuracy and sent a reading every 1 s. The results of measuring and assessing the data transmission bit rate of the designed smart meter are displayed and discussed in Section 5.