#include <LiquidCrystal.h> // include Arduino LCD library
// LCD module connections (RS, E, D4, D5, D6, D7)
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.setCursor(0, 0);
lcd.print("Power Factor:");
//analogReference(INTERNAL); // set ADC positive reference current to 1.1amp (internal)
}
const int xorOutputPin = 2; // Pin connected to XOR gate output
unsigned long pulseWidth;
double phaseAngle, powerFactor;
void setup() {
pinMode(xorOutputPin, INPUT);
Serial.begin(9600);
}
void loop() {
// Measure the pulse width in microseconds
pulseWidth = pulseIn(xorOutputPin, HIGH);
// Convert pulse width to phase angle here
// ...
// Calculate power factor
powerFactor = cos(phaseAngle);
// Display the power factor
Serial.print("Power Factor: ");
Serial.println(powerFactor);
// Add a delay between readings if necessary
delay(1000);
lcd.setCursor(0, 1);
//lcd.print(buf);
lcd.print(v1);
delay(500);
}
// end of code