YHDC SCT-013 100a:50mA

Hello everyone, I'm having a trouble on using the SCT-013 100:50mA current sensor, can you give me sample code on how to properly use this kind of sensor?

Thank you.

1: Show a schematic of your project
2: Show the full code of the best attempt you have so far
3: Describe in detail what is not going the way you intend it to.

Once all of the above is present, assistance may be possible.

If you don't want to do 1 - 3, then I would recommend the Paid Jobs & Consultancy forum where you can pay someone to do the project for you.

currently I am using this code with my ADS1115 16 bit version

#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads(0x48);

const float FACTOR = 50;
const float multiplier = 0.0625F;

void ImprimirMedidas(String prefix, float value, String postfix);

void setup()
{
Serial.begin(9600);
ads.setGain(GAIN_TWO);
ads.begin();
}
void loop()
{
float CorrienteRMS = getCorriente();
float Potencia = 220.0 * CorrienteRMS;
ImprimirMedidas("Irms: ", CorrienteRMS, "A ,");
ImprimirMedidas("Potencia: ", Potencia, "W");
}

void ImprimirMedidas(String prefix, float value, String postfix)
{
Serial.print(prefix);
Serial.print(value, 3);
Serial.println(postfix);
}

float getCorriente()
{
float voltage;
float corriente;
float sum = 0;
long tiempo = millis();
int counter = 0;

while (millis() - tiempo < 1000)
{
voltage = ads.readADC_Differential_0_1() * multiplier;

corriente = voltage * FACTOR;
corriente /= 1000.0;
counter = counter + 1;

}
corriente = sqrt(sum / counter);
return (corriente);
}

#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads(0x48);

const float FACTOR = 50;
const float multiplier = 0.0625F;

void ImprimirMedidas(String prefix, float value, String postfix);

void setup()
{
  Serial.begin(9600);
  ads.setGain(GAIN_TWO);
  ads.begin();
}
void loop()
{
  float CorrienteRMS = getCorriente();
  float Potencia = 220.0 * CorrienteRMS;
  ImprimirMedidas("Irms: ", CorrienteRMS, "A ,");
  ImprimirMedidas("Potencia: ", Potencia, "W");
}

void ImprimirMedidas(String prefix, float value, String postfix)
{
  Serial.print(prefix);
  Serial.print(value, 3);
  Serial.println(postfix);
}

float getCorriente()
{
  float voltage;
  float corriente;
  float sum = 0;
  long tiempo = millis();
  int counter = 0;

  while (millis() - tiempo < 1000)
  {
    voltage = ads.readADC_Differential_0_1() * multiplier;

    corriente = voltage * FACTOR;
    corriente /= 1000.0;
    counter = counter + 1;
  }
  corriente = sqrt(sum / counter);
  return (corriente);
}
1 Like

Ok, you're using the ADS1115 in differential mode. Can you show the schematic diagram of your full setup?
Also, what is not going according to plan?

(Do you really have 220V where you live? I thought we had all moved to 230V by now...?)

PS: nice of you to include the code tags in your later post :slight_smile:

2 Likes

I just follow this diagram sir/ma'am
image
and base on the code I uploaded, the recorded data is always zero.

1 Like

if you do a web search for SCT-013 you will get plenty of links showing how to connect it to a microcontroller and sample code

I used an arduino nano with three 100amp SCT_013 Current clamps to monitor three phase grid usage, e.g. showing overnight consumption

I have a Tesla Powerwall and solar panls so minimal grid use thru the day - at midnight the Powerwall starts charging and night storage heaters switch on

AFAIK the SCT013 does not have a I/V resistor built into it, although your schematic does show it. The datasheet however only shows a TVS diode.


this will be the result when I started the program and the sensor.

connection in current sensor
image

I tried many times on the other sample codes yet the initial record has a value., and only this code I uploaded has presented "0" as its initial value. yet I dont understand why is it not responding when I uses the SCT-013-000 sensor

Hello sir, can you show me the diagram and sample code on your setup if you allow sir? thanks

I used a circuit similar to sct-013-030-to-measure-watt to offset the SCT-100 ground with 10Kohm resistors - this gave me a sinewave around approximatly 2.5V
code for 3 phase device is

// use a SCT-013 current clamp

// the signal is AC so a potential divider to 5V pin  is used to offset the voltage 
//  the 5V pin read 4.7V 

#include <math.h> 
#define CURRENT  100.0     //  ***** clamp current rating
#define SAMPLETIME 30000UL   // sample time in mSec

int analogPin1 = 2;     
int analogPin2 = 4;     
int analogPin3 = 6;     

//float val = 0;           // variable to store the value rea
unsigned long oldMillis = millis();

void setup()
{
  Serial.begin(115200);          //  setup serial
  Serial.print(CURRENT);
  Serial.println(" amp current sensor");
  oldMillis = millis();
 }


void loop()
{
  static float ave1=0, ave2=0, ave3=0, peak3=0;;
  static long int count=0;
  int timeout= (millis()-oldMillis) > SAMPLETIME;
  count++;  
  float rms1=readcurrent(analogPin1, &ave1, count, timeout);
  float rms2=readcurrent(analogPin2, &ave2, count, timeout);
  float rms3=readcurrent(analogPin3, &ave3, count, timeout);
  // the PC looks for a line starting with > 
   if(timeout) { 
      oldMillis = millis();
      Serial.print(">");             // for file
      Serial.print(rms1); 
      Serial.print( " ");             // for file
      Serial.print(rms1*.24); 
      Serial.print(" ");             // for file
      Serial.print(rms2); 
      Serial.print( " ");             // for file
      Serial.print(rms2*.24); 
      Serial.print(" ");             // for file
      Serial.print(rms3); 
      Serial.print( " ");             // for file
      Serial.println(rms3*.24); 
      count=0;
 }
}

float readcurrent(int analogPin, float *ave,  long int count, int print)
{
  // read analogue input pin
  int analogue=analogRead(analogPin);
  // convert to volts (it is a 10bit ADC to offset is 511)
  float val = ((analogue-511)/1024.0)*4.7;    // read the input pin (5V pin is actually 4.7V)
  if(fabs(val) > 0.01) *ave=*ave+(val*val);                         // square for RMS and add to average                                 // increment sample count
//  float val2=val;//=fabs(val);
//  if(val2<0.0)val2=-val2;
//  if(val2>(*peak))(*peak)=val2;
  if(print) {
      float rms = sqrt(*ave/count) * CURRENT;//-1.2;  // calculate RMS 
      Serial.print("ADC ");             // debug value
      Serial.print(analogPin);             // debug value
      Serial.print(" ");             // debug value
      Serial.print(analogue);             // debug value
      Serial.print(" val ");             // debug value
  //    Serial.print(((analogue-511)/1024.0)*4.7);             // debug value
     // Serial.print(" ");             // debug value
      Serial.print(val*1000);             // debug value
      Serial.print(" ave ");             // debug value
      Serial.print(*ave);             // debug value
      Serial.print(" count ");             // debug value
      Serial.print(count);             // debug value
      Serial.print(" current ");             // debug value
      Serial.println(rms);             // debug value
  //    Serial.print(" peak ");             // debug value
  //    Serial.println((*peak)* CURRENT*0.707);             // debug value

      *ave=0;
      oldMillis = millis();
      return rms;
  }
 // else delay(20);
}

I have checked the SCT-100 results using a clamp current meter and readings are within a couple of amps w

photo showing configuration

the three current readings are sent over USB to a PC program which plots the results

hello Horace, thank you for sharing., I will try to refer on your code for my project which I am using only one SCT-013-000/100A:50mA version. I am trying to measure our line current in our house with a configuration of line to ground (230Volts-0Volts) single phase.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.