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

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);

}

}
"

Currentsensor_LCD_PF.ino (1.73 KB)

(deleted)

Delta_G:
Is your problem with an Arduino or with the proteus simulator. It doesn't need always give an accurate representation of what a real board would do.

I'd have more for you but there's that "urgent" word slowing me down.

Hello Delta_G
Sorry for the urgency, but I was really stressed out because my simulation was not working at all.
I invite you to check an update on this topic. Here's the link : Problems reading signals in Arduino. Are there any other alternatives? - Programming Questions - Arduino Forum
Thanks in advance for your response!

Delta_G:
If your issue is with a simulation then you should ask the proteus folks. Not going to find a lot of knowledge of proteus here. We work with this stuff on real boards.

Proteus is only the program I use for Arduino simulation....but I'm not asking anything about the software itself. What I'm really asking for are suggestions or advices on how to read an AC signal coming from the sensors. I've tried to read them through the A0 pin but the results are constantly changing, so I can't apply a formula to calculate the current and voltage.
Hope this makes more sense to you and will appreciate your help also! Thanks