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.


Sunday, 22 January 2017

How to establish the communication between ZigBee(Telegesis) and Arduino UNO

The part number of this ZigBee is EXTR357 of Telegesis. 
For convenient, the development board of ZigBee (Telegesis) and Arduino UNO are going be used for testing.

According to the datasheet of Arduino UNO, whose chip number is ATmega328P, it only has one software serial and one hardware serial. For the EXTR357 of ZigBee, it only has one hardware serial also. The hardware serial of them is occupied by the USB port. At the same time, Arduino UNO cannot use software serial to communicate with the hardware serial of ZigBee.
Therefore, the communication between them can only be established by hardware serial.

The connection of the hardware serial will be the diagram below. But at this testing, the power supply of Arduino will be supplied by the battery of ZigBee. So the 3.3 Vcc of Arduino should short with the Vcc of ZigBee together as the standard voltage input of ZigBee is 3.3V. Since the USB port of both of them will occupy the hardware serial, after downloaded the program, they should be plugged out when the ‘Tx’ or ‘Rx’ is using.
Without the USB port, the ZigBee can change to battery power through changing the connection in the development board, referring the picture below.
Therefore, the code for testing the communication between ZigBee and Arduino can be written, referring the code below.
This code is going to write the value stored in the S3B register of ZigBee with increasing the number. As the register of S3B is to contain text, the text inside can be read also for checking. 

Sunday, 15 January 2017

How to use the current sensor of ACS721 (Communicate with Arduino)

According to the datasheet of the current sensor of ACS721, it can be used in AC or DC circuit and even connected with 230Vac directly. Moreover, the reasons for choosing this component are the size of it is small enough and it can communicate with Arduino through Serial Port.


Referring to the picture above, the pin 1 and pin 2 should be shorted together and connected to the positive pole of the AC circuit. The pin 3 and pin 4 should be shorted and connected to the negative pole. The pin 8 is Vcc, which connected to the 5Vdc power supply. And the filter connects with one capacitor then connects to ground. After finished the circuit by following the picture above, the pin 7 (Vout) can connect with anyone of the analog input of the Arduino, as which is analog signal output, referring the Pin Mapping of Arduino below.

After finished the connection, the Arduino UNO and the Current sensor will look like the picture below.

For convenience, the breakout boards of current sensor can be used also. As the connection is easier.



There is the progress code for trying to understand the communication between Arduino UNO and this Current sensor, referring the steps below.

1. It is just to see what value will Arduino UNO received through the Serial Monitor when there is no current pass through. Referring the picture, the raw value appeared in the serial monitor is around 512, 513, and 514.



2. After opened the power supply with AC current (which means got current pass through the current sensor), the raw value is changed abound 5 higher or lower than 513 alternately.



3. These are the final code which will be used.


Saturday, 12 November 2016

Design Circuit & Purchase Components

Aims to expand and perfect the home automation project, the end devices (Smart Power Plug) will be added in. As it is a power plug device called smart, it will not only be controlled by web page while the user wants to on or off it, but also can detect and sent the current signal to the web page for the user managing electricity and saving money.

The components required for measuring current are Current Sensor, Microcontroller, and Telegesis ZigBee chip. Current Sensor is to measure current and send out the analog signal through output pin. The microcontroller is to receive the analog signal and convert it to the digital signal. After got the digital signal from Microcontroller, ZigBee sends out the data, which is the value of current through wireless. Of course, there is a component rolled power supply, which can convert 230 Vac to 3.3 Vdc or 5.5 Vdc for other components.



Purchasing Components:

  • Current Sensor:
  • Microcontroller:
  • ZigBee:
  • Power Supply:

After receiving the components, the connection between current and microcontroller are going to be tested firstly. Referring the picture below:
According to the circuit diagram of the datasheet, the Vout of the current sensor can connect with the Analog input of the microcontroller.