Current Transducer for Spark

Hey Guys did a search did not get any results. Has anyone have a recommendation of a current sensor for monitoring power consumption on an external device ( 115 volt ) with the spark core?

I am looking for a product recommendation. Thanks!

Well, these topics popped up after I searched for “current”:


and this one:

Read both ( unlike some new folks I do use the search ) first one is not very reassuring to try that particular device and the second one is for measuring DC and I am looking to measure line voltage which is 115volts AC

Thanks though.

@Herner have you seen this post:

There are a lot of ways to do this depending on what your goals are.

The old (2009) Tweet-A-Watt from Lady Ada is good reading and Newegg has the Kill-A-Watts for around US$20. You are going to be hard-pressed to engineer your own solution for that price

I have used cheap little current transformers but they can be a bit non-linear. They are great if you just want a binary indication of the device is drawing current (above some threshold) or not, and you can be very isolated from the 120VAC.

Maybe if you told us what you are trying to do we could help more?

@peekay123 great project I read it months ago but thanks for reminding me about it. I just re-read it and it will likely help me with some items on my list to knock off.

@bko You are right I am being a bit ambiguous in my description my apologies. I have a variable speed external device where I want to monitor its power consumption. It will use as few as 5 watts where it idles and as many as 80-100 watts.

Thanks all appreciate you helping me out.

@peekay123 did a bunch more reading and since my voltage will almost always be a constant your link may be what I need afterall.

http://openenergymonitor.org/emon/buildingblocks/how-to-build-an-arduino-energy-monitor-measuring-current-only

So long as EMON has been ported to spark that should do me fine.

I dug a bit this morning and this is the current sensor that I used in the past:

http://www.crmagnetics.com/Products/CR2550-P13.aspx

You can replace the LED with your own opto-isolator or use it directly. They have other solutions but this was the cheapest way to go for me in the past.

@Herner I have a Spark monitoring my house power consumption and Solar generation output and use a similar type of AC current clamp to the one typically used by the open energy monitor. They seem to work pretty well feeding the analog inputs of the Spark with a couple of analog components to shift the DC level and some filtering if you feel it necessary. The clamps I use are rated for 60 A and seem to work well down to 1A and below. I am not sure quite how linear they are but I can see the fluctuations from individual light bulbs being turned on and off so the resolution is good.

There is a 5A version which sound as though it would suit your application.

Look for the SCT-13-005 on ebay.

The advantage of a clamp is it’s isolated and relatively simple to fit. Disadvantage is it’s bulky.

Thanks @nickgb I also prefer the split core CT’s. Means you can put them on without messing with line voltage. For me size is not a big deal on THAT side of it :slight_smile: Thanks for suggesting one to try.

Are you willing to share your sketch and how you put it together? I have never used one before and am quite new to the hardware game.

Hi @Herner. This is the main code, it use it used to be in an Arduino and was my first Spark project. I can’t claim to be original as most of this is inspired by the open energy monitor. There are two current probes on A1 and A2 and a voltage reference from a 6 volt transformer (reduced down) on A0, just like the Open Energy Monitor. The method below is a reasonably straight reproduction of a covariance calculation (= real power) method from Donald Knuth Wikipedia - covariance. It is a little more complicated than some methods but has the advantage that it takes any DC offsets out of the analog inputs automatically.

You will see there is some smoothing of the results at the bottom then I put the data into a structure and share it with other devices on my Home wifi as a UDP packet.

// main calculation of RMS voltage, RMS current and real power.
// this is based on the algorithm Knuth popularised for running mean and variance calculation
// Real Power is calculated as covariance of V & I

// initialise loop variables
n = 0;
vbm = vbn = V2m = V2n = 0;
ibm1 = ibn1 = I2m1 = I2n1 = 0;
ibm2 = ibn2 = I2m2 = I2n2 = 0;
ibm3 = ibn3 = I2m3 = I2n3 = 0;
Pm1 = Pn1 = 0;
Pm2 = Pn2 = 0;
Pm3 = Pn3 = 0;
errf = 0;

while( true ){    // loop runs 
    n += 1.0;  // increment number of samples
    
    // save the last values of variables (some are needed below)
    ibm1 = ibn1; 
    I2m1 = I2n1;
    ibm2 = ibn2; 
    I2m2 = I2n2;
    ibm3 = ibn3; 
    I2m3 = I2n3;
    vbm  = vbn; 
    V2m  = V2n; 
    Pm1  = Pn1;
    Pm2  = Pn2;
    Pm3  = Pn3;

    // get the ADC values - voltage is read in the middle to minimise the phase difference between current and voltage
    data1_I = ((double)analogRead(A1))/Ical1;
    data0_V = ((double)analogRead(A0))/Vcal;
    data2_I = ((double)analogRead(A2))/Ical2;
    
    // Variance calculations remove any DC offset so are effective for RMS AC signals with no DC component
    // feed 1 is the solar feed into the house
    // feed 2 is the grid feed into the house (negative if exporting)
    // feed 3 is the sum of the other two feeds so *should* be the power used by the house.
    ibn1 = ibm1 + (data1_I - ibm1)/n;                   // Mean(I1)
    I2n1 = I2m1 + (data1_I - ibn1) * (data1_I - ibm1);  // Var(I1)*n

    ibn2 = ibm2 + (data2_I - ibm2)/n;                   // Mean(I2)
    I2n2 = I2m2 + (data2_I - ibn2) * (data2_I - ibm2);  // Var(I2)*n

    ibn3 = ibm3 + (data1_I + data2_I - ibm3)/n;                   // Mean(I3)
    I2n3 = I2m3 + (data1_I + data2_I - ibn3) * (data1_I + data2_I - ibm3);  // Var(I3)  

    vbn = vbm + (data0_V - vbm)/n;                      // Mean(V)     
    V2n = V2m + (data0_V - vbn) * (data0_V - vbm);      // Var(V)*n

    Pn1 = Pm1 + (data0_V - vbn) * (data1_I - ibm1);     // Covar(V,I1) - this is power
    Pn2 = Pm2 + (data0_V - vbn) * (data2_I - ibm2);     // Covar(V,I2)
    Pn3 = Pm3 + (data0_V - vbn) * (data1_I + data2_I - ibm3);     // Covar(V,I3)
    
    if (te <= millis()) break;
}

te += looptime1;  // time next iteration ends
  
// final calculations
Pt1 = Pn1 / n;
Pt2 = Pn2 / n;
Pt3 = Pn3 / n;
Vt  = sqrt( V2n / n ) ;
It1 = sqrt( I2n1 / n ) ;
It2 = sqrt( I2n2 / n ) ;
It3 = sqrt( I2n3 / n ) ;
            
// filtered output variables
VOut  += alpha * ( Vt - VOut );
IOut1 += alpha * ( It1 - IOut1 );
IOut2 += alpha * ( It2 - IOut2 );
IOut3 += alpha * ( It3 - IOut3 );
POut1 += alpha * ( Pt1 - POut1 );
POut2 += alpha * ( Pt2 - POut2 );
POut3 += alpha * ( Pt3 - POut3 );

// COntrol Variable for balancing energy use
EnergyBalance =  max(-1000.0, min(1000.0, EnergyBalance + Pt2 * looptime1 / 1000.0));

msg1.Bal  = (short) EnergyBalance;
msg1.Ps   = (short) POut1;
msg1.Pg   = (short) POut2;
msg1.Ph   = (short) POut3;
msg1.V    = (short) (VOut*10.0);
msg1.Is   = (short) (IOut1*100.0);
msg1.Ig   = (short) (IOut2*100.0);
msg1.Ih   = (short) (IOut3*100.0);
1 Like

Thank you for taking the time to share this! I am going to order some CT’s and give it a shot.

@nickgb I just found these ones which appears to be what you used. Am I right? If so I am going to order a bunch :smile:

@Herner Yes that’s the one. I’m using the -030 and -060 versions. You get 1 volt out for the rated current so for the -005 version 1Volt = 5A. I checked mine against a commercial clamp current meter to get calibration values (the Ical1 and Ical2 values in the code segment I posted earlier).

Having a voltage reference is useful if you want more than just current measurements. In my case with a micro generation solar system the power into the house can go negative (exporting) so the voltage reference is essential. I have a cheap home power usage meter but it is very inaccurate below 500Watts and can’t tell the difference between me selling electricity to the power company and them selling it to me. -

Thanks nick for your assistance it is really appreciated. I am going to be ordering a whack of these for my mad scientist lab.

As far as the voltage goes I am going to just code it as a constant since I will be using this on a residential grid where the power factor should stay prettty constant. Plus it will make it an easy start for me! :slight_smile: