SCT013-30A/V with ESP12-F

Hi everyone, I am using ESP 12 in combination with ADS1115 and SCT013 transformers to measure the power of AC appliances, but there seems to be some problems with my circuit diagram and code.
Could anyone please give me some advice? (2 sensors connecting to PC)
Circuit:
image
Result:
image

Code:

#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads;

const float ADC_BITS = 32768.0; 
const float GAIN_VOLTAGE = 2.048; 
const float MULTIPLIER = GAIN_VOLTAGE / ADC_BITS; 
const float SENSOR_SENSITIVITY = 1.0 / 30.0; 
const float RESISTOR = 22.0; 


const float FACTOR = MULTIPLIER / (SENSOR_SENSITIVITY * RESISTOR); 

void setup() {
  Serial.begin(9600);
  ads.setGain(GAIN_TWO);
  ads.begin();
}

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

void loop() {
  float currentRMS1 = getCurrentRMS(0); 
  float currentRMS2 = getCurrentRMS(1); 
  float power1 = 110.0 * currentRMS1; 
  float power2 = 110.0 * currentRMS2; 

  printMeasure("Sensor 1 - Irms: ", currentRMS1, "A ,");
  printMeasure("Sensor 1 - Power: ", power1, "W");
  printMeasure("Sensor 2 - Irms: ", currentRMS2, "A ,");
  printMeasure("Sensor 2 - Power: ", power2, "W");
  delay(1000);
}

float getCurrentRMS(int channel) {
  float sum = 0;
  int counter = 0;
  long startTime = millis();

  while (millis() - startTime < 1000) {
    int16_t adcReading;
    if (channel == 0) {
      adcReading = ads.readADC_SingleEnded(0);
    } else if (channel == 1) {
      adcReading = ads.readADC_SingleEnded(1);
    }
    float voltage = adcReading * MULTIPLIER; 
    float current = voltage / RESISTOR; 

    sum += sq(current); 
    counter++;
    delay(1); 
    yield(); 
  }

  float rms = sqrt(sum / counter); 
  return rms;
}

Welcome, C_C, to the OEM forum.

I can see a few things wrong with your circuit, but my first question is, are you sure you are using the right ADC? The ADS1115 has a maximum sample rate of 860 samples per second, so even if you’re in the 50 Hz world, you’ll only get 17 samples of current per mains cycle, which is just about OK provided you don’t expect an accurate reading from nasty things like fluorescent or LED lamps and you don’t want to measure both circuits at the same time. If you’re in the 60 Hz world, it’s even worse.

The second problem is your c.t. already has a burden resistor inside, the output is 1 V for 30 A input, so you don’t want the 22 Ω burden resistors.

The third problem is you’re dividing the voltage down to roughly a third with R11 & R12, why? Your 1 V rms is less than 3.3 V peak to peak, so there’s every reason not to attenuate the c.t’s output to promptly (possibly) amplify it again with the PGA setting inside the ADS1115. And worse - the attenuator (R11 & R12) is referenced to GND, so you’re shifting the quiescent input voltage downwards. This is bad.

For a somewhat complicated reason concerning unwanted interference, I’d suggest you instead adopt the circuit arrangement we use in the emonTx4:

Again, you should not have the 33 Ω burden resistor because it is incorporated inside your c.t., and “Arduino input” goes to your “AIN0” etc. And of course you use your 3.3 V supply and not 5 V as shown for the Arduino. You end up with the c.t. and just 3 components, the two 10 kΩ resistors and the 10 µF capacitor, per channel.

Now looking at the software and its relationship to the circuit, the bias resistors (R1 & R2 in my diagram, R13 & R14 in yours, apply a fixed d.c bias to the input signal
to the ADC, so the ADC output is a fixed voltage, 1.65 V when you’ve changed to the circuit I suggest, with the (varying) alternating voltage from the c.t. superimposed on top, as illustrated. You need to remove this fixed component in the maths - and I can’t see where you do this. My favoured method is to take the ADC reading and subtract the nominal half-scale offset that the bias has put there (nominally 2048 for you, if full-scale is 4095), simply to keep the numbers small. Then you accumulate over the measuring period two values - the sum of all the readings and the sum of all the readings squared. You can then do the maths to get the rms value of the input minus the offset:

The rms value of a signal plus an offset is √(signal² + offset²).

At the end of the measuring period, you have accumulated two values, (signal+offset)² and the offset (what’s left after you subtracted the bias value - ideally it will be zero but in practice it never is). So do the maths to get signal² and hence signal - the rms value which is proportional to the current and is the current in amperes when you apply the correct scale factors. You should do the minimum maths inside the loop: for each sample subtract the nominal offset, accumulate the samples and samples². When you’ve collected all the samples, then you do the final offset removal, divide by the number of samples to get the average, scaling etc to present the final value.

I can’t see where you do the rms calculation in your software.

So I’m sorry, but you have quite a lot of work to do.

Hi Robert!
Thank you so much for your kind reply!
I am the new one in design the circuit, As you said that, i found the circuit its better for those sensor no burden resistor inside. Thanks agin for your suggestions, i will change my circuit and code these days.
Best wishes!