Development of a Smart Meter for Power Quality-Based Tariff Implementation in a Smart Grid

: Regarding the modern power smart grid, distribution consumers and prosumers are highly concerned about power quality (PQ). In fact, they would prefer to pay higher prices for a reliable and good quality power supply. Unfortunately, utility operators still aim for reliability alone, ignoring the quality of supply voltage and current. There are no clear guidelines for monitoring, penalizing, or implementing PQ-based tariff schemes in LV distribution systems. In addition, the implementation of a PQ-based tariff requires a real-time measuring mechanism at the user end, which is very expensive and difﬁcult to understand for a domestic consumer. This paper presents a novel, low-cost, efﬁcient, and user-friendly smart PQ meter to overcome these issues and limitations. It is essentially a PQ analyzer with energy metering functionality, which implements a novel PQ-based tariff scheme that penalizes consumers violating the PQ limits and provides incentives for a good PQ proﬁle. It measures as many as 28 parameters and keeps track of the PQ for both the consumer and the grid in real-time. This paper demonstrates the speciﬁcations, design, and testing of the meter and proves the validity of the concept by practical implementation. The meter is practical, feasible, and economical for implementing PQ-based tariff schemes in LV distribution systems or smart grids. estimating PQ even results obtained from testing satisfactory, PQ-based penalty assessments smart PQ The sensitivities penalties/incentives


Introduction
In many developing nations, a reliable power supply is a major concern and maintaining power quality (PQ) is of least priority. Although PQ issues have existed since the end of the 19th century, the severity and frequency of occurrence have increased recently because of the advent of modern power electronic devices in the distribution system. According to Brookings India's report [1], the distribution sector in India is the weakest link in the power industry in terms of financial and operational sustainability, and poor PQ is one of the primary reasons for it. The monitoring and regulation of PQ is a big challenge for utility operators. Thus, the PQ is neither measured nor maintained by the utility companies for LV domestic consumers.
Interestingly, nowadays consumers have realized the impact of poor PQ and are willing to pay higher tariff prices for a good quality power supply [2]. The consequences of poor PQ include fluctuations in the supply voltage, which causes a flicker phenomenon in domestic lights. This flickering causes a sensation of irritation to human eyes. In addition, oscillatory and impulsive transients or surges cause damage to computers and electronic loads [3]. Voltage sag and swell also degrade the performance of electromechanical devices like fans and motors [4]. These PQ disturbances not only affect the consumers but also damage utility equipment. For example, modern consumer loads are rich in harmonics, which can cause distribution transformers to get overheated and even saturated in worstcase scenarios due to the DC offset. Harmonics in the consumer load current also cause events related to voltage and frequency. However, it does not measure or monitor the consumer current. In addition, it needs an external computer and lacks the integration of energy metering functionality. Therefore, a separate hardware and energy metering device are required to accomplish the required functionalities of PQ and energy metering. Authors in [18] have proposed an Ethernet-based smart meter for PQ monitoring, which utilizes the LabVIEW software to assess the voltage quality. It includes a load scheduling functionality for PQ improvement in real-time. This meter also requires an external computer to run LabVIEW and does not measure distortions in the consumer current. A stand-alone smart meter proposed in [19] can detect voltage sag and swell, frequency of the supply, and power factor under linear load conditions only. However, it is suitable neither for measuring the harmonic distortion in both the voltage and current for the power-electronic energized loads nor the displacement power factor (DPF). In [20], the authors developed a Raspberry-Pi-based smart meter, which cannot measure consumer current distortion. An open-source Raspberry-Pi-based PQ analyzer presented in [21] measures the voltage parameters only. Moreover, the usage of Raspberry Pi is redundant and expensive and has a relatively higher power consumption.
A multifunctional smart meter in [22] has both energy and basic PQ metering capabilities and anti-theft features. However, it lacks the consumer current quality assessment functionality. A sophisticated FPGA-based PQ monitoring system proposed in [23] is complex and needs an external computer running LabVIEW. Another FPGA-based smart energy meter presented in [24] can be used as a stand-alone device for domestic applications. Nevertheless, this is a very complex system and is not cost-effective for domestic applications. It could be concluded that the FPGA and Raspberry-Pi-based smart meters are not stand-alone and affordable for domestic PQ monitoring applications.
Furthermore, in recent years, there have been a few data privacy concerns raised with smart meters. In some cases, smart meters can gather small pieces of information over short intervals and, therefore, give a detailed picture of which appliances are being used. This breach can lead to identifying specific characteristics that reveal information about a home's socio-economic status, dwelling, and appliances, posing a significant threat to consumers' privacy [25]. Data management becomes central to the development of AMI; therefore, some institutional changes are indispensable [26].
The aforementioned and a few commercially available smart PQ meters lack the features listed in Table 1. They are neither compact nor stand-alone. Additionally, they do not communicate to the server in some instances or end up being much too complex and thus expensive. The most important observation is that these meters do not have the required hybrid metering functionalities of energy and PQ metering. Therefore, there is a need to develop an efficient, low-cost PQ-based smart meter that has both energy and load PQ metering functionality. This paper presents a novel PQ-based tariff scheme based on the techno-economic consequences of consumers' reactive power and harmonics profiles. It imposes a fair penalty to consumers for their harmonic injection and gives them compensation for harmonic distortion in the grid voltage. The reactive energy penalty/incentive for consumers is defined based on PF limits. We designed and developed a low-cost, stand-alone smart PQ meter to efficiently implement the proposed single-phase tariff scheme. It communicates to the server quickly for data logging and implements the proposed tariff scheme.

Methodology
The PQ monitoring at each consumer location and penalizing for violations would help regulate PQ in the active distribution network. The following PQ-based tariff scheme is proposed for LV consumers to meet the objective.
This tariff scheme calculates penalties or incentives based on domestic consumers' reactive and harmonic energy profiles. This cost would be additional to their active energy cost and would be accumulated for short intervals of 10 min (settling window). The flowchart shown in Figure 1 illustrates the computation of the total penalty/incentive for a consumer. The first term, 'a', represents the fixed cost component of the tariff, which accounts for the costs related to the smart meter upgradation and operational and maintenance charges of ancillary services. The second term represents a penalty for violating power factor limits of 0.9. This limit is chosen as per the IEEE recommendations [27]. Here, 'b' is a penalty price for low PF ($/kVARh), and W QLPF is the reactive energy consumption at low PF (kVARh). The third term is the penalty to the consumer according to their harmonic pollution, where 'c' is the harmonic injection price ($/kVAh) and W HckVA is the nonfundamental or harmonic apparent energy (kVAh) injected by the consumer. The fourth and the last term is an incentive to the consumer due to grid harmonic distortion, where 'd' is the harmonic incentive price ($/kVAh) and W HukVA is the nonfundamental or harmonic apparent energy (kVAh) absorbed by the consumer due to the grid distortion. The index THD is chosen to verify the harmonic limit violation, and if violated, the penalty is based on the harmonic apparent energy. The THD of voltage and current are set to 5% in this work. However, these limits can be adjusted according to the recommendations of network operators and regulatory commissions. The value of d is chosen to be equal to the penalty price coefficient c. Thus, the consumer is penalized for the harmonic injection and given a compensation for distortion because of the grid voltage at the same price. This penalty/incentive tariff promotes good behavior from the consumer and utility and helps improve good practices for PQ regulation. The price coefficients b, c, and d are determined based on the techno-economic consequences of the consumer's reactive power and harmonic injection to the utility [28].

Hardware Description
To implement the proposed PQ-based tariff, a hardware setup of the smart PQ meter has been developed. The experimental setup of the meter and its PCB schematic are shown in Figures 2 and 3, respectively. This meter consists of mainly three sections: measurement, processing, and data relaying. The measurement section comprises voltage and current sensors along with an external ADC MCP3008. In most common circuits, a resistive voltage divider is used to step down and sample the line voltage, but that suffers from power line and stray noise issues. To overcome this, galvanic isolation is necessary between the power and measurement circuitry. Therefore, ZMPT101B is chosen for the voltage sensing because of its onboard potential transformer. This sensor belongs to the high-accuracy measurement class of 0.2, has a 1% linearity, and gives analog voltage output proportional to the line voltage applied across its input terminals. The ADC MCP3008 samples this output voltage, and it streams the digital readings to the dataplane processing unit (DPU) by SPI protocol. The current is measured by an integrated differential Hall-effect (Infineon TLI4970) sensor, which can measure up to 50A of peak value with a factory calibrated 1% precision range. This current sensor chip consists of an integrated differential Hall sensor on board along with integrated stress and temperature measurement sensors to compensate the readings for chip stress and temperature variations. It utilizes onboard DSP to process and filter the measurements directly. This DSP can be configured to design a filter of the user's choice to output the processed signal directly via the SPI bus. Both the sensors are synchronized with the help of a real-time operating system (RTOS) to avoid any significant phase angle errors.

Hardware Description
To implement the proposed PQ-based tariff, a hardware setup of the smart PQ meter has been developed. The experimental setup of the meter and its PCB schematic are shown in Figures 2 and 3, respectively. This meter consists of mainly three sections: measurement, processing, and data relaying. The measurement section comprises voltage and current sensors along with an external ADC MCP3008. In most common circuits, a resistive voltage divider is used to step down and sample the line voltage, but that suffers from power line and stray noise issues. To overcome this, galvanic isolation is necessary between the power and measurement circuitry. Therefore, ZMPT101B is chosen for the voltage sensing because of its onboard potential transformer. This sensor belongs to the high-accuracy measurement class of 0.2, has a 1% linearity, and gives analog voltage output proportional to the line voltage applied across its input terminals. The ADC MCP3008 samples this output voltage, and it streams the digital readings to the dataplane processing unit (DPU) by SPI protocol. The current is measured by an integrated differential Hall-effect (Infineon TLI4970) sensor, which can measure up to 50 A of peak value with a factory calibrated 1% precision range. This current sensor chip consists of an integrated differential Hall sensor on board along with integrated stress and temperature measurement sensors to compensate the readings for chip stress and temperature variations. It utilizes onboard DSP to process and filter the measurements directly. This DSP can be configured to design a filter of the user's choice to output the processed signal directly via the SPI bus. Both the sensors are synchronized with the help of a real-time operating system (RTOS) to avoid any significant phase angle errors. Energy (BLE) mode. The Bluetooth module can also be connected to the user's smartphone to display the PQ measurements. It also has RTOS support, which is maintained by the manufacturer. Overall, this meter runs on a 5 V power supply and consumes significantly less power, typically around 1.5 W. It is very power efficient and can be powered from miniature power supplies like smartphone charging adapters without hassle. The power adapter can be integrated within the meter and powered from the incoming AC lines.  This MCU polls both voltage and current sensors at a high sampling rate of 2048 samples per second and computes 28 parameters from the voltage and current raw data. The parameters include fundamental frequency, actual and gross RMS values of voltage and current, magnitude and phase of voltage and currents, active power and energy, reactive power and energy, THD, DPF, voltage sag and swell, utility distortion volt-ampere, and consumer distortion volt-ampere. Finally, it calculates the penalties/incentives for the consumer based on these extracted parameters.
The meter records the PQ phenomena for monitoring and post analysis and sends all the data to the remote server every minute continuously. The meter uses the HTTP POST protocol to send the data to the specified domain address. This domain has a PHP script running, which captures this data and injects it into the MySQL database. These readings Energy (BLE) mode. The Bluetooth module can also be connected to the user's smartphone to display the PQ measurements. It also has RTOS support, which is maintained by the manufacturer. Overall, this meter runs on a 5 V power supply and consumes significantly less power, typically around 1.5 W. It is very power efficient and can be powered from miniature power supplies like smartphone charging adapters without hassle. The power adapter can be integrated within the meter and powered from the incoming AC lines.  This MCU polls both voltage and current sensors at a high sampling rate of 2048 samples per second and computes 28 parameters from the voltage and current raw data. The parameters include fundamental frequency, actual and gross RMS values of voltage and current, magnitude and phase of voltage and currents, active power and energy, reactive power and energy, THD, DPF, voltage sag and swell, utility distortion volt-ampere, and consumer distortion volt-ampere. Finally, it calculates the penalties/incentives for the consumer based on these extracted parameters.
The meter records the PQ phenomena for monitoring and post analysis and sends all the data to the remote server every minute continuously. The meter uses the HTTP POST protocol to send the data to the specified domain address. This domain has a PHP script running, which captures this data and injects it into the MySQL database. These readings The core of the DPU is ESP32, which has a very capable 32-bit dual-core Tensilica Xtensa LX6 microprocessor with a rich number of multiplexed and programmable GPIO pins and communication protocol support like UART, SPI, I2C, I2s, and CAN. The key feature of this module is the integrated Wi-Fi and dual-mode Bluetooth. This Wi-Fi can run in both station and access modes. It can be used to connect to the internet for data upload, and it can also host a local webpage to the users via TCP/IP to display data to the users. The Bluetooth function can also run in both classical Bluetooth and Bluetooth Low Energy (BLE) mode. The Bluetooth module can also be connected to the user's smartphone to display the PQ measurements. It also has RTOS support, which is maintained by the manufacturer. Overall, this meter runs on a 5 V power supply and consumes significantly less power, typically around 1.5 W. It is very power efficient and can be powered from miniature power supplies like smartphone charging adapters without hassle. The power adapter can be integrated within the meter and powered from the incoming AC lines.
This MCU polls both voltage and current sensors at a high sampling rate of 2048 samples per second and computes 28 parameters from the voltage and current raw data. The parameters include fundamental frequency, actual and gross RMS values of voltage and current, magnitude and phase of voltage and currents, active power and energy, reactive power and energy, THD, DPF, voltage sag and swell, utility distortion volt-ampere, and consumer distortion volt-ampere. Finally, it calculates the penalties/incentives for the consumer based on these extracted parameters.
The meter records the PQ phenomena for monitoring and post analysis and sends all the data to the remote server every minute continuously. The meter uses the HTTP POST protocol to send the data to the specified domain address. This domain has a PHP script running, which captures this data and injects it into the MySQL database. These readings can be accessed and visualized on the webpage for both users and the utility provider. This meter can also log the data via its UART port to a PC for analysis and diagnostic purposes.

Algorithm
The smart meter must perform both energy and PQ metering in real time, and hence the RTOS is used to handle all the mission-critical activities. This RTOS divides all the functions into smaller tasks, which have their priority and resources assigned to them. This RTOS supports symmetrical multiprocessing (SMP) in which each core shares resources with the other and has a dedicated scheduler for task scheduling. The scheduler in the RTOS makes sure that each task gets enough computational and hardware resources according to the priority and finishes its execution in the allocated timeline. Nevertheless, this needs careful execution because sharing resources can result in deadlocks, spinlocks, and core panics. Therefore, tools like semaphores and mutexes are used to avoid these issues.
For this meter, the functions are divided into three major tasks: measurement, processing, and data relaying. The measurement task is pinned to core 1 of the CPU and is used to poll the sensors regularly and update the array containing voltage and current samples. This core samples the readings in the current instant by utilizing hardware timer interrupts. This task is very time-critical, meaning that the polling should be symmetrical and synchronous; otherwise, it may compromise the overall meter functionality. The polling task is depicted with s1, s2, s3, etc., as shown in Figure 4. Since the sampling frequency is 2048 Hz, the readings are taken at an equidistant sampling interval of 1/2048 s. With the selected sampling rate, the meter can measure the harmonics up to 20th order in both voltage and current. The second task of processing is pinned to core 0 of the CPU, processes the voltage and current readings captured in the previous second, and posts the data to the server every minute. This task has a deadline of 1 s, indicating that the readings of the previous second should be processed entirely, and the processor should be idle before the new readings arrive. The timeline of all the tasks and their respective cores are shown in Figure 4. The final task of data relaying is also pinned to core 0, and this task is executed every 60 s. This task relays both active and reactive power and energy, DPF, distortion VA of the grid and consumer, and the penalties and incentives for the PQ profiles. All the tasks run parallelly in real time, as shown in the timeline, and all the hardware resources and programming variables are shared within the two cores simultaneously. can be accessed and visualized on the webpage for both users and the utility provider. This meter can also log the data via its UART port to a PC for analysis and diagnostic purposes.

Algorithm
The smart meter must perform both energy and PQ metering in real time, and hence the RTOS is used to handle all the mission-critical activities. This RTOS divides all the functions into smaller tasks, which have their priority and resources assigned to them. This RTOS supports symmetrical multiprocessing (SMP) in which each core shares resources with the other and has a dedicated scheduler for task scheduling. The scheduler in the RTOS makes sure that each task gets enough computational and hardware resources according to the priority and finishes its execution in the allocated timeline. Nevertheless, this needs careful execution because sharing resources can result in deadlocks, spinlocks, and core panics. Therefore, tools like semaphores and mutexes are used to avoid these issues.
For this meter, the functions are divided into three major tasks: measurement, processing, and data relaying. The measurement task is pinned to core 1 of the CPU and is used to poll the sensors regularly and update the array containing voltage and current samples. This core samples the readings in the current instant by utilizing hardware timer interrupts. This task is very time-critical, meaning that the polling should be symmetrical and synchronous; otherwise, it may compromise the overall meter functionality. The polling task is depicted with s1, s2, s3, etc., as shown in Figure 4. Since the sampling frequency is 2048 Hz, the readings are taken at an equidistant sampling interval of 1/2048 s. With the selected sampling rate, the meter can measure the harmonics up to 20th order in both voltage and current. The second task of processing is pinned to core 0 of the CPU, processes the voltage and current readings captured in the previous second, and posts the data to the server every minute. This task has a deadline of 1 s, indicating that the readings of the previous second should be processed entirely, and the processor should be idle before the new readings arrive. The timeline of all the tasks and their respective cores are shown in Figure 4. The final task of data relaying is also pinned to core 0, and this task is executed every 60 s. This task relays both active and reactive power and energy, DPF, distortion VA of the grid and consumer, and the penalties and incentives for the PQ profiles. All the tasks run parallelly in real time, as shown in the timeline, and all the hardware resources and programming variables are shared within the two cores simultaneously.

Measurment
As the voltage and current waveforms are sampled at 2048 Hz, the interrupt should be generated at every 488.28 µs interval. To do so, an appropriate count is loaded in timer 1 of core 1, and this timer interrupt updates a flag variable in the interrupt service routine (ISR) upon its overflow, indicating to the core that the time has elapsed and the sensors should be polled. The sensors are polled for a complete 1 s interval like this, and the sampled readings are passed to core 0 for the calculation task. After this, polling for the next second begins again, and the process continues forever in a loop. It is a time-bound infinite loop that runs continuously in parallel to all the other tasks. The flow chart of the whole program is shown in Figure 5.
Energies 2021, 14, x FOR PEER REVIEW 8 of 22 As the voltage and current waveforms are sampled at 2048 Hz, the interrupt should be generated at every 488.28 μs interval. To do so, an appropriate count is loaded in timer 1 of core 1, and this timer interrupt updates a flag variable in the interrupt service routine (ISR) upon its overflow, indicating to the core that the time has elapsed and the sensors should be polled. The sensors are polled for a complete 1 s interval like this, and the sampled readings are passed to core 0 for the calculation task. After this, polling for the next second begins again, and the process continues forever in a loop. It is a time-bound infinite loop that runs continuously in parallel to all the other tasks. The flow chart of the whole program is shown in Figure 5.

Processing
For the implementation of the penalty/incentive scheme, the following listed power, energy, and PQ parameters are measured.

True RMS Value
Unlike the conventional method, which finds the RMS value from its amplitude, this method computes the true RMS value as given in (3).

Active and Reactive Power
The active (P) and reactive (Q) powers can be computed by using the RMS value of the fundamental voltage and current components and the DPF value as follows. P = V1RMS I1RMS DPF and Q = VRMS IRMS tan(cos −1 (DPF)) (4) Figure 5. Task execution loops for both cores.

Processing
For the implementation of the penalty/incentive scheme, the following listed power, energy, and PQ parameters are measured.

True RMS Value
Unlike the conventional method, which finds the RMS value from its amplitude, this method computes the true RMS value as given in (3).

Active and Reactive Power
The active (P) and reactive (Q) powers can be computed by using the RMS value of the fundamental voltage and current components and the DPF value as follows. P = V 1RMS I 1RMS DPF and Q = V RMS I RMS tan(cos −1 (DPF)) (4)

Active and Reactive Energy
Similarly, the active and reactive energies can be found by multiplying the active and reactive power values with time. In this case, the time set is to 1 s, meaning that at any second, active or reactive energy being utilized is equal to active or reactive power. Here, the term (∅ 1 − θ 1 ) corresponds to the phase difference between the fundamental voltage and current. Reactive Energy = P * tan (∅ 1 − θ 1 ) * t (5)

THD in Voltage and Current
THD, an acronym for total harmonic distortion, is a quantity defined as the ratio of harmonic RMS voltage/current to the fundamental RMS voltage/current. The THD values indicate the amount of distortion with respect to the fundamental component. The THD in voltage and current can be determined using (6), where V 1 , V 2 , V 3 , etc., represent the magnitudes of the fundamental, second, and third harmonic components, respectively.

Consumer and Grid Harmonic Distortion Power in VA
In the case of nonsinusoidal voltage and current signals, the total apparent power can be computed as in (7), per the IEEE standard [29].
where V 1 I 1 is the fundamental apparent power, V 1 I H is the current harmonic distortion VA, V H I 1 is the voltage harmonic distortion VA, V H I H is the harmonic distortion apparent power VA. These power values are used to find the harmonic contribution of the consumer and grid, and then the energy values W HckVA and W HukVA are derived. W HckVA corresponds to the harmonic distortion energy injected by the consumer, and it is found by multiplying the current harmonic distortion value, i.e., V 1 I H , with time. W HukVA is the harmonic distortion energy due to utility, and it is a product of the V H I H component and time.

Sag and Swell in the Utility Voltage
The percentage of voltage sag and voltage swell are monitored continuously as given in (8) and (9)

Penalties and Incentives for PQ violations
Finally, after assessing the power, energy, and necessary PQ parameters for a consumer and utility, these values should be checked for violations of the specified limits. If the consumer load profile adheres to the aforementioned harmonic and power factor limits, the consumer is given an incentive and penalized otherwise. In this scheme, the penalties are imposed because of harmonic limit violations and reactive power limit violations, whereas compensation is given to the consumer for grid voltage distortion due to utility. The total penalty/incentive is obtained using (1)-(9), and they are in addition to the active energy consumption charges.

Data Relaying
After necessary computations and processing, the PQ smart meter communicates all these quantities to a remote server. This information flow is shown in Figure 6. The meter gets connected to the Wi-Fi access point, sends an HTTP POST request to the website running the PHP script, and waits for acknowledgment. This PHP script captures the meter data, verifies the access credentials, and then transmits the captured data into the SQL database. This database is then later used for visualization by another PHP script on the website to display the data for the user.
After necessary computations and processing, the PQ smart meter communicates all these quantities to a remote server. This information flow is shown in Figure 6. The meter gets connected to the Wi-Fi access point, sends an HTTP POST request to the website running the PHP script, and waits for acknowledgment. This PHP script captures the meter data, verifies the access credentials, and then transmits the captured data into the SQL database. This database is then later used for visualization by another PHP script on the website to display the data for the user.

Software Testing Results
To elucidate the estimation accuracy and proof of concept of implementation of the tariff scheme, the developed smart PQ meter is verified for both simulated and real-world situations. The performance of the meter is tested under various load conditions to examine its hardware and software functionalities like the interrupt reliability, efficiency of the FFT algorithm, overall penalty/incentive calculation, PHP site, and MySQL server. Figure 7 shows how interrupts are generated every required second without fail. To test the implementation of the FFT algorithm, a digital nonsinusoidal signal, shown in Figure 8, with a mixture of third harmonic components, is loaded into the MCU, and then the obtained FFT spectrum is compared with the expected one. The calculated magnitude spectrum shown in Figure 9 exactly matches the expected spectra, and the phase relationships are found to be correct.
Finally, to test the data upload and visualization, the MCU is fed with sample data in two sets. The first set has digitized samples of the voltage corresponding to the RMS values of 230 V, 50 Hz, and the phase of 60 ° and current of the magnitude of 5 A for the fundamental and 1.5 A for third harmonic. The second set of data has digitized samples corresponding to the same voltage and current values with an additional 12% voltage sag. It is observed that all 28 parameters are calculated with very satisfactory accuracy, and the error due to floating-point arithmetic is much lower, almost negligible. The meter gets connected to a Wi-Fi network and, through HTTP POST, sends the data to the remote site and displays the parameters on the local computer as well via UART, as shown in Figures 10 and 11. The website updates the readings with the arrival of every new datum, and this datum is verified to be correct.

Software Testing Results
To elucidate the estimation accuracy and proof of concept of implementation of the tariff scheme, the developed smart PQ meter is verified for both simulated and realworld situations. The performance of the meter is tested under various load conditions to examine its hardware and software functionalities like the interrupt reliability, efficiency of the FFT algorithm, overall penalty/incentive calculation, PHP site, and MySQL server. Figure 7 shows how interrupts are generated every required second without fail. To test the implementation of the FFT algorithm, a digital nonsinusoidal signal, shown in Figure 8, with a mixture of third harmonic components, is loaded into the MCU, and then the obtained FFT spectrum is compared with the expected one. The calculated magnitude spectrum shown in Figure 9 exactly matches the expected spectra, and the phase relationships are found to be correct.
Finally, to test the data upload and visualization, the MCU is fed with sample data in two sets. The first set has digitized samples of the voltage corresponding to the RMS values of 230 V, 50 Hz, and the phase of 60 • and current of the magnitude of 5 A for the fundamental and 1.5 A for third harmonic. The second set of data has digitized samples corresponding to the same voltage and current values with an additional 12% voltage sag. It is observed that all 28 parameters are calculated with very satisfactory accuracy, and the error due to floating-point arithmetic is much lower, almost negligible. The meter gets connected to a Wi-Fi network and, through HTTP POST, sends the data to the remote site and displays the parameters on the local computer as well via UART, as shown in Figures 10 and 11. The website updates the readings with the arrival of every new datum, and this datum is verified to be correct.

Hardware Testing Results
To verify the efficiency of the hardware setup, the PQ meter is subjected to various operating conditions. A wave shape and phase relationship test and true RMS measurement test were carried out, and the results discussed below.

Waveshape and Phase Relationship Test
The meter was connected to monitor a 750 W electric iron box load to test the waveshape and the phase relationship. The load was linear and slightly inductive. The code was loaded to the MCU to visualize the voltage and current readings on the serial terminal of a computer, which is shown in Figure 12. It can be noticed from the voltage and current waveforms that the current lagged the voltage and was not contaminated with noise.

Hardware Testing Results
To verify the efficiency of the hardware setup, the PQ meter is subjected to various operating conditions. A wave shape and phase relationship test and true RMS measurement test were carried out, and the results discussed below.

Waveshape and Phase Relationship Test
The meter was connected to monitor a 750 W electric iron box load to test the waveshape and the phase relationship. The load was linear and slightly inductive. The code was loaded to the MCU to visualize the voltage and current readings on the serial terminal of a computer, which is shown in Figure 12. It can be noticed from the voltage and current waveforms that the current lagged the voltage and was not contaminated with noise.

True RMS Measurement Test
A bulb was connected to single-phase supply mains with a fan regulator in series to test the true RMS measurement capability, as shown in Figure 13. The fan regulator acted as a potential divider and facilitated the voltage control across the bulb. The smart PQ meter readings are tabulated in Table 2, and the percentage deviation was computed with reference to the values measured from the commercially available digital multimeter (DMM). The maximum error was found to be 1.3%, which is acceptable as per the standards.

True RMS Measurement Test
A bulb was connected to single-phase supply mains with a fan regulator in series to test the true RMS measurement capability, as shown in Figure 13. The fan regulator acted as a potential divider and facilitated the voltage control across the bulb. The smart PQ meter readings are tabulated in Table 2, and the percentage deviation was computed with reference to the values measured from the commercially available digital multimeter (DMM). The maximum error was found to be 1.3%, which is acceptable as per the standards.  Table 3 demonstrates the merit of the proposed penalty/incentive scheme considering four possible conditions. The penalty/incentive prices and the cost were derived in Indian Rupees (Rs. or INR) as per the cost of ancillary services and tariffs in the Indian electricity market. However, for a universally acceptable representation, they have been reported in USD. The price coefficients a, b, c, and d in (1) were set to 0.0012 USD/hr, 0.014 USD/kVARh, 0.021 USD/kVAh, and 0.016 USD/kVAh, respectively. The energies and thereby the penalties/incentives were computed assuming that the load was operated in a steady state for one hour. Case 1 was a purely linear and resistive load, and as expected, the consumer was not penalized for any of the violations. In case 2, the load was linear Figure 13. Hardware setup to test true RMS measurement capability.  Table 3 demonstrates the merit of the proposed penalty/incentive scheme considering four possible conditions. The penalty/incentive prices and the cost were derived in Indian Rupees (Rs. or INR) as per the cost of ancillary services and tariffs in the Indian electricity market. However, for a universally acceptable representation, they have been reported in USD. The price coefficients a, b, c, and d in (1) were set to 0.0012 USD/hr, 0.014 USD/kVARh, 0.021 USD/kVAh, and 0.016 USD/kVAh, respectively. The energies and thereby the penalties/incentives were computed assuming that the load was operated in a steady state for one hour. Case 1 was a purely linear and resistive load, and as expected, the consumer was not penalized for any of the violations. In case 2, the load was linear but inductive with 0.8 pf lag. Therefore, the distortion and penalty due to harmonics were zero, but the consumer was penalized for the power factor violation alone. The consumer with the reactive and nonlinear load, as presented in case 3, was penalized for both the violations. In case 4, an incentive was given to the consumer for harmonics (6% THD) in the grid voltage. The smart meter measured the voltage and current, processed the signals, computed all the necessary parameters, and penalized the consumers. The smart PQ meter was connected to the three types of domestic loads to test the overall PQ and energy meter functionality. One was purely resistive, and the second was an RL load and a nonlinear load. The test setups of the three loads are shown in Figure 14. Figure 14a shows the experimental setup of a smart meter measuring the PQ of an incandescent bulb, which had a resistive property. Figure 14b shows the PQ measurement of a domestic iron, which was an RL-type load. The laptop charger was basically a switch-mode power supply, and, hence, the current distortion could be measured using the PQ meter, as shown in Figure 14c. The waveforms of measured voltage and current of these loads, which were captured using a serial plotter, are shown in Figure 15. The phase relationships of the applied voltage and load current of all the loads were found to be satisfactory. These measured raw data were processed, and all 28 PQ parameters were computed as explained in Sections 3 and 4. The parameters estimated using the smart meter were displayed on a monitor locally, as shown in Figure 16. The lamp was neither inductive nor nonlinear, and, hence, the estimated power factor was in unity and there were no additional penalties/incentives for this load. The overall computation time was around 160 ms, which indicates that the monitoring could be performed online without loss of data. The domestic iron, which was an inductive load, was penalized for its poor power factor. Since the grid voltage was sinusoidal and the load was also linear, the penalty and incentive for harmonic distortion were zero.

Overall Functionality Testing
The same was evident from the results displayed in Figure 16b. The laptop charger, which was both nonlinear and had a poor input power factor, was penalized for both violations, as shown in Figure 16c. The THD of the current was estimated to be 129.76%, and there was a negligible distortion VA due to utility for all three load cases. Due to a lack of shielding, the EMI was prominent. As a result, the THD of pure sinusoidal voltage was estimated to be 3%. Therefore, the penalty was imposed if the THD was more than 8% only. As the utility voltage had an actual THD of less than 5%, the consumer received no incentive for the same. These measured and estimated parameters were uploaded to the site and visualized on the webpage, as shown in Figure 17. The results were also saved in the database with a timestamp for post-PQ analysis. The same was evident from the results displayed in Figure 16b. The laptop charger, which was both nonlinear and had a poor input power factor, was penalized for both violations, as shown in Figure 16c. The THD of the current was estimated to be 129.76%, and there was a negligible distortion VA due to utility for all three load cases. Due to a lack of shielding, the EMI was prominent. As a result, the THD of pure sinusoidal voltage was estimated to be 3%. Therefore, the penalty was imposed if the THD was more than 8% only. As the utility voltage had an actual THD of less than 5%, the consumer received no incentive for the same. These measured and estimated parameters were uploaded to the site and visualized on the webpage, as shown in Figure 17. The results were also saved in the database with a timestamp for post-PQ analysis.   Finally, the results clearly indicated the feasibility and efficiency of the implementation of a PQ-based smart meter. It was able to measure and monitor the PQ parameters of the single-phase consumer along with the energy metering and impose a penalty/incentive to promote good PQ practices. To avoid a penalty for reactive energy consumption, the consumers can install a fixed capacitor bank for the reactive power support. Additionally, consumers can utilize energy-efficient and certified equipment only. The developed smart PQ meter also uploads data to the server to characterize the PQ profiles of both consumer and utility. Therefore, the developed PQ meter provides relevant information about the grid and user PQ profiles in real time with the help of the Finally, the results clearly indicated the feasibility and efficiency of the implementation of a PQ-based smart meter. It was able to measure and monitor the PQ parameters of the single-phase consumer along with the energy metering and impose a penalty/incentive to promote good PQ practices. To avoid a penalty for reactive energy consumption, the consumers can install a fixed capacitor bank for the reactive power support. Additionally, consumers can utilize energy-efficient and certified equipment only. The developed smart PQ meter also uploads data to the server to characterize the PQ profiles of both consumer and utility. Therefore, the developed PQ meter provides relevant information about the grid and user PQ profiles in real time with the help of the existing network infrastructure. This meter has a small form factor, consumes less power, around 1.5 W, and is Wi-Fi connected. In addition, the meter has cutting-edge communication technology such as a Bluetooth Low Energy (BLE) and Wi-Fi module on board, which can work in access and station modes.
The total cost of the smart meter implementation is 39 USD only and is economical compared to a commercially available smart meter, which usually costs 55-70 USD. The cost of major components is given in Table 4. This cost can be reduced further by batch production. The cost for an annual server subscription to host a website is 44 USD, which can be commonly used to monitor data from thousands of smart meters. The proposed penalty/incentive is arrived at based on reactive and harmonic energy. Therefore, the scheme can be extended seamlessly for the three-phase consumers as well. To this end, we can adopt the "effective voltage, current, and power" concept suggested in the IEEE standard 1459 [29] to estimate the effective reactive and harmonic energies. This approach is applicable for both the balanced and unbalanced three-phase, four-wire systems. For the smart PQ meter to measure three-phase voltages and currents, all the phases should be equipped with voltage and current sensors and necessary peripheral devices for interfacing and monitoring.

Conclusions
This work presents a PQ-based tariff scheme for the regulation of harmonics and reactive power in an LV distribution system. Additionally, it demonstrated the implementation and merits of a smart PQ meter for the PQ-based tariff. The price coefficients of the proposed penalty/incentive scheme were arrived based on the techno-economic consequences of their PQ load profile. This meter is equipped with quality sensors and processing and wireless communication mechanisms. It is capable of estimating 28 PQ parameters from the voltage and current and even record and relay them to a remote server continuously. The results obtained from testing were satisfactory, and the PQ-based penalty assessments were realistic. It can be concluded that the developed smart PQ meter is practical and economical for installation at the supply mains of LV consumers. This continuous PQ monitoring and tariff scheme for LV consumers can help in PQ regulation and encourages the utility and consumer to improve their PQ profile. The sensitivities of penalties/incentives to variations in PF and distortion limits can be studied in the future.