Hardware

Measuring Current

There are two ways I am willing to entertain for measuring current. One is via a current transformer and the other vial hall effect.

I combed the web to look for affordable devices in North America. It seems that Europe has access to cheaper current transformers.  I ended purchasing three  (3) current transformers and two(2) hall effect chips.

Two (2) revenue Grade Current Transformer Two from CR Magnetics to install on each side of my 200A pannel per each side  (CR8459-2000-N)

One (1) general purpose 0-20A for experimentation CR Magnetics  (CR8410-1000)

Two (2) Hall effect bases chips from Allegro ACS712ELCTR-20A-T

I ordered on-line via Digi-Key and found to have an excellent customer experience. I opted for one stop shopping for other goodies such as zigbee chips and other odds and ends. I also wanted something Canada friendly so I picked a place that operates in both Canada and US.

I entertained the idea of spit-core transformers to facilitate wrapping around the wire. I could not find some at a cheap rate and figured some higher quality ones could be used for permanent installation. I’ve done enough wiring to feel comfortable inside the panel box. I would not recommend venturing in high voltage areas without a good understanding what can harm you. Get an electrician to wire those if you have any doubts.

Measuring Voltage

I have a bunch of AC transformers lying around so I plan on using those to measure the AC voltage.  120:10 volts p-p will do as that is all I have in stock.

Embedded System
I entertained the idea of using a multi-tasking OS such as The FreeRTOS Project and finding a board to host it. The KISS principle forced me to focus on deploying hardware to perform specific tasks and avoid creeping elegance. I only want a device that at will feed into the mesh network. No sense over engineering things. I can use the FreeRTOS for a data concentrator later on. There were many choices out there e.g.  PIC and Micromint. I opted for simplicity and went with the Arduino Duemilanove.

I purchased my Aduino from spikenzielabs along with the following to help me get ball going.

  • Arduino Duemilanove w/ Atmega328
  • XBee Explorer USB
  • Adafruit Proto Shield for Arduino
  • Basic 16×2 Character LCD – White on Black 5V
  • Breakout Board for XBee Module

power parts

Time to plug things in and see what happens.

Discrete Time Equivalents

Earlier I spoke about modeling the math to simulate the calculations that I will be using in my home grown energy monitoring system. I think I have a good enough grasp on the math to come up with the algorithm to use in the software. Specifically, the computation of RMS values and average power.

P_{avg} = \frac{1}{N}\sum_{n=1}^{N}v_ni_n \approx \frac {1}{T}\int^{to+T}_{to}p(t)dt \qquad(1) X_{rms}= \sqrt{\frac{1}{N}\sum_{n=1}^{N}x^2_n} \approx \sqrt{\frac {1}{T}\int^{to+T}_{to}x^2(t)dt} \qquad(2)

The simulation implemented both these and the integration functions to compare results. We are dealing with low frequency power line signals of 60hz which in theory we need to sample at 120 times per second. The reality is that there will be higher frequency components such as harmonics and we would need to sample at a higher rate capture those effect and ensure we can compute true RMS values.

Don Lancaster’s Tech Musings provides an excellent summary about measuring power s and pitfalls in trying to measure it.

I think I have enough theory and now ready to start building something.

Modeling the Math

I used Excel to enter the power calculations on a simulated data set (voltage and current). I later wanted something more responsive to what-ifs and designed for mathematical computation. I stumbled on a MatLab like open source tool cal GNU-Octave. I decided to download and install the tool to enter basic power calculations.

What I like about this tool and like Matlab is the ability to manipulate matrices and vectors. I can set up calculations for my power without resorting to annoying for loops. With my short attention span, I liked this.

Earlier I described the basic math and reduced the following salient equations:

P_{avg}=\frac {1}{T}\int^{to+T}_{to}p(t)dt\qquad(1) I_{equiv}=I_{rms}=\sqrt{\frac {1}{T}\int^{to+T}_{to}i^2(t)dt} \qquad(2) P_{avg} = V_{rms}I_{rms}cos(\Theta_v-\Theta_i) \qquad(3))

For giggles, I wanted to use Octave to calculate and plot power curves. I know from sampling theory that we need to sample at least at the Nyquist frequency to be able to reconstruct the signal.The reality is we don’t live in an ideal world with perfect filters. More about sampling rate later.

I created functions in Octave to generate a waveform. I can also import a text file with data values and compute the various types of powers as well. I wanted to test a couple of sunny day scenarios to ensure that my calculations were correct. I took two approaches. One I actually defined the function and let Octave integrate it. The other was to sample the function like I would in the software. Both yielded the same results. The table below outlines the expected and actual results.

Package/ToolURLDescriptionInstallation
log4jslog4jslog4js based logging services for node.jsnpm install log4js -S
monkmonkwrapper to mongodb that is simpler yet not as powerful as mongoosenpm install monk -S
nodemonnodemonlistens for file changes and restarts server npm install nodemon -g
dummy-jsondummy-sontool to generate JSON files used for my testingnpm install dummy-json -g
RobomongorobomongoMongoDB managerdownload and point to mongoDB instance (default localhost:27017)
Bluebirdbluebirdpromise library implementationnpm install bluebird -S
SerialPortserial portserial port driver for node.jsnpm install serialport -S # have 4.0.7
xbee-apixbee-apixbee API for node.jsnpm install xbee-api -S

I also generated an odd current waveform that could occur in speed control via a triac or something and ploted the graph below.

SCR

Intuitively one would expect the average power to be half of the sunny day scenario. The other half is reactive power. The following shows the power calculations for varying sampling rates.

[table “3” not found /]

Steady State Power Analysis

I wanted to brush up on the theory before I jump to the implementation. So back to basic circuit analysis.

Instantaneous Power
In a steady state system, the voltage and current as a function of time consists of

v(t)=V_{max}cos(wt + \Theta_v) \qquad(1) i(t)=I_{max}cos(wt + \Theta_i) \qquad(2)

where \Theta_x is is the phase angle of the voltage and current respectively

The instantaneous power is defined as
p(t)=v(t)i(t)=V_{max}I_{max}cos(wt + \Theta_v)cos(wt + \Theta_i)\qquad(3)

Using some trigonometry, (3) reduces to
p(t) = \frac{V_{max}I_{max}}{2}[cos(\Theta_v-\Theta_i) + cos(2wt + \Theta_v + \Theta_i)]\qquad(4)

(4) shows that the instantaneous power has a constant or DC component and a time-variant component and illustrated below.  (v=1, i=1, \Theta_v=\Theta_i=0)

inphase

Note the average component “the DC offset” and the frequency of the instantaneous power is two times that of the voltage or current.

We can compute the average power by integrating (4) over one period. We get

P_{avg}=\frac {1}{T}\int^{to+T}_{to}p(t)dt\qquad(5)

If one substitutes (4) into (5), (5) reduces to P=\frac{1}{2}V_{max}I_{max} in a purely resistive circuit and P=\frac{1}{2}V_{max}I_{max}cos(90^\circ) assuming a sinusoidal waveform.

RMS Values
In the power measurement solution for home, one can assume purely resistive loads and sinusoidal voltages and currents. That will come at the price of accuracy. The reality loads such as computers, UPS, etc. introduce inductance and capacitance which create loads that are neither purely resistive nor purely reactive. Furthermore, the current and voltage profiles are not clean sine waves.

Recall that the average power absorbed by a purely resistive load using a sinusoidal source was P_{avg}=\frac{1}{2}V_{max}I_{max}. Note that if the source was a DC, then P_{avg}=I^2R What if the source is not a sinusoidal wave? Is there an equivalent constant current that can be computed that delivers the same average power to a purely resistive load (R)? .e.g. P_{avg} = I^2_{equiv}R =\frac {1}{T}\int^{to+T}_{to}i^2(t)Rdt solving for I_{equiv} we get

I_{equiv}=I_{rms}=\sqrt{\frac {1}{T}\int^{to+T}_{to}i^2(t)dt} \qquad(6)

Plug in in a sinusoidal current like i(t)=I_{max}cost(wt + \Theta)\quad T=\frac{2\pi}{w} into (6) we get the infamous I_{rms}=\frac{I_{max}}{\sqrt{2}}

Given this view of the RMS current, one can write the average power as

P_{avg} = V_{rms}I_{rms}cos(\Theta_v-\Theta_i) \qquad(7)) In the North-American 120 volt system, the 120 is the RMS voltage and V_{max} = 120\sqrt{2}\approx 170V

For non-sinusoidal functions, more complex integration needs to occur. Fortunately, in the implementation, there are some assumptions we can make to approximate the integration that makes the math much simpler. Nevertheless, an understanding of the math is needed to bend the rules.

Power Factor
One last component needs to be addressed and that is the power factor. Equation (7) contains two components. The product of V_{rms}I_{rms} is known as the Apparent Power (S) and the cos(\Theta_v-\Theta_i) as the Power Factor.

In an purely resistive circuit, P_{avg}=P_{apparent} since cos(\Theta_v-\Theta_i) = 1

Moving Forward

The reference implementation shall compute the average power, Irms and Vrms. Using (7), one can compute the power factor. e.g. \frac{P_{avg}}{V_{rms}I_{rms}} = PF

The power factor angle = arccos{\frac{P_{avg}}{V_{rms}I_{rms}}}   The reactive power can be computed by the relation S^2 = P^2_{avg} + Q^2 where Q is the reactive power in vars. Solve for Q and we can now compute all power related components.

Now you may ask why the Power Factor Angle? We don’t even reference it? Well, you could use to compute the reactive power. What it does give me is sense of the types of loads I have in the house. A value closer to 0, implies I am operating in a resistive load. If you look at the power factor angle of a variable speed drill, at low speeds the angle would be far from zero. At full RPM the angle would approach zero. Why this is the case is because how variable speed drills work. That is a separate discussion.

Next I want to model the math using a tool to help me make some assumptions for my reference implementation.

Home Power Monitoring

Back in the day I used to read Byte magazine and faithfully read Steve Ciarcia’s articles. I went down a career path that did not include much in terms of pure engineering and left it as a distant memory. I recently decided it was high time to renew my hobby in tinkering with electronics and software. Fortunately, Steve is still around at Circuit Cellar with a group of dedicated writers willing to share their experiences with their readers.  I will never make a living in designing electronics and embedded systems nor do I want to. As a hobby, good enough is good enough for me.

My first project will be home power monitoring. The end-goal is to install solar modules on the roof and I would like to trend environmental information both inside and outside of the home so I can baseline my power consumption profile. True one can purchase technology to measure power but where would the fun be in that? 

Functional Requirements

Real-time Information
RMS current, RMS voltage, power factor, power factor angle, apparent power, real power, reactive power

Temperature – this will be a separate project to measure external and internal temperatures throughout the home. I felt that adding a temperature measurement  is trivial and will not add too much complexity to the project.

Historical Data
Average, Max, Min, Median of real-time data derived from data historian

Communications
Over mesh network at home. I want to include other devices around the house from which all data aquistion will be collected by a data concentrator. Not sure what the data concentrator will be at this point.

Human Machine Interface
Simple LCD to display real-time information at the point of measurement

Web and iphone viewing of near-real-time and historical data.

Technology
Do as much work using open source software.

Utilize an affordable and easy to use embedded system so that my kids might take interest in learning electronics and interfacing

Well off to the races I go.