Power Logger Source Code Guide

The Continuous Power Monitor program shares the same base source code and program structure as the Power Sampler program. The overall program structure is described here. Below is a description of how the continuous power monitor program works.

Arduino Sketch

Reading in data

The Arduino reads instantaneous voltage and current values over a second processing them into a collection of useful data values (detailed below), this collection of data values is then sent to the computer once a second. We will call this collection of data values a packet.

A packet contains one value of each of the following 10 data types:

Type Number, Type Name, Identifier

0 Real Power A
1 Apparent Power B
2 Power Factor C
3 Frequency D
4 Vrms E
5 Irms F
6 peakV G
7 peakI H
8 time1 I
9 time2 J

The capital letter on the right is called the identifier.
The identifier is used to identify the type of the values as they are read in from the serial connection.

For example a typical serial read out would be:

...100A200B500C...

The numbers left of the letter belong to the letter.
In the above case A is Real Power and therefore Real Power = 100W
B is Apparent Power and therefore Apparent Power = 200W
C is Power Factor,

Power factor was scaled up by 1000 on the Arduino in order to keep the transmitted value an integer and so we need to divide the recieved value by 1000 to give us the correct value for power factor and so Power Factor = 0.5

Storing the data values in an array

Once a data value is recieved the value is stored in an array. The program has 10 data value arrays an array for each data value type. Each data value's position in its array is defined by its packet number. Were packet number 0 corresponds to the first data packet recieved.

A data value in one of these data arrays is therfore defined as:

Data.value[typeNumber][packetNumber]

We then use the data stored in these arrays for graphing.

Graph Output

For example if we wanted to graph real power versus time. Real power (data type 0) is our y axis. Time (data type 9) is our x axis.

for (packetNumber 1 to totalNumberOfPackets)
{

x1 = Data.value[9][packetNumber-1];
y1 = Data.value[0][packetNumber-1];
x2 = Data.value[9][packetNumber];
y2 = Data.value[0][packetNumber];

Draw.line(x1,y1,x2,y2);
}

And that completes a initial rough guide to the process of reading, storing and outputing the data. I hope to improve on the source code description as time goes on, adding examples and tutorials on the various key parts like reading data from the Arduino and Graphing.