AC Current monitor - ADS1115 & SCT-013-000

Hello everyone, I’m trying to build a energy monitor for measuring current on a AC line. Ive been at this for a week or two now & not really making much progress. I have researched online for methods of measuring AC waves and there is a lot of vague info out there. I saw the emon lib and I can get that to work fine on my Mega with the SCT-013-000 and analog inputs. Where I’m running into issues is porting it over to work with a ADS1115 ADC on a ESP8266 Sparkfun Thing Dev. I tried modifying the library and couldn’t get that to work. So I’m trying to do the math manually. The below sketch I get consistent readings, slightly low, but they correspond with my control meter so I feel i’m on the right track. They match up if I divide the final number by 10. I don’t know why but that gets the almost correct readings, just slightly low.

I’m using the RMS voltage graphical method. I have a 18ohm burden resistor and its using a voltage divider @ 1.65v for the “base reference”.

Any input would be greatly appreciated. Hopefully I’m not way off lol

#include <Wire.h>
#include <ADS1115.h>

ADS1115 adc0(ADS1115_DEFAULT_ADDRESS);

//////////////////////////////////////////////

unsigned long startTime = 0;
unsigned long endTime = 0;

float mv;
int runTime = 0;
int readingCount = 0;
float offset = 0;
float adjusted = 0;
int squaredReading = 0;
unsigned long allReadingsSqrd = 0;
float dividedRMS = 0;
float finalNum = 0;

void setup(void)
{
  Wire.begin();
  Wire.setClock(400000L);

  Serial.begin(9600);

  Serial.println("Starting...");
  adc0.initialize();

  Serial.println("Testing connection...");
  Serial.println(adc0.testConnection() ? "ADS1115 connection successful" : "ADS1115 connection failed");

  adc0.showConfigRegister();
  Serial.println("");
  delay(1000); //view register

  adc0.setMode(ADS1115_MODE_CONTINUOUS);
  // adc0.setMode(ADS1115_MODE_SINGLESHOT);

  adc0.setRate(ADS1115_RATE_860);

  // adc0.setGain(ADS1115_PGA_0P256); 0.0078125mV
  // adc0.setGain(ADS1115_PGA_0P512); 0.015625mV
  // adc0.setGain(ADS1115_PGA_1P024); // 0.03125mV
  adc0.setGain(ADS1115_PGA_2P048); // 0.0625mV
  // adc0.setGain(ADS1115_PGA_4P096); 0.125mV
  // adc0.setGain(ADS1115_PGA_6P144); 0.1875mV

  adc0.showConfigRegister();
  Serial.println("");
  Serial.println("");
}



void loop()
{
  getCurrent2();
  delay(5000);
}


void getCurrent2()
{

  endTime = millis() + 1000;
  runTime = 1000;
  readingCount = 0;
  adjusted = 0;
  allReadingsSqrd = 0;


  offset = ( adc0.getConversionP1GND() * 0.0625 );

  while (runTime >= 0)
    {
      runTime = endTime - millis();

      mv = ( adc0.getConversionP0GND() * 0.0625 );
      readingCount++;

      adjusted = offset - mv;
      squaredReading = adjusted * adjusted;
      allReadingsSqrd += squaredReading;
    }

  dividedRMS = float( allReadingsSqrd / readingCount );
  finalNum = sqrt(dividedRMS);


  Serial.println(offset);
  Serial.println(mv);
  Serial.println(adjusted);
  Serial.println(squaredReading);
  Serial.println(allReadingsSqrd);
  Serial.println(" --- ");
  Serial.println(dividedRMS);
  Serial.println(finalNum);
}

The ADS1115 has an internal voltage reference. That makes it a poor choice for a ratiometric sensor, unless you measure differential voltage. Post a diagram of how you have connected the CT to the ADS, and how you power the ADS. Leo.. Edit: I think the 680 samples/sec of the ACS1115 is too slow for mains frequency. The Uno/Mega does ~10000/s

help me…

iwant my 2 current sensor ,detect the same
if the two current sensor has a difference a 10%
the arduino send a code in gsm and send that the wire has been tapped by the other…
i used emonlib… so plss help me …ineed it for my thesis tomorrow
sorry for my bad english

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include “EmonLib.h” // Include Emon Library
EnergyMonitor emon1; // Create an instance
EnergyMonitor emon2;
double VA1=0;
double VA2=0;

void setup()
{
Serial.begin(9600);

emon1.current(1, 111.1); // Current: input pin, calibration.
emon2.current(2, 111.1); // Current: input pin, calibration.
}

void loop()
{

double Irms1 = emon1.calcIrms(1480); // Calculate Irms only
double Irms2 = emon2.calcIrms(1480);

VA1 = Irms1230.0;
VA2 = Irms2
230.0;
Serial.print(“Sensor 1:”); // Apparent power
Serial.print(VA1);
Serial.print(" “);
Serial.println(Irms1); // Irms
Serial.print(”\n");
Serial.print(“Sensor 2:”);
Serial.print(VA2); // Apparent power
Serial.print(" ");
Serial.println(Irms2); // Irms
}

int difference = emon1.current1 - emon2.current2;

if (difference < 10 && difference > -10)

Why are you trying to measure the waveform to get to current?

Normally to measure a current you’d use a shunt resistor and measure the voltage across it - in case of AC simply use a rectifier & smoothing cap & measure the voltage, you then have the peak voltage and from that you can calculate the rest (knowing AC mains is a near-perfect sine).

keep track of the number of readings, the total of the readings and the total of the squares. You can calculate the rms even with an arbitrary offset if you use the right formulae:

mean = total / number

mean_square = (total_of_squares - total^2/number) / number

rms = sqrt (mean_square)