Interfacing CT sensor with electric imp

I am trying to interface the CT sensor YHDC SCT-013-030 to electric imp 001. I am trying to measure current drawn by a refridgerator (inductive load) and then calculate apparent power consumption. I am having problem in converting the output voltage of the CT to correct value of RMS value of current. The approximate value that I should be getting is 2A. But right now I am getting Irms value as 130mA or so. I am using a burden resistance of 23 ohms and my current calibration constant is 100. I am not sure whether my calibration is incorrect or calculations of Irms. I am using arduino code as reference with emon library as given on Please help.

`ADC_COUNT <- 65536;
ICAL <- 100.0;
offsetI <- ADC_COUNT>>1;
sampleI <- 32768;
filteredI <- 0.0;
sqI <- 0.0;
sumI <- 0.0;

function samplesReady(buffer, length)
server.log("buffer " + length);

    for(local i = 0; i < length; i=i+2)
        sampleI  = buffer[i+1]<<8;
        offsetI = (offsetI + (sampleI-offsetI)/65536.0);
        filteredI = sampleI - offsetI;
        sqI = filteredI*filteredI;
        sumI += sqI;
    local IRatio = ICAL * ((hardware.voltage())/65536.0);
    local Irms = IRatio * math.sqrt(2*sumI/length);
    sumI = 0;
    server.log("RMS value of current" + Irms);

function stopSampler()
buffer1 <- blob(2000);
buffer2 <- blob(2000);

hardware.sampler.configure(hardware.pin1, 1000, [buffer1, buffer2], samplesReady);

imp.wakeup(10, stopSampler);`

Need to determine if the problem is hardware or software.
Can you insert this immediately after the for loop server.log ("s="+sampeI+",l="+length);

typo fix from above.
server.log ("s="+sampleI+",l="+length);


Thank you for replying. I inserted the log command after for loop. Below is the log that I recorded when I passed a live wire (single phase) through the CT. Right now, I am stopping the sampler after 10 seconds but if I keep sampling after a certain interval, I get similar values.

2015-08-05 16:29:57 UTC-4 [Status] Device connected
2015-08-05 16:29:58 UTC-4 [Device] s=14035, l=2000
2015-08-05 16:29:58 UTC-4 [Device] RMS value of current 154.109
2015-08-05 16:29:59 UTC-4 [Device] s=24822, l=2000
2015-08-05 16:29:59 UTC-4 [Device] RMS value of current 154.00143
2015-08-05 16:30:00 UTC-4 [Device] s=36953, l=2000
2015-08-05 16:30:00 UTC-4 [Device] RMS value of current 154.0906
2015-08-05 16:30:01 UTC-4 [Device] s=60254, l=2000
2015-08-05 16:30:01 UTC-4 [Device] RMS value of current 154.619
2015-08-05 16:30:02 UTC-4 [Device] s=65535, l=2000

Another thing is when I have a neutral passing through the CT, there should be bo current flowing, so the RMS value of current should be very close to 0. But that is not the case. I get a value like 98-110 for neutral wire. I have attached the circuit that I am using.
I know that my circuitry is correct because I have an LED in series with my burden resistance. So the LED glows when I am testing live wire and doesn’t glow in case of neutral. So I think something wrong with the using the sampler or logic of calculating RMS value by centering the signal around 0 counts.

This is the circuit I am using

Is this the Arduino library you mentioned?

Note that the first problem is your circuit, which is biasing the input to 2.5v (5v divided by 2). You should connect the top of the 10k resistor divider to the imp’s 3.3v supply, so that the input is biased to 1.65v (3.3v divided by 2) otherwise your waveform won’t be balanced.

You may need to adjust the 23 ohms to reduce the swing too (15 ohms is a good first guess, as 3.3/5.0 * 23 ~= 15.

OK I do not know this sensor or the measurement techniques, so these comments may not make sense or may not be worth anything: but anyways:

  1. I do not think you can put a LED in series with the burden resistor because this is an AC domain circuit. The LED is a diode and will only allow current to go through the circuit one way, and I think it will affect the behavior by changing it to DC. As well, the LED only conducts when the source voltage gets above 1.2-1.5 volts and in this circuit that will make things even worse.
    2)The server.log looks funky to me. the AD count seems to only increase and never drop out. After three seconds is was at 65535. This may be related to Hugo comment, but only if the current flow was in the top of the sensing range. I would have expected that ‘sampleI’ would come to some value and stay there. Its almost like ‘sampleI’ never gets cleared or reset. (see #1 and #4)
  2. For 120 VAC appliances (stuff you can plug in) the current goes out on the HOT (black wire in NA) and returns on the Neutral (white in NA). So it should not matter which wire is being sensed. The only wire without current under normal operation is the ground wire. If in fact your wiring has the power going out on HOT and NOT coming back on NEUTRAL then there must be a MAINS AC wiring issue that scares the pants off me. PLEASE BE CAREFUL!
  3. Because this is AC, I think your code should be trapping the maximum AD value reading over several seconds. If you average an AC wave over a long period, it should come out to 0.00 or, if the circuit is fixed as per @Hugo comments, 1.65 volts/32768 (give or take when you started and stopped averaging based on the voltage waveform) . Off hand your code looks like it averages over 2000 samples. I do not think this technique will work.

Anyways, these are just my offhand comments. Which may not be worth anything at all.

(edited for poor grammar)

Hi Hugo,

Thank you for pointing out the bias input. I changed it to 3.3V and it works perfect for the live wire. I am able to measure the 2.3A current. But I still am not getting a near zero value for the neutral wire. Infact the reading is around 1.8A for the neutral. I still have to check both readings for other loads. But thank you so much for pointing out this mistake. As for the burden resistance calculation, I had considered the reference voltage as 3.3V and got the value as 23ohms (for 5V reference, the value comes to 33ohms).Reference calculations as below in case anyone wants to refer:-

Burden resistance = (Aref * Number of turns of CT)/(21.414max primary current)
= (3.32000)/(21.41*100) giving 23 ohms.


The link you shared I think is for measuring both current and voltage. I am using the current only methos and the link is