Questions about CT on Arduino

Dear all,
I've always wanted to create my own "home" monitoring system and just discovered Arduino and your community, which is really great !!
After I've successfully worked on temperature sensors, which is not very difficult... I'm working now on monitoring current energy consumption.

So my hardware consist in an Arduino Uno and a CT sensor YHDC SCT-013-030 (30 Amps).

According to what I understood, this CT sensor has a built in resistance and then delivers tension from 0 to 1V for 0 to 30A on AC side (primary). This is different from the 100A model which does not have this burden resistance.
Anyway I'm really fighting to get an accurate 0 to 1V tension reading on the ADC of the Arduino (I choosed A0) . Here is what I understood and what I've been through these last days :

  • CT is providing an alternative (0...1V) current whereas Arduino Analog input is a 0 to 5V direct current.

  • What you suggested on the following page is to use two 10kOhms resistance to set the "0V" level at half the maximum input of the Arduino, which then is 2.5V.

  • Then my understanding is that the alternative 0..1V current will now move above and below the 2.5V input of the Arduino, from 1.5V to 3.5V at most.

  • Now I've worked on different algorithms to "read" this alternative current and find the appropriate voltage of the CT and i've several problems / questions :

First I'm using a min/max and average method to calculate the "gap" between the highest and lowest value over a sufficient period of time. Does it sound good (code is below) ?

Second, I've put my Fluke multimeter at the output of the CT to get a clear voltage reading before it goes to the Arduino, and I also have an external fluke clamp to measure AC current of the AC cable directly. So I can compare :
- Current from my external AC clamp to to my Fluke multimeter voltage of the CT : this is really accurate (I just need to multiply the voltage of the CT by 30) as both are reading exactly the same number of Amps. One good news.
- Voltage from my fluke at the CT output and the voltage read from my algorithm using Serial.print by the Arduino. It is not so bad (meaning the difference is quite acceptable) if I've got only a few device plugged but as soon as Amps are going high the difference is way too high. What's wrong?

code :

const int sensorPin = A0;
const int number_of_samples = 50;

int vmin;
int vmax;
int sampleI;
int summax;
int summin;
int jmoy;
double moymax;
double moymin;
double Vrate;
double tension;
int topdepart;

void setup()
  summax = 0;
  summin = 0;
  jmoy= 0;

  topdepart = millis();

void loop(){

  vmin = analogRead(sensorPin);
  vmax = vmin;

  for(int i = 0; i <number_of_samples;i++){
    sampleI = analogRead(sensorPin);

    if (sampleI < vmin)
      vmin = sampleI ;

    if  (sampleI > vmax)
      vmax = sampleI ;


  summax += vmax;
  summin += vmin;

  if(millis() >= (topdepart+1000)){

    moymax = summax / jmoy;
    moymin = summin / jmoy;

    Vrate = (moymax - moymin) / 2.0;
    tension = Vrate * 5000.0 / 1024.0;


    topdepart = millis();
    jmoy = 0;
    summax = 0;
    summin = 0;







Robert Wall's picture

Re: Questions about CT on Arduino

Why don't you use one of our sketches on Github that use the emonLib library. Those can give you the genuine rms current. "rms"  (root mean square) is the value everybody uses for power measurements. Your Fluke, if it is an expensive one, will be reading rms; otherwise, it will be reading the rectified average but scaled to indicate the rms value for a pure sine wave.

I'm sorry, but the answer to "Does it sound good (code is below)" is no. The rms value of an alternating wave is the value that gives the same heating effect in a resistor (example: a water heater) as a direct current of the same value. For example, a motor car light bulb supplied with 12 V rms ac will be the same brightness as when it is supplied with 12 V dc. The shape of the alternating current wave is not necessarily a perfect sine wave, and measuring the distance between peaks of opposite polarity will not give you an accurate measure of the heating effect of the current.

littlepanda's picture

Re: Questions about CT on Arduino

Hi Robert,

Thanks a lot for your answer. I've worked on your Emonlib library and in fact didn't really understand why you used RMS, now I do thanks to your explanation. And you're right my fluke is quite an expense one and is providing I think RMS value by default, since I have an option to display also min/max and average values.

One thing though, can you confirm it is not necessary to use diode to convert alternative current from the CT to direct ? You're not doing this thanks to your RMS algorithm or is there any other reason?

many thanks


Robert Wall's picture

Re: Questions about CT on Arduino

You must not have any rectification outside the software, it is all done internally. And in any case, you would take away the ability to know the direction of power flow - which you can have if you also have a voltage reference signal.

I can see why you are asking this, I think you need to study the sketch and the library (and the mathematics!) to see how we process the signal.  Here's a very quick overview that should be enough to get you going:

We sample the current, about 110 times per cycle (@ 50 Hz, less at 60 Hz). As it comes in, the wave is centred on 511 or so. We use the present value and the one before to run a high pass filter on the numbers - this restores the wave so that it's centred about zero. Then we square the values and add them (this is where it gets rectified), and after the preset (and large) number of samples, that hopefully spans a complete number of cycles so we don't get any 'end effects', we divide by the number to get the mean, then take the square root.

littlepanda's picture

Re: Questions about CT on Arduino

Hi Robert,

Thanks a lot for all your answers. I did understand the square average thing, but I did not know the high pass filter methodology which is really great indeed.

Now thanks to you and your library it works fine !

have a good day



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.