ArduinoComm

ArduinoComm is used for all the basic sensor setups as the first step on the computer side to read the data coming in from the arduino and output it to terminal for viewing. You may need to change a few lines of code to get this to run with your configuration, Ive detailed how the program works and the important lines that you may need to change below.

Running ArduinoComm

  1. Download the ArduinoComm java program here.
  2. Unzip ArduinoComm.tar.gz
  3. Compile the program by typing $ javac *.java
  4. Run the program with $ java Program

For a 'How to' on compiling and running java programs have a look here. (It also details installation of rxtx library)

If its all working you should see something like this appear in your terminal window (assuming the arduino is sending 5 different data types labeled A to E - more details below)

128.43 153.25 0.84 242.62 0.63
126.76 151.31 0.84 243.17 0.62
128.24 153.42 0.84 242.9 0.63
....

You can then write these values to a file by running the program with $ java Program >filename.dat

This file can then be opened in real time by KST for graphing which is detailed here.

How ArduinoComm works

In the ArduinoComm folder there are two files:

Program.java contains the all important public static void main(String args[]).

ArduinoComm.java is were everything really happens. 

Lets say our arduino sketch is calculating real and apparent power and we want to send these values to the computer for logging.

On the Arduino we need to enter:

realPower = 100.0

apparentPower = 200.0

Serial.print(realPower);
Serial.print("A");
Serial.print(apparentPower);
Serial.print("B");     

In ArduinoComm.java in the serialEvent method just underthe line    double value = Double.parseDouble(rawStr); we need:

if (ch=='A') System.out.print(value+" ");
if (ch=='B') System.out.println(value+" ");

This will give an output in terminal of the form:

100.0 200.0

Say we now wanted to add another value, say powerFactor.

We add to the arduino sketch

Serial.print(powerFactor);
Serial.print("C");     

and in ArduinoComm.java

if (ch=='C') System.out.println(value+" ");

our terminal output will now look like this:

100.0 200.0 0.5

ArduinoComm's default setting is to recieve 5 unique data values from A to E but you can add and subtract as many as you need for your application.

For further detailed description of how ArduinoComm works the code is annotated or please comment with any questions.

Hi Chaps, Have you given any

Hi Chaps,

Have you given any thought to using "zero-crossing-detection" to facilitate power-factor recording ?

I have been doing some work on just such a system, and have only recently come across the Arduino ( and your site )

Cheers, Charles

Hi Charles, I'm busy with a

Hi Charles,
I'm busy with a similar project and "zero-crossing" was suggested by someone to measure frequency, but not power.
Do you have a cct diagram for such a circuit that will work with the Arduino's 0-5V input maybe?
Thanks,
dubbleUJay

Hello Charles and dubbleUJay,

Hello Charles and dubbleUJay, Thanks for the suggestion Charles. I have been using zero-crossing detection on the voltage signal to measure frequency but haven't tried to use it to measure power factor. I think it might be challenging however since the current signal is often much less sinusoidal and so the point at which it crosses zero isn't so "clear" as the voltage signal. I tried to measure the frequency from the current signal and found that that was a problem.
Ive been measuring the voltage signal with a step down AC to AC transformer recently and then calculating the power factor by dividing the real power by the apparent power, seems to be working nicely, need to document it next and put it up here :)
Trystan

Hi Trystan, I was thinking of

Hi Trystan, I was thinking of using the zero-crossing of the current waveform and the voltage-waveform, then measuring the time diffrence - is fairly simple to then calculate the power-factor. On smaller loads, like switching power-supplies or "CFL" lights, the power factor is not nearly as important as with larger loads. I have some experience with power-factor-correction at installations like saw-mills and the like ( 500 KVa supply ). Charles

Measuring the power factor

Measuring the power factor with the Arduino is not that easy. The zero crossings must be measured with the current to the load as well as the voltage across the load. If the voltage is stepped down through a transformer, it will introduce a phase shift of unknown value. So you need to be able to measure and then correct for the introduced phase shift. Or use a resistive voltage divider which then introduce high (line) voltages into your project. For household purposes the power factor is near to 1 and I believe can be safely ignored.