Thursday, 23 February 2017

How to use Arduino to measure the real power (Program)

After making sure that the analog input 1 is connected to the output of ACS712 and the analog input 2 is connected to the output of the adjusting voltage circuit, the next step is using Arduino UNO to help to calculate out the real power value.


Figure 1 Arduino UNO Pin Mapping

Real power is the average of instantaneous power. The calculation is relatively straightforward:

Firstly, the instant power can be calculated out by multiplying the instant voltage measurement by the instant current measurement. After that, the instant power measurement can be summed over a given number of samples and divide by that number of samples:

    Calibration Theory for Voltage Part

As the voltage value going into the analog pin of Arduino UNO is not the real voltage, the calibration should be setup.

Referring to the circuit diagram above,
counts = (input pin voltage ÷ 3.3) × 1024
input pin voltage = transformer output voltage ÷ 11
transformer output voltage = mains voltage × transformer ratio
After simplify,
counts = mains voltage ×(transformer ratio×1024)/(3.3×11)
main voltage = counts ×(3.3/1024)×(11/transformer ratio)

The part of (11/transformer ratio), which can be calcuted out from the hardware part, will be 185.9, which is proved after a lot of testing.
Notes, the voltage transformer output is nominally 9 V for 230 V input, but this is at full load. When used as a voltage monitor, it is effectively running unloaded, and the voltage is approximately 20% higher (the value depends on the design of the transformer. 20% is typical for this type and size).

    Calibration Theory for Current Part

As the voltage value going into the analog pin of Arduino UNO is converted after the component of ACS712, the calibration should be setup.

Referring to the circuit diagram above,
counts = (input pin voltage ÷ 3.3) × 1024
input pin voltage = primary current × Sensitivity
After simplify,
counts = primary current ×(sensitivity×1024)/3.3
primary current = counts ×(3.3/1024)×(1/sensitivity)

The part of (1/sensitivity), which can be calcuted out from the hardware part with referring to the data ship of ACS712, will be 17.49, which is proved after a lot of testing.

Calibration Setup
After making sure the calibration value, the next step is adding them into the Arduino program and double confirm the value through comparing with the real value.

    Measure the real power for 1 second

Referring to the program below, the while loop for reading the voltage and current signal is depending on two conditions. The number of crossing in this project is 20. The value of the timeout is 200ms. That means it will go out of the while loop when the count of cross is bigger than 20 or time up.
Calculation:
20 No. of half wavelengths = 10 full wavelengths
1 / 50Hz = 20ms
10 × 20ms = 200ms = 0.2s
The reason for setting the value of time-out is 200ms is making sure it will go out of the while loop every 200ms.
0.2s × 5 = 1s
For measuring the real power for 1 second the for loop is used to accumulate the real power 5 times and then divide by 5.

How to use Arduino to measure the real power (Measure Circuit)

·        What is Real Power

The two types of load will appear in the home appliance is Resistive Load and Partially Reactive Load.
Resistive load means its current draw is equal to the voltage divided by resistance (Ohm's Law). A purely resistive load gives a voltage and current waveform output similar to the following:

Figure 1 Resistive Load

Referring to the waveform above, the power is always positive.
However, there are the home appliance are not so straightforward, like fridges, which runs like Partially Reactive Load. As these appliances take in a certain amount of energy, then release some energy back into the mains supply. A partially inductive load gives a voltage and current waveform output similar to the following:


Figure 2 Partially Reactive Load

Referring to the waveform above, the positive bit is energy flowing to the load and the negative bit is energy flowing back from the load.

Real power is often defined as the power used by a device to produce useful work. Therefore, the power going to, minus the power going back, is the real power. The real power or active power can be found out through calculating the average of the instantaneous power also:


·        Adjust Voltage

The circuit diagram below is for adjusting the AC voltage before it goes to the analog pin of Arduino.

Figure 3 Circuit for Adjusting Voltage

For this part, the tasks should be done are scaling down the waveform and adding an offset for making sure there is no negative component.
The Voltage Transformer used is for converting 230 Vac to 9 Vac. Resistors R1 and R2 form a voltage divider that scales down the AC voltage. Depending on the theory between voltage and resistor, the calculation will be:

Voltage Transformer Output = 9 Vrms
9 Vrms x √2 = 12.7 Vp
12.7 Vp x 2 = 28.45 Vpp
28.45 Vpp x 10 / (100+10) = 2.58 Vpp


At the same time, Resistors R3 and R4 provide the voltage bias. Capacitor C1 provides a low impedance path to ground for the AC signal. As the R3 and R4 are connected in series between the Arduino Vcc and GND, the mid-point of them will be the half of the Vcc while R3 and R4 are the same value. (The reason for choosing 470k Ohm is for safety as this value is big enough.)
Referring to the circuit, the mid-point of R3 and R4 are connected to one side of R1, so the voltage of the other side of R1 will be shift up the half of the Vcc. As the part of R1 Voltage peak to peak is about 2.58 Vpp, which is smaller than 3.3V, then it can go to the analog pin of Arduino safety.

·       Adjust current to Voltage output
The component and circuit diagram below is for adjusting the AC current to Voltage output before it goes to the analog pin of Arduino.

With using the component of ACS712, the tasks of scaling down the waveform and adding an offset can be done directly. As the output of ACS712 is an analog singal, Vout, that varies linearly with the uni- or bi-directional AC or DC primary sensed current, Ip, within the range specified, referring to the circuit diagram above and below.