Problems reading signals in Arduino. Are there any other alternatives?

Hello everyone,
I write to ask for your help concerning the project I'm working on.

Turns out that I'm working on a Energy Meter for an Electric Power-Generator. The openenergymonitor.org web page helped me a lot, however I still have some drawbacks.

Although the Power Factor is OK, I can not determine the current and voltage values separately. In the schematic you will see that there are 2 test probes called "Current" and "Voltage" respectively, which are connected to the Arduino PWM read inputs (Pin 2, 3).

I've tried to measure the signals in A0 and A1 inputs; I've also measured the number of pulses at the output after the OPAMP (zero crossing), the smoothing code provided to make many measurements, PWM counter... but in all these cases described above, the measurement goes crazy without showing any stabilized values. : smiley-confuse:: smiley-confuse:
I know I have to make a formula corresponding to my values ​​that would allow me to calculate the current and voltage, however, if these "values" are not stable, how do I then to calculate current and voltage?

These two signals: Current is a signal of very low amplitude (<1V AC) and also with freq = 60Hz coming from sensor SCT-013-060 (it's simulated with an alternator at 500mV, which would basically result into 30Amps).
For Voltage I use the ZMPT 101B sensor and get an output of approx 4.5 VAC for 170VAC of home electric outlet.

On the other hand, I have tried to stabilize the signals before passing through the XOR gate with capacitors (3300uF), but they damage the square wave that determines the Power Factpr at the end of the logic gate.

I need your help! Thanks in advance for your contributions and comments :slight_smile:

PS: Schematic Attached below.

This is my code:

/*Power Factor calculator
 * Prog  mod by JCS Oct 25th, 2017 */

float x,y,z;
float current,voltage;
#define echoPin 7 // Digital Signal coming from XOR.
#define Corriente 2
#define Voltaje   3

#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

void setup()
{ 
  pinMode(echoPin, INPUT);
  pinMode(Corriente, INPUT);
  pinMode(Voltaje, INPUT);
  lcd.begin(16, 2);// set up the LCD's number of columns and rows:
  lcd.setCursor(0,0);
  lcd.print(" Welcome to the");
  lcd.setCursor(0,1);
  lcd.print("Energy Monitor");
  delay(800);
  lcd.clear();
  
}

void loop()
{
  
  x = pulseIn(echoPin,HIGH); //reads  duartion pulse in Microseconds
  y = (2 * PI * x/16667); //Angulo en radianes
  z = cos(y);

//Lectura pulsos para corriente y voltaje
 current= pulseIn(Corriente,HIGH);
 voltage= pulseIn(Voltaje, HIGH);
  
  if (x>500)
  {
 
  //Printing Values of Power Factor
  lcd.setCursor(0,1);
  lcd.print("PF=");
  lcd.print(z);
  delay(10);
  
  //Printing Current Values
  lcd.setCursor(0,0);
  lcd.print("I=");
  lcd.setCursor(3,0);
  lcd.print(current);

// Printing Voltage Values
  lcd.setCursor(9,0);
  lcd.print("V=");
  lcd.setCursor(11,0);
  lcd.print(voltage);
  delay(1000);

  }

}

I know I have to make a formula corresponding to my values ​​that would allow me to calculate the current and voltage, however, if these "values" are not stable, how do I then to calculate current and voltage?

Which values are not stable and what range are they in? We haven't seen the output you get yet, so you might have to show that first. I currently don't see yet how you would calculate the voltage or current from the rectangle signal you get on the digital inputs. The phase offset to calculate the power that is used seems to be clear but both voltage and current rectangle waves should be equal to the frequency of your system (60Hz I guess).

Try here

which are connected to the Arduino PWM read inputs (Pin 2, 3).

I've tried to measure the signals in A0 and A1 inputs

This pair of statements makes no sense. If the current and voltage sensors are connected to A0 and A1, they are NOT connected to pins 2 and 3. If they are connected to pins 2 and 3, reading A0 and A1 is a waste of effort.