# Smart Internet of Things Power Meter for Industrial and Domestic Applications
## 3 Proposed Solution
### Software Architecture
#### 3.2.2 Calibration Procedure and Measured Value Calculation
To keep the load current stable during the calibration, we connected several incandescent light bulbs with different power ratings (40 W, 100 W, 200 W) and a 2500 W radiator, obtaining different load currents. The calibration setup is presented in Figure 4.  
Using this setup, we applied a two-point calibration method for the voltage and current measurements. This method involves conducting two sets of measurements at different points using the device to be calibrated and another already calibrated device, serving as a reference [33; 34; 35; 36; 37]. We can establish a linear relationship between two known points, which can be correlated with (1). \[y=m\times x+b \tag{1}\]  
where  
\(y\) represents the actual value (reference device),  
\(m\) is the slope of the calibration curve (gain),  
\(x\) represents the measured value (device to be calibrated), and  
\(b\) is the curve y-intercept (offset). The first measurement should be performed within the lower range of the device's measurement domain, while the second measurement, if possible, should be executed within the upper range. For each measurement, the values indicated by both devices are recorded and then inserted into (2). \[ \begin{split} Out_{val}=(Raw_{val}-Dev_{L})\times\frac{Ref_{ range}}{Dev_{range}}+Ref_{L}\\ Ref_{range}=Ref_{H}-Ref_{L}\\ Dev_{range}=Dev_{H}-Dev_{L}\end{split}  \tag{2}\]  
where  
\(Raw_{val}\) is the value measured by the device at a given moment of time that needs to be corrected,  
\(Dev_{L}\) represents the value measured in the lower end domain of the device that needs to be calibrated,  
\(Dev_{H}\) is the value measured in the high-end domain of the device that needs to be calibrated,  
\(Ref_{L}\) represents the value measured in the lower-end domain of the calibrated (reference) device, and  
\(Ref_{H}\) is the value measured in the higher-end domain of the calibrated (reference) device. We used as reference device the Siemens SENTRON PAC4200 power meter. For the voltage measurement calibration, we executed the first measurement connecting our measuring device to the 110 V output of the isolation transformer. We recorded the phase voltages indicated by the Siemens power meter and our device and then executed the second measurement using the 230 V output of the isolation transformer. We stored the parameters and then used them in the compensation equation to adjust each measured voltage sample. The same technique was used for the current measurement. Using the signal samples, we calculated the voltage and current \(RMS\) values using (3). \[RMS_{value}[V/A]=\sqrt{\frac{\sum_{i=1}^{m}S_{i}^{2}}{n}} \tag{3}\]  
where  
\(S_{i}\) represents the signal sample, and  
\(n\) is the total number of samples. The active power was calculated as the average value of the voltage and current samples product. The apparent power results as the product of the voltage and currentRMS values. Based on the active and apparent power, the reactive power and power factor was obtained using (4). \[ \begin{split} P[W]=\frac{\sum_{j=1}^{n}U_{j}\times I_{j}}{n}\\ S[VA]=U_{RMS}\times I_{RMS}\\ Q[VAr]=\sqrt{\xi^{2}-P^{2}}\\ PF=\frac{P}{S}\end{split}  \tag{4}\]  
where:  
\(U_{j}\) represents a voltage sample value,  
\(I_{j}\) represents a current sample value,  
\(n\) is the total number of samples,  
\(U_{RMS}\) is the voltage RMS value, and  
\(I_{RMS}\) is the current RMS value. To analyze the power quality, we needed to compute the voltage and current total harmonic distortion values. This was achieved by determining the signal harmonic spectrum using a Fast Fourier Transform (FFT) and extracting the harmonics amplitude. The total harmonic distortion was calculated by introducing the harmonics amplitude in (5),  
\[ \begin{split} THD[\%]=\frac{\sqrt{\sum_{i=2}^{n}H_{IRMS}^{2}}}{H_ {fRMS}}\times 100\%\end{split}  \tag{5}\]  
where:  
Figure 4: Calibration setup diagram.