Problem running two CT current sensors on Arduino Mega

Hello everyone,

Before I ask my question, a quick look at what I am currently working on.
I try to do an automatic control of my dust collection in my workshop.
If one machine runs, the CT sensor reads it, the dust extration starts and the blast gate opens using a pneumatic cylinder.

I just started to do the sketch and yet I have a problem. I would like to use the EmonLib to measure the current. If the measured current rises above a certain reading (in my case 1), a pneumatic valve is switched, to open the blast gate. So I don’t care if the readings are exact, I just want to know if the machine is switched on or not.

If I am using only one CT everything works fine but I can’t manage to include a second one to the sketch (in future there will be 8 of them)

The second CT shows a much higher value even if the CT is not attached and doesn’t change if a current is flowing. I checked if it’s a hardware problem, but both CT’s work fine if I run them separately.

It must be a software problem, would you please check my sketch?
Thank you! Greetings, David


#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1, emon2; // Create an instance

void setup()
{
  Serial.begin(9600);
  pinMode(30, OUTPUT);
  pinMode(31, OUTPUT);
  digitalWrite(30, HIGH);
  digitalWrite(31, HIGH);

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

void loop(){
  
double Irms1 = emon1.calcIrms(1480);  // Calculate Irms only

  Serial.println(Irms1); // Irms

  if(Irms1 > 1)
  {digitalWrite(30, LOW);}
  else 
  {digitalWrite(30, HIGH);}

double Irms2 = emon2.calcIrms(1480);

  Serial.println(Irms2);

  if(Irms2 > 1)
  {digitalWrite(31, LOW);}
  else 
  {digitalWrite(31, HIGH);}

  
}

Welcome, David.

I cannot see a problem with your sketch, so we must look at your hardware.

Does your input circuit look like this?
Are you using a completely separate circuit (R1, R2 & C1) for each c.t?
What is the actual current in Amperes that your machine uses?
Which c.t. are you using?
I remember a weird problem some time ago, but I cannot remember the details, either the problem or the solution. Can you use 2 c.t’s using different input pins - say A0 & A2?
Which ATMega exactly do you have?

Hi Robert,

thank you for your quick respond! After trying it with an other imput pin, everything works just fine… It seems that my A1 is broken.

Anyway, I still have more than enough other analog Pins left, so I will just skip this one :slight_smile:

thanks a lot for your help!
David