Have you ever been curious about the power consumption of an appliance? For example did you wonder how much it will cost you to leave your television in standby mode whole night? Or did you want to learn how much change your refrigerator settings will make on your electric bill? If your answer is yes, you can use a wattmeter to measure the power consumption of a device. In this project we are building one (Figure 1).
This is an AC Watt Meter which can measure the real power consumption of a device connected to the 230Vrms/50Hz mains line. The PIC microcontroller PIC18F252 from Microchip collects the voltage and the current information with the help of ADCs and then calculates the RMS voltage of the mains line, RMS current drawn by the device and the resulting average power consumption. All these information is then displayed on the dot matrix LCD.
The meter itself doesn’t need an external power source. It is powered from the mains. Despite this, the microcontroller side is fully isolated from the parts interfacing to the mains.
The schematic of the project (Figure 2) is drawn in SoloCapture, the schematic editor of SoloPCB tools. SoloCapture makes the schematic drawing process very easy and fast. You can download SoloPCB tools for FREE.
You can download the SoloPCB design files of the project by using the link in download section. Please check out this video to see how to import the project libraries, open and synchronize the schematic and PCB files.
To calculate the power, we need to know the voltage across the load and the current drawn by the load. The voltage that should be measured is directly the mains voltage. We know that the mains voltage is 230 Vrms/50 Hz but it has a 10% tolerance. So the voltage can change between 207 Vrms and 253 Vrms. To make an accurate power measurement, it will be better to measure the mains voltage instead of putting 230 Vrms into the calculations.
The mains line is connected to the AC IN connector (J1), see Figure 3. For the voltage measurement, a resistor divider network (R1, R2, R3) is connected between the phase and the neutral lines. With the help of the voltage divider, the mains voltage is down scaled at a factor of R1/(R1 + R2 + R3) = 1/201 which converts ±320 V (peak) to ±1.59 V. Then 2.5 V up shifting is applied which finally maps ±320 V to 0.91 V – 4.09 V that nicely fits between 0-5 V with a good level of safety margin.
After this scaling and shifting process, the voltage across R2 is read by MCP3202 ADC. Then the voltage information is read by the microcontroller in 12 bit format over SPI interface. To isolate the microcontroller part from the section interfacing to the mains, HCPL-0630 high speed optocouplers are used. The second analog input channel of MCP is used to read the 2.5 V reference voltage and use it as the correction factor in the calculations.
While the neutral and earth lines coming from the AC IN connector are directly connected to the AC OUT connector (J2), the phase line is passing through the ACS712-20A hall effect based current sensor (U4) for the purpose of current measurement. The sensor outputs 2.5 V at 0 A. When current flows between the IP+ and IP- terminals, the sensor output changes at a rate of 100 mV/A. So the output voltage becomes 4.50 V at +20 A and 0.500V at -20A. The sensor output is read by another MCP3202 and sent to the microcontroller over SPI. The ACS712 provides internal isolation so no external precaution is required for isolation.
ACS712-20A is capable of reading ±20 A. But considering the current limitations of the terminal blocks and the fuse holder, the AC current path is protected by a 16 A fuse which is connected in series to the phase line.
There are two isolated 5 V sources to power the mains and the microcontroller sides. The transformer generates 2×6 Vrms from the 230 Vrms. Each output is rectified by the bridge diodes and then regulated by the 78L05 linear regulators. D2 and D3 are the LEDs indicating the status of each 5 V.
The microcontroller of the wattmeter is PIC18F252. Basically it reads the voltage and the current and calculates the RMS voltage, the RMS current and the average power. Then it interfaces with the LCD and shows all these values. It has a hardware SPI module which lets communicating with the MCP3202 ADCs. On the other hand it interfaces to the LCD over 4-bit or 8-bit interface. The microcontroller’s master clock becomes 5 Mhz when 20 Mhz crystal oscillator is used. There is an onboard ICSP connector (J3) which is used to program the PIC.
The PCB of the project is designed in SoloPCB. SoloPCB is a pack of powerful tools consisting of schematic capture, PCB layout, and integrated autorouting.
Designing the wattmeter as a handheld device was a good idea. The outline of the PCB was drawn accordingly. Autocad was used to draw the outline and the .dxf file was imported in SoloPCB.
All the footprints which are not included in the SoloPCB libraries were created manually. They can be found in the SoloPCB design files.
The lines (phase, neutral and earth) connecting AC IN connector to AC OUT connector were drawn as thick as possible. The bypass capacitors are placed as close to the ICs as possible. Two separate ground planes are drawn for AGND and DGND to keep the ground resistance low.
All the components were placed at the top layer. An acrylic cover was planned to use as a cover for both the top and bottom layers. So the height of the bottom layer would be as low as possible.
Basically the MCU reads the voltage and the current samples every 1 ms and collects 40 sample pairs which means two periods for the 50Hz. Then calculates the RMS values and the average power. 1ms period is generated by using the Timer A module. The module runs in 16 bit mode and generates an interrupt at each overflow. So we assign a start value in each cycle and wait for the 1ms trigger.
After collecting all of the samples, the calculation processes begin. The RMS voltage is calculated by using the equation below,
The RMS current is also calculated by using the same equation.
The voltage and the current samples include the phase relation between the voltage and the current. So active (real) AC power which is V * I* cosθ can be achieved by calculating the average power by using the equation below.
Calculated RMS and power values are displayed on the LCD by using the lcd.h library of CCS C compiler.
The whole CCS C code is provided at the end of the article.
Assembly and Test
The part list of the project is given below
You can see the power consumption of a solder station while heating up below (Figure 6).
You can see another measurement below. 2KW water boiler is connected to the meter (Figure 7).
Source Code (CCS C Compiler) - download
SoloPCB Project Files (Schematic, PCB layout) - download